Guest User

fence.lua

a guest
Apr 8th, 2020
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.79 KB | None | 0 0
  1. local ARGS = {...}
  2.  
  3. turtle.select(1)
  4.  
  5. -- convenience functions
  6. local function nextSlot()
  7.   turtle.select(turtle.getSelectedSlot()+1)
  8. end
  9.  
  10. local function empty()
  11.    return turtle.getItemCount() == 0
  12. end
  13.  
  14. local function build()
  15.   turtle.placeDown()
  16.   if empty() then nextSlot() end
  17.   turtle.forceForward()
  18. end
  19.  
  20.  
  21. -- MAIN
  22.  
  23. if not empty() then
  24.   -- build fence
  25.   local w = tonumber(ARGS[1])
  26.   local l = tonumber(ARGS[2])
  27.  
  28.   turtle.forceUp()
  29.   for i=2,l do build() end
  30.   turtle.turnRight()
  31.   for i=2,w do build() end
  32.   turtle.turnRight()
  33.   for i=2,l do build() end
  34.   turtle.turnRight()
  35.   for i=2,w do build() end
  36.  
  37. else
  38.   -- take down fence
  39.   while turtle.detect() do
  40.     while turtle.detect() do
  41.       turtle.forceForward()
  42.     end
  43.     turtle.turnRight()
  44.   end
  45. end
Advertisement
Add Comment
Please, Sign In to add comment