Advertisement
npexception

CC Turtle Fence Builder

Apr 8th, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local version = 1.1
  2. --  +------------------------+  --
  3. --  |-->  INITIALIZATION  <--|  --
  4. --  +------------------------+  --
  5. if not turtle or not turtle.forceForward then
  6.   print("This program can only be")
  7.   print("executed by a turtle")
  8.   print("with BetterTurtle API.")
  9.   return
  10. end
  11.  
  12. -- UPDATE HANDLING --
  13. if _UD and _UD.su(version, "5V85iVAM", {...}) then return end
  14.  
  15. local ARGS = {...}
  16.  
  17. turtle.select(1)
  18.  
  19. -- convenience functions
  20. local function nextSlot()
  21.   turtle.select(turtle.getSelectedSlot()+1)
  22. end
  23.  
  24. local function empty()
  25.    return turtle.getItemCount() == 0
  26. end
  27.  
  28. local function build()
  29.   turtle.placeDown()
  30.   if empty() then nextSlot() end
  31.   turtle.forceForward()
  32. end
  33.  
  34.  
  35. -- MAIN
  36.  
  37. if not empty() then
  38.   -- build fence
  39.   local w = tonumber(ARGS[1])
  40.   local l = tonumber(ARGS[2])
  41.  
  42.   turtle.forceUp()
  43.   for i=2,l do build() end
  44.   turtle.turnRight()
  45.   for i=2,w do build() end
  46.   turtle.turnRight()
  47.   for i=2,l do build() end
  48.   turtle.turnRight()
  49.   for i=2,w do build() end
  50.  
  51. else
  52.   -- take down fence
  53.   while turtle.detect() do
  54.     while turtle.detect() do
  55.       turtle.forceForward()
  56.     end
  57.     turtle.turnRight()
  58.   end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement