Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Chests in slot 1, fuel in slot 2
- local IgnoreSlots = 2
- local fuelIndex = 2
- local DepthIntoGrid = 0
- local DepthTarget = 120
- local mov = {}
- local rot = {}
- local dig = {}
- local function Refuel()
- currentFuelRequired = (10 + (DepthTarget-DepthIntoGrid)*2)/20
- if turtle.getFuelLevel() < currentFuelRequired then
- turtle.select(fuelIndex)
- return turtle.refuel(currentFuelRequired)
- else
- return true
- end
- end
- mov.forward = function(times)
- local boolean v = false
- for i=1,times do
- if turtle.detect() == false then
- while not turtle.forward() do
- Refuel()
- sleep(1)
- end
- v = true
- else
- v = false
- return v
- end
- end
- return v
- end
- mov.back = function(times)
- local boolean v = false
- for i=1,times do
- while not turtle.back() do
- Refuel()
- sleep(1)
- end
- v = true
- end
- return v
- end
- mov.up = function(times)
- print("In mov.up")
- local boolean v = false
- for i=1,times do
- if turtle.detectUp() == false then
- while turtle.up() == false do
- Refuel()
- sleep(1)
- end
- v = true
- else
- v = false
- print("Out mov.up")
- return v
- end
- end
- print("Out mov.up")
- return v
- end
- mov.down = function(times)
- print("In mov.down")
- local boolean v = false
- for i=1,times do
- if turtle.detectDown() == false then
- while turtle.down() == false do
- Refuel()
- sleep(1)
- end
- v = true
- else
- print("Out mov.down")
- v = false
- return v
- end
- end
- print("Out mov.down")
- return v
- end
- mov.place = function()
- while not turtle.place() do
- sleep(1)
- end
- return true
- end
- rot.right = function()
- while not turtle.turnRight() do
- sleep(1)
- end
- return true
- end
- rot.left = function()
- while not turtle.turnLeft() do
- sleep(1)
- end
- return true
- end
- dig.forward = function()
- print("In dig.forward")
- if turtle.detect() then
- while not turtle.dig() do
- sleep(1)
- end
- print("Out dig.forward")
- return true
- else
- print("No Block to mine forward")
- print("Out dig.forward")
- return false
- end
- end
- dig.up = function()
- print("In dig.up")
- if turtle.detectUp() then
- while not turtle.digUp() do
- sleep(1)
- end
- print("Out dig.up")
- return true
- else
- print("No Block to mine up")
- print("Out dig.up")
- return false
- end
- end
- dig.down = function()
- print("In dig.down")
- if turtle.detectDown() then
- while not turtle.digDown() do
- sleep(1)
- end
- print("Out dig.down")
- return true
- else
- print("No Block to mine down")
- print("Out dig.down")
- return false
- end
- end
- local function DigMoveForward()
- print("In DigMoveForward")
- if mov.forward(1) == false then
- dig.forward()
- sleep(0.5)
- DigMoveForward()
- end
- print("Out DigMoveForward")
- end
- local function DigMoveUp()
- print("In DigMoveUp")
- while mov.up(1) == false do
- dig.up()
- sleep(0.5)
- end
- print("Out DigMoveUp")
- end
- local function DigMoveDown()
- print("In DigMoveDown")
- while mov.down(1) == false do
- dig.down()
- sleep(0.5)
- end
- print("Out DigMoveDown")
- end
- local function ReturnBack()
- print("In ReturnBack")
- turtle.select(1)
- while not turtle.compareUp() do
- DigMoveUp()
- end
- print("Out ReturnBack")
- end
- local function CheckRefuel()
- if Refuel() == false then
- print("***Out of fuel***")
- ReturnBack()
- while Refuel() do
- end
- for i=1,DepthIntoGrid do
- DigMoveDown()
- end
- end
- end
- local function DepositChest()
- print("In DepositChest")
- turtle.select(1)
- if not turtle.compareUp() then
- print("ERROR: Should be below chest.")
- print("Out DepositChest")
- return
- end
- print("Depositing the Load...")
- for i = IgnoreSlots + 1,16 do
- turtle.select(i)
- turtle.dropUp()
- end
- print("Out DepositChest")
- end
- local function InventoryFull()
- print("In InventoryFull")
- SlotsFull = 0
- for i=1,16 do
- if turtle.getItemCount(i) > 0 then
- SlotsFull = SlotsFull + 1
- end
- end
- if SlotsFull == 16 then
- print("Out InventoryFull")
- return true;
- else
- print("Out InventoryFull")
- return false;
- end
- end
- local function CheckInventory()
- if InventoryFull() then
- print("***Inventory Full***")
- ReturnBack()
- DepositChest()
- for i=1,DepthIntoGrid do
- DigMoveDown()
- end
- end
- end
- local function Harvest()
- while turtle.suck() == true do
- CheckInventory()
- end
- dig.forward()
- end
- local function Advance()
- DigMoveDown()
- DepthIntoGrid = DepthIntoGrid + 1
- BlocksTillEnd = DepthTarget - DepthIntoGrid
- end
- local function Finish()
- print("In Finish")
- ReturnBack()
- DepositChest()
- DigMoveForward()
- DigMoveForward()
- DigMoveForward()
- DigMoveForward()
- print("Out Finish")
- end
- function StartMining()
- print("In StartMining")
- BlocksTillEnd = DepthTarget - DepthIntoGrid
- while BlocksTillEnd > 0 do
- CheckRefuel()
- CheckInventory()
- Harvest()
- for i=1,4 do
- Advance()
- end
- print("Depth: ")
- print(DepthIntoGrid)
- end
- Harvest()
- Finish()
- print("Out StartMining")
- end
- -- MAIN PROGRAM
- local FuelCount = turtle.getItemCount(fuelIndex)
- if FuelCount == 0 then
- print("please put fuel in the last slot of the Turtle.")
- return
- else
- if FuelCount < 10 then
- print("Please put at least 10 of the fuel you are using in the Turtle.")
- return
- end
- end
- Refuel()
- turtle.select(1)
- turtle.placeUp()
- StartMining()
Advertisement
Add Comment
Please, Sign In to add comment