Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- WORKS ONLY IN VERSION 1.13 OR NEWER!
- -- Basicaly write *yourprogram* CubeDepth CubeWidth CubeHeight - for example | mine 2 2 | mines out cube 2x2x1
- -- Takes negative dimensions in all directions too!
- args={...}
- x=tonumber(args[1])
- if x == nil then
- x=1
- end
- y=tonumber(args[2])
- if y == nil then
- y=1
- end
- z=tonumber(args[3])
- if z == nil then
- z=1
- end
- moves=0
- -- 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))
- function midPrint(text,color)
- term.setBackgroundColor(color)
- term.clear()
- local r,t=term.getSize()
- t=t/2+1
- r=(r/2)-(string.len(text)/2)+1
- term.setCursorPos(r,t)
- print(text)
- end
- function Forward()
- while not turtle.detect() and not turtle.forward() do
- midPrint("Blocked!",colors.red)
- end
- end
- function Dig()
- while turtle.detect() do
- turtle.dig()
- end
- end
- function Up()
- while not turtle.detectUp() and not turtle.up() do
- midPrint("Blocked!",colors.red)
- end
- end
- function DigUp()
- while turtle.detectUp() do
- turtle.digUp()
- end
- end
- function Down()
- while not turtle.detectDown() and not turtle.down() do
- midPrint("Blocked!",colors.red)
- end
- end
- function DigDown()
- while turtle.detectDown() do
- turtle.digDown()
- end
- end
- -- Negative coords logic conversion
- yOdd=false
- if z<0 then
- Zneg=true
- z=z*(-1)
- end
- if y<0 and x>0 then
- turtle.turnLeft()
- local Ymem=y
- y=x
- x=Ymem*(-1)
- elseif y<0 and x<0 then
- turtle.turnLeft(2)
- yOdd=true
- local Ymem=y
- y=x*(-1)
- x=Ymem*(-1)
- elseif y>0 and x<0 then
- turtle.turnRight()
- local Ymem=y
- y=x*(-1)
- x=Ymem
- end
- --Refueling (My best attempt to make this not crash the code)
- while turtle.getFuelLevel()<(x*y*z) do
- local InventorySlot=16
- while turtle.select(InventorySlot) do
- midPrint(("Not enough fuel! ("..(math.ceil((x*y*z-turtle.getFuelLevel())/80)).." Required)"),colors.red)
- if turtle.getItemDetail() then
- if (tostring(turtle.getItemDetail().name)=="minecraft:coal") then
- break
- end
- end
- InventorySlot=InventorySlot-1
- if InventorySlot==0 then
- InventorySlot=16
- sleep(1)
- end
- end
- if (tostring(turtle.getItemDetail().name)=="minecraft:coal") then
- turtle.refuel(math.ceil((x*y*z-turtle.getFuelLevel())/80))
- if turtle.getFuelLevel()>(x*y*z) or turtle.getFuelLevel()==(x*y*z) then
- break
- end
- end
- end
- -- Main loop
- l=false
- for i=z-1,0,-1 do
- for m=y-1,1,-1 do
- for n=x-1,1,-1 do
- Dig()
- Forward()
- moves=moves+1
- midPrint((tostring(math.floor((moves/(x*y*z))*1000)/10).."%"),colors.green)
- end
- if not yOdd then
- if not l then
- yOdd=true
- turtle.turnRight()
- end
- if x==1 and not l then
- yOdd=false
- l=true
- end
- Dig()
- Forward()
- moves=moves+1
- midPrint((tostring(math.floor((moves/(x*y*z))*1000)/10).."%"),colors.green)
- if not l then
- turtle.turnRight()
- end
- else
- yOdd=false
- turtle.turnLeft()
- Dig()
- Forward()
- moves=moves+1
- midPrint((tostring(math.floor((moves/(x*y*z))*1000)/10).."%"),colors.green)
- turtle.turnLeft()
- end
- end
- for n=x-1,1,-1 do
- Dig()
- Forward()
- moves=moves+1
- midPrint((tostring(math.floor((moves/(x*y*z))*1000)/10).."%"),colors.green)
- end
- if i>0 then
- if Zneg then
- DigDown()
- Down()
- moves=moves+1
- midPrint((tostring(math.floor((moves/(x*y*z))*1000)/10).."%"),colors.green)
- if x>1 or y>1 then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- else
- DigUp()
- Up()
- moves=moves+1
- midPrint((tostring(math.floor((moves/(x*y*z))*1000)/10).."%"),colors.green)
- if x>1 or y>1 then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- end
- end
- end
- midPrint("Complete",colors.blue)
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment