Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local params = {...}
- -- Validade Params
- if(tonumber(params[1]) < 1) then
- term.write("Param [".. params[1] .."] is invalid")
- return
- elseif(tonumber(params[2]) < 1) then
- term.write("Param [".. params[2] .."] is invalid")
- return
- elseif(tonumber(params[3]) < 1) then
- term.write("Param [".. params[3] .."] is invalid")
- return
- end
- params[1] = tonumber(params[1])
- params[2] = tonumber(params[2])
- params[3] = tonumber(params[3])
- -- Check fuel
- local fuelRequired = params[1] * params[3] * math.ceil(params[2] / 3)
- if(params[2] > 1) then
- fuelRequired = (fuelRequired + 1) + (math.floor(params[2] / 3) * 2)
- end
- if(turtle.getFuelLevel() < fuelRequired) then
- term.write("Fuel required: ".. fuelRequired ..", turtle fuel: ".. turtle.getFuelLevel())
- return
- end
- print("Now digging...")
- print(" ".. params[1] * params[2] * params[3] .." blocks")
- print(" Required fuel: ".. fuelRequired)
- fuelRequired = nil;
- -- Variables
- local posX = 0
- local posY = 0
- local posZ = 0
- local rot = 0
- -- 0 = forward
- -- 1 = right
- -- 2 = back
- -- 3 = left
- local turn = 0
- local hasEnderChest = false
- -- Check inventory
- turtle.select(1)
- local info = turtle.getItemDetail()
- if(info ~= nil and info.name == "EnderStorage:enderChest") then
- hasEnderChest = true
- end
- -- Moviment
- function DirectionOperator()
- if(rot < 2) then
- return 1
- else
- return -1
- end
- end
- function Forward()
- if(turtle.forward()) then
- if(rot == 0) then
- posZ = posZ + 1
- elseif(rot == 1) then
- posX = posX - 1
- elseif(rot == 2) then
- posZ = posZ - 1
- elseif(rot == 3) then
- posX = posX + 1
- end
- return true
- end
- return false
- end
- function Up()
- if(turtle.up()) then
- posY = posY + 1
- return true
- end
- return false
- end
- function Down()
- if(turtle.down()) then
- posY = posY - 1
- return true
- end
- return false
- end
- function ForceForward()
- while Forward() == false do end
- end
- function ForceUp()
- while Up() == false do end
- end
- function ForceDown()
- while Down() == false do end
- end
- function Right()
- turtle.turnRight()
- rot = (rot + 1) % 4
- end
- function Left()
- turtle.turnLeft()
- rot = (rot - 1) % 4
- end
- function Dig()
- repeat
- turtle.dig()
- until turtle.detect() == false
- end
- function DigUp()
- repeat
- turtle.digUp()
- until turtle.detectUp() == false
- end
- function DigDown()
- repeat
- turtle.digDown()
- until turtle.detectDown() == false
- end
- -- Functions
- function CheckForFullInventory(side)
- if(hasEnderChest and turtle.getItemCount(16) ~= 0) then
- turtle.select(1)
- if(side == 1) then
- turtle.place()
- for i = 2, 16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- turtle.dig()
- elseif(side == 2) then
- turtle.placeUp()
- for i = 2, 16 do
- turtle.select(i)
- turtle.dropUp()
- end
- turtle.select(1)
- turtle.digUp()
- elseif(side == 3) then
- turtle.placeDown()
- for i = 2, 16 do
- turtle.select(i)
- turtle.dropDown()
- end
- turtle.select(1)
- turtle.digDown()
- end
- end
- end
- function GoDig()
- if(posY + 1 <= 0) then
- DigUp()
- CheckForFullInventory(2)
- end
- if(posY - 1 > -params[2]) then
- DigDown()
- CheckForFullInventory(3)
- end
- if(rot == 0) then
- if(posZ + 1 <= params[3]) then
- Dig()
- CheckForFullInventory(1)
- end
- elseif(rot == 2) then
- if(posZ - 1 > 0) then
- Dig()
- CheckForFullInventory(1)
- end
- end
- end
- function EndRowRight()
- Right()
- Dig()
- ForceForward()
- Right()
- end
- function EndRowLeft()
- Left()
- Dig()
- ForceForward()
- Left()
- end
- function EndLevel()
- -- +1 already digged, +2 wont dig up, +3 will dig up
- if(posY - 3 > -params[2]) then
- DigDown()
- ForceDown()
- CheckForFullInventory(2)
- DigDown()
- ForceDown()
- CheckForFullInventory(2)
- DigDown()
- ForceDown()
- elseif(posY - 2 > -params[2]) then
- DigDown()
- ForceDown()
- CheckForFullInventory(2)
- DigDown()
- ForceDown()
- else
- return
- end
- Right()
- Right()
- end
- function NextTurn()
- if(turn == 0) then
- if(posZ == params[3] or posZ == 1) then
- EndRowLeft()
- turn = 1
- --print("Turn set to 1")
- end
- else
- if(posZ == params[3] or posZ == 1) then
- EndRowRight()
- turn = 0
- --print("Turn set to 0")
- end
- end
- end
- -- Dig Loop
- --::dig::
- local levels = math.ceil(params[2] / 3)
- if(params[2] > 1) then
- DigDown()
- ForceDown()
- end
- Dig()
- ForceForward()
- for loopY = 1, levels do
- for loopX = 1, params[1] do
- for loopZ = 1, (params[3] - 1) do
- GoDig()
- ForceForward()
- --print(loopZ .." ".. params[3] .." | ".. posX .." ".. posZ)
- end
- if(posY + 1 <= 0) then
- DigUp()
- CheckForFullInventory(2)
- end
- if(posY - 1 > -params[2]) then
- DigDown()
- CheckForFullInventory(3)
- end
- if(loopX ~= params[1]) then
- --print("NextTurn")
- NextTurn()
- end
- end
- if(loopY ~= levels) then
- EndLevel()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement