Vortus

Turtle Cube v1.1

Oct 1st, 2025 (edited)
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.47 KB | Gaming | 0 0
  1. -- WORKS ONLY IN VERSION 1.13 OR NEWER!
  2.  
  3. -- Basicaly write *yourprogram* CubeDepth CubeWidth CubeHeight - for example | mine 2 2 | mines out cube 2x2x1
  4. -- Takes negative dimensions in all directions too!
  5. args={...}
  6. x=tonumber(args[1])  
  7. if x == nil then
  8.     x=1
  9. end
  10. y=tonumber(args[2])
  11. if y == nil then
  12.     y=1
  13. end
  14. z=tonumber(args[3])
  15. if z == nil then
  16.     z=1
  17. end
  18. moves=0
  19.  
  20. -- Few functions so that the code is "easier" to code  (this mainly includes weird exceptions and failsafes (For example mob blocking turtle or falling blocks))
  21. function midPrint(text,color)
  22.     term.setBackgroundColor(color)
  23.     term.clear()
  24.     local r,t=term.getSize()
  25.     t=t/2+1
  26.     r=(r/2)-(string.len(text)/2)+1
  27.     term.setCursorPos(r,t)
  28.     print(text)
  29. end
  30. function Forward()
  31.     while not turtle.detect() and not turtle.forward() do
  32.         midPrint("Blocked!",colors.red)
  33.     end
  34. end
  35. function Dig()
  36.     while turtle.detect() do
  37.         turtle.dig()
  38.     end
  39. end
  40. function Up()
  41.     while not turtle.detectUp() and not turtle.up() do
  42.         midPrint("Blocked!",colors.red)
  43.     end
  44. end
  45. function DigUp()
  46.     while turtle.detectUp() do
  47.         turtle.digUp()
  48.     end
  49. end
  50. function Down()
  51.     while not turtle.detectDown() and not turtle.down() do
  52.         midPrint("Blocked!",colors.red)
  53.     end
  54. end
  55. function DigDown()
  56.     while turtle.detectDown() do
  57.         turtle.digDown()
  58.     end
  59. end
  60.  
  61. -- Negative coords logic conversion
  62. yOdd=false
  63. if z<0 then
  64.     Zneg=true
  65.     z=z*(-1)
  66. end
  67. if y<0 and x>0 then
  68.     turtle.turnLeft()
  69.     local Ymem=y
  70.     y=x
  71.     x=Ymem*(-1)
  72. elseif y<0 and x<0 then
  73.     turtle.turnLeft(2)
  74.     yOdd=true
  75.     local Ymem=y
  76.     y=x*(-1)
  77.     x=Ymem*(-1)
  78. elseif y>0 and x<0 then
  79.     turtle.turnRight()
  80.     local Ymem=y
  81.     y=x*(-1)
  82.     x=Ymem
  83. end
  84.  
  85. --Refueling   (My best attempt to make this not crash the code)
  86. while turtle.getFuelLevel()<(x*y*z) do
  87.     local InventorySlot=16
  88.     while turtle.select(InventorySlot) do
  89.         midPrint(("Not enough fuel! ("..(math.ceil((x*y*z-turtle.getFuelLevel())/80)).." Required)"),colors.red)
  90.         if turtle.getItemDetail() then
  91.            if (tostring(turtle.getItemDetail().name)=="minecraft:coal") then
  92.                break
  93.            end
  94.         end
  95.         InventorySlot=InventorySlot-1
  96.         if InventorySlot==0 then
  97.             InventorySlot=16
  98.             sleep(1)
  99.         end
  100.     end
  101.     if (tostring(turtle.getItemDetail().name)=="minecraft:coal") then
  102.         turtle.refuel(math.ceil((x*y*z-turtle.getFuelLevel())/80))
  103.         if turtle.getFuelLevel()>(x*y*z) or turtle.getFuelLevel()==(x*y*z) then
  104.             break
  105.         end
  106.     end
  107. end
  108. -- Main loop
  109. l=false
  110. for i=z-1,0,-1 do
  111.     for m=y-1,1,-1 do
  112.         for n=x-1,1,-1 do
  113.             Dig()
  114.             Forward()
  115.             moves=moves+1
  116.             midPrint((tostring(math.floor((moves/(x*y*z))*1000)/10).."%"),colors.green)
  117.         end
  118.         if not yOdd then
  119.             if not l then
  120.                 yOdd=true
  121.                 turtle.turnRight()
  122.             end
  123.             if x==1 and not l then
  124.                 yOdd=false
  125.                 l=true
  126.             end
  127.             Dig()
  128.             Forward()
  129.             moves=moves+1
  130.             midPrint((tostring(math.floor((moves/(x*y*z))*1000)/10).."%"),colors.green)
  131.             if not l then
  132.                 turtle.turnRight()
  133.             end
  134.         else
  135.             yOdd=false
  136.             turtle.turnLeft()
  137.             Dig()
  138.             Forward()
  139.             moves=moves+1
  140.             midPrint((tostring(math.floor((moves/(x*y*z))*1000)/10).."%"),colors.green)
  141.             turtle.turnLeft()
  142.         end
  143.     end
  144.     for n=x-1,1,-1 do
  145.         Dig()
  146.         Forward()
  147.         moves=moves+1
  148.         midPrint((tostring(math.floor((moves/(x*y*z))*1000)/10).."%"),colors.green)
  149.     end
  150.     if i>0 then
  151.         if Zneg then
  152.             DigDown()
  153.             Down()
  154.             moves=moves+1
  155.             midPrint((tostring(math.floor((moves/(x*y*z))*1000)/10).."%"),colors.green)
  156.             if x>1 or y>1 then
  157.                 turtle.turnLeft()
  158.                 turtle.turnLeft()
  159.             end
  160.         else
  161.             DigUp()
  162.             Up()
  163.             moves=moves+1
  164.             midPrint((tostring(math.floor((moves/(x*y*z))*1000)/10).."%"),colors.green)
  165.             if x>1 or y>1 then
  166.                 turtle.turnLeft()
  167.                 turtle.turnLeft()
  168.             end
  169.         end
  170.     end
  171. end
  172. midPrint("Complete",colors.blue)
  173. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment