Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local wait = sleep
- local posX = 0
- local mining = true
- local facingForward = true
- -- Ores list
- local ores = {
- ["minecraft:gold_ore"] = true,
- ["minecraft:iron_ore"] = true,
- ["minecraft:diamond_ore"] = true,
- ["minecraft:emerald_ore"] = true,
- ["minecraft:lapis_ore"] = true,
- ["minecraft:redstone_ore"] = true,
- ["create:copper_ore"] = true,
- ["create:zinc_ore"] = true
- }
- local function checkInvFull()
- for i = 1, 16 do
- if not turtle.getItemDetail(i) then
- return false -- not full
- end
- end
- return true --full
- end
- local function checkInvEmpty()
- for i = 1, 16 do
- if turtle.getItemDetail(i) then
- return false
- end
- end
- return true
- end
- local function fuelStop()
- if turtle.getFuelLevel() <= 500 then
- os.setComputerLabel("Refulling")
- turtle.suckDown(64)
- turtle.refuel(64)
- os.setComputerLabel("Refueled with a level of: " .. turtle.getFuelLevel())
- else
- os.setComputerLabel("No refulling needed")
- wait(3)
- os.setComputerLabel("fuel level is: " .. turtle.getFuelLevel())
- end
- wait(3)
- os.setComputerLabel("miner")
- end
- local function turnAround()
- turtle.turnLeft()
- turtle.turnLeft()
- facingForward = not facingForward
- end
- local function dumpInventory()
- if posX == 0 then
- if facingForward then
- turtle.back()
- turtle.up()
- for i = 1, 16 do
- turtle.select(i)
- local amount = turtle.getItemCount(i)
- turtle.dropUp(amount)
- end
- turtle.down()
- turtle.forward()
- else
- turnAround()
- end
- end
- end
- local function returnHome(reason)
- mining = false
- turnAround()
- os.setComputerLabel("Returning home" .. reason)
- while posX > 0 do
- turtle.forward()
- posX = posX - 1
- end
- turnAround()
- end
- local function diggy()
- turtle.dig("right")
- local ok, name = turtle.inspectUp()
- if ok and ores[name] then
- turtle.digUp("right")
- end
- local ok, name = turtle.inspectDown()
- if ok and ores[name] then
- turtle.digDown("right")
- end
- end
- fuelStop()
- while true do
- if mining then
- if turtle.detect() == false then
- turtle.forward()
- posX = posX + 1
- else
- if checkInvFull == false then
- if posX > turtle.getFuelLevel() + 10 then
- diggy()
- else
- returnHome("no fuel")
- end
- else
- returnHome("inventory full")
- end
- end
- else
- if checkInvEmpty() == false then
- dumpInventory()
- end
- fuelStop()
- mining = true
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement