Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Very basic turtle mining program.
- function refuel()
- local data
- local success = false
- for i = 1, 16, 1 do
- turtle.select(i)
- data = turtle.getItemDetail()
- if data then
- if data.name == "minecraft:coal" then --refuel if coal found in internal storage
- turtle.refuel(turtle.getItemCount())
- success = true
- end
- end
- if turtle.getFuelLevel() == turtle.getFuelLimit() then --if already refueled no need to continue this function
- break
- end
- end
- if not success then
- print("Couldn't refuel!\n")
- end
- turtle.select(1)
- return success
- end
- function isFull()
- local data
- for i = 1, 16, 1 do
- turtle.select(i)
- data = turtle.getItemDetail()
- if not data then
- do return false end
- end
- end
- turtle.select(1)
- return true
- end
- function isStorage(chestName)
- local success, data = turtle.inspect()
- if success then
- if data.name == chestName then
- do return true end
- end
- end
- return false
- end
- function goBackHome(chestName)
- turtle.turnLeft()
- turtle.turnLeft() --180°
- while not isStorage(chestName) do
- turtle.forward()
- end
- end
- function store()
- local success
- for i = 1, 16, 1 do
- turtle.select(i)
- success = turtle.drop()
- if not success then
- do return false end
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(1)
- return true
- end
- --main
- local storageChestName = "minecraft:chest"
- local canStillWork= true
- while true do
- if turtle.getFuelLevel() == 0 then
- canStillWork = refuel()
- elseif isFull() then
- goBackHome(storageChestName)
- canStillWork = store()
- else
- turtle.dig()
- turtle.up()
- turtle.dig()
- turtle.down()
- turtle.forward()
- end
- if not canStillWork then
- break
- end
- end
- print("Job finished!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement