Advertisement
nadkarnik

walldebug.lua

Jul 4th, 2025
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.38 KB | None | 0 0
  1. function selectNextSlot()
  2.   for i=1,16 do
  3.     local slot = (turtle.getSelectedSlot() % 16) + 1
  4.     turtle.select(slot)
  5.     if turtle.getItemCount() > 0 then return true end
  6.   end
  7.   return false
  8. end
  9.  
  10. function placeWallBlock()
  11.   while not turtle.placeDown() do
  12.     if turtle.getItemCount() == 0 and not selectNextSlot() then
  13.       error("Out of blocks while placing down for walls")
  14.     end
  15.     sleep(0.1)
  16.   end
  17. end
  18.  
  19. function forwardSafe()
  20.   while not turtle.forward() do
  21.     turtle.dig()
  22.     sleep(0.1)
  23.   end
  24. end
  25.  
  26. function upSafe()
  27.   while not turtle.up() do
  28.     turtle.digUp()
  29.     sleep(0.1)
  30.   end
  31. end
  32.  
  33. function downSafe()
  34.   while not turtle.down() do
  35.     turtle.digDown()
  36.     sleep(0.1)
  37.   end
  38. end
  39.  
  40. -- === WALL BUILD TEST (FIXED) ===
  41. function testWalls()
  42.   local length, width, height = 3, 3, 3
  43.   local wallHeight = height - 2
  44.   if wallHeight < 1 then return end
  45.  
  46.   print("Going up to layer 2...")
  47.   upSafe()
  48.  
  49.   for h = 1, wallHeight do
  50.     print("Building wall layer "..h)
  51.     for side = 1, 4 do
  52.       local distance = (side % 2 == 1) and length or width
  53.       for i = 1, distance do
  54.         placeWallBlock()
  55.         if i < distance then forwardSafe() end
  56.       end
  57.       turtle.turnRight()
  58.     end
  59.     if h < wallHeight then upSafe() end
  60.   end
  61.  
  62.   print("Returning to ground...")
  63.   for i = 1, wallHeight do downSafe() end
  64. end
  65.  
  66. -- Run test
  67. testWalls()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement