Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- chquarry
- --
- -- At the beginning everything must be already placed:
- -- a quarry facing North,
- -- an "item" enderchest on the West side of the quarry,
- -- a full power cell on the East side of the querry,
- -- a chunkloading mining turtle running this program facing the power cell from its East side,
- -- (ie. the turtle must face West)
- -- a "charged power cell" enderchest above the turtle, and
- -- a "discharged power cell" enderchest below the turtle.
- -- Download this as chquarry and put this code into the "startup" file: shell.run("chquarry")
- local FUEL_SLOT = 1
- local QUARRY_SLOT = 2
- local ENERGY_CELL_SLOT = 3
- local CHARGED_CELLS_ENDERCHEST_SLOT = 4
- local EMPTY_CELLS_ENDERCHEST_SLOT = 5
- local ITEMS_ENDERCHEST_SLOT = 6
- local TRASH_SLOT = 7
- local RELOCATE_DISTANCE = 9
- local MIN_FUEL_FOR_CYCLE = RELOCATE_DISTANCE + 12
- local STEPS_COUNT = 3
- local STEP_SLEEP = 600
- local QUARRY_STOP_SLEEP = 30 -- wait for the quarry to stop after disconnecting power
- function recharge()
- turtle.select(ENERGY_CELL_SLOT)
- turtle.dig()
- turtle.dropDown()
- while turtle.getItemCount(ENERGY_CELL_SLOT)==0 do
- turtle.suckUp()
- if turtle.getItemCount(ENERGY_CELL_SLOT)==0 then
- sleep(1)
- end
- end
- turtle.place()
- end
- function cleanup()
- turtle.select(TRASH_SLOT)
- turtle.dig()
- turtle.digUp()
- turtle.digDown()
- turtle.dropDown()
- turtle.drop()
- end
- function pack()
- turtle.select(ENERGY_CELL_SLOT)
- turtle.dig()
- turtle.dropDown()
- sleep(QUARRY_STOP_SLEEP)
- turtle.select(CHARGED_CELLS_ENDERCHEST_SLOT)
- turtle.digUp()
- turtle.select(EMPTY_CELLS_ENDERCHEST_SLOT)
- turtle.digDown()
- sleep(0.5)
- turtle.forward()
- turtle.select(QUARRY_SLOT)
- turtle.dig()
- sleep(0.5)
- turtle.forward()
- turtle.select(ITEMS_ENDERCHEST_SLOT)
- turtle.dig()
- turtle.turnRight()
- end
- function unpack()
- cleanup()
- turtle.turnLeft()
- cleanup()
- turtle.select(ITEMS_ENDERCHEST_SLOT)
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- cleanup()
- turtle.forward()
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(QUARRY_SLOT)
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- cleanup()
- turtle.forward()
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(EMPTY_CELLS_ENDERCHEST_SLOT)
- turtle.placeDown()
- turtle.select(CHARGED_CELLS_ENDERCHEST_SLOT)
- turtle.placeUp()
- recharge()
- end
- function relocate()
- for i=1,RELOCATE_DISTANCE do
- cleanup()
- turtle.forward()
- end
- end
- function cycle()
- print("waiting for quarry")
- sleep(STEP_SLEEP)
- for i=1,(STEPS_COUNT-1) do
- print("recharging")
- recharge()
- sleep(STEP_SLEEP)
- end
- print("packing")
- pack()
- print("relocating")
- relocate()
- print("unpacking")
- unpack()
- end
- function check_fuel()
- if turtle.getFuelLevel() < MIN_FUEL_FOR_CYCLE then
- -- TODO: try to get fuel from the "charged cells" enderchest
- print("not enough fuel, waiting for fuel")
- while turtle.getFuelLevel() < MIN_FUEL_FOR_CYCLE do
- sleep(5)
- turtle.select(FUEL_SLOT)
- turtle.suckUp()
- if turtle.refuel() then
- moreFuel = True
- while moreFuel do
- sleep(3)
- turtle.suckUp()
- if not turtle.refuel() then
- moreFuel = False
- turtle.dropUp()
- end
- end
- else
- turtle.dropUp() -- not fuel, return to chest
- end
- end
- end
- end
- -- ***********************************************************************
- print("starting automated quarry operation")
- while true do
- check_fuel()
- cycle()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement