Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args={...} -- Basicaly write *yourprogram* CubeDepth CubeWidth CubeHeight - for example | mine 2 2 | mines out cube 2x2x1
- x=tonumber(args[1]) -- Takes negative dimensions in all directions too!
- 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)
- function midPrint(text,color)
- term.setBackgroundColor(color)
- term.clear()
- 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
- local yOdd=false
- -- Negative coords logic conversion
- if z<0 then
- Zneg=true
- z=z*(-1)
- end
- if y<0 and x>0 then
- turtle.turnLeft()
- Ymem=y
- y=x
- x=Ymem*(-1)
- elseif y<0 and x<0 then
- turtle.turnLeft(2)
- yOdd=true
- Ymem=y
- y=x*(-1)
- x=Ymem*(-1)
- elseif y>0 and x<0 then
- turtle.turnRight()
- Ymem=y
- y=x*(-1)
- x=Ymem
- end
- --Fuel
- while turtle.getFuelLevel()<(x*y*z) do
- local InventorySlots=16
- while turtle.select(InventorySlots) do
- midPrint(("Trying to find fuel! ("..((math.floor((x*y*z-turtle.getFuelLevel())/80))+1).." Required)"),colors.red)
- if turtle.getItemDetail() then
- if (tostring(turtle.getItemDetail().name)=="minecraft:coal") then
- break
- end
- end
- InventorySlots=InventorySlots-1
- if InventorySlots==0 then
- InventorySlots=16
- sleep(1)
- end
- end
- while ((turtle.getItemCount())<((math.floor((x*y*z-turtle.getFuelLevel())/80))+1)) do
- if turtle.getItemDetail() then
- if (tostring(turtle.getItemDetail().name)=="minecraft:coal") then
- midPrint(("Not enough Fuel! ("..((math.floor((x*y*z-turtle.getFuelLevel())/80))+1).." Required)"),colors.yellow)
- sleep(3)
- else
- break
- end
- else
- break
- end
- end
- if ((turtle.getItemCount())>((math.floor((x*y*z-turtle.getFuelLevel())/80)))) and (tostring(turtle.getItemDetail().name)=="minecraft:coal") then
- turtle.refuel((math.floor((x*y*z-turtle.getFuelLevel())/80))+1)
- break
- end
- end
- -- Main loop
- local 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((moves/(x*y*z))*100).."%"),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((moves/(x*y*z))*100).."%"),colors.green)
- if not l then
- turtle.turnRight()
- end
- else
- yOdd=false
- turtle.turnLeft()
- Dig()
- Forward()
- moves=moves+1
- midPrint((tostring((moves/(x*y*z))*100).."%"),colors.green)
- turtle.turnLeft()
- end
- end
- for n=x-1,1,-1 do
- Dig()
- Forward()
- moves=moves+1
- midPrint((tostring((moves/(x*y*z))*100).."%"),colors.green)
- end
- if i>0 then
- if Zneg then
- DigDown()
- Down()
- moves=moves+1
- midPrint((tostring((moves/(x*y*z))*100).."%"),colors.green)
- if x>1 or y>1 then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- else
- DigUp()
- Up()
- moves=moves+1
- midPrint((tostring((moves/(x*y*z))*100).."%"),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