Advertisement
nadkarnik

walldebug.lua

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