Vortus

Turtle Cube v1.1

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