Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Miner
- local SLOT_FEUL = 1
- function get_place_dig_suck_drop_in_empty_space()
- local success, data = turtle.inspect()
- if not success then
- return turtle.place, turtle.dig, turtle.suck, turtle.drop
- end
- success, data = turtle.inspectUp()
- if not success then
- return turtle.placeUp, turtle.digUp, turtle.suckUp, turtle.dropUp
- end
- success, data = turtle.inspectDown()
- if not success then
- return turtle.placeDown, turtle.digDown, turtle.suckDown, turtle.dropDown
- end
- error("No empty space in front, above, or below the turtle")
- end
- function try_with_rotation(func)
- for i=1,4 do
- vals = {pcall(func)}
- if vals[1] then
- for j = 1,(i-1) do
- turtle.turnRight()
- end
- table.remove(vals, 1)
- return unpack(vals)
- end
- turtle.turnLeft()
- end
- error("Could not execute function in any orientation")
- end
- function refuel_from_chest(slot)
- local place, dig, suck, drop = try_with_rotation(get_place_dig_suck_drop_in_empty_space)
- local prev_slot = turtle.getSelectedSlot()
- turtle.select(slot)
- local success = place()
- assert(success, "Could not place chest")
- success = suck()
- assert(success, "Could not obtain fuel from chest")
- success = turtle.refuel()
- assert(success, "Could not use item obtained from chest as fuel")
- success = dig()
- assert(success, "Could not remove chest")
- turtle.select(prev_slot)
- end
- refuel_from_chest(SLOT_FEUL)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement