Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- quarry
- -- "swapper" (engineering turtle (turtle+crescent hammer)) must face NORTH
- -- "mover" (digging turtle) must face the swapper from the right (should face west)
- -- the quarry, 3 enderchests and a power cell must be placed at the beginning
- local args = {...}
- local role = args[1]
- 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 = 360
- local MEETING_SLEEP = 5
- local MOVING_SLEEP = 1
- local QUARRY_STOP_SLEEP = 45 -- wait for the quarry to stop after disconnecting power
- local WAIT_FOR_MOVER = 20
- function saveState(state)
- f = fs.open("state","w")
- f.write(tostring(state))
- f.close()
- end
- function swapper_recharge()
- turtle.select(ENERGY_CELL_SLOT)
- turtle.dig()
- turtle.dropDown()
- while turtle.getItemCount(ENERGY_CELL_SLOT)==0 do
- turtle.suckUp()
- end
- turtle.place()
- end
- function swapper_pack()
- turtle.select(ENERGY_CELL_SLOT)
- turtle.dig()
- turtle.dropDown()
- sleep(QUARRY_STOP_SLEEP)
- turtle.back() -- make room for mover
- turtle.turnLeft()
- while not(turtle.forward()) do
- sleep(1)
- end
- sleep(1)
- while not(turtle.forward()) do
- sleep(1)
- end
- turtle.turnRight()
- print("giving mover time to relocate in front of swapper")
- sleep(WAIT_FOR_MOVER)
- end
- function swapper_relocate()
- for i=1,RELOCATE_DISTANCE do
- sleep(MOVING_SLEEP)
- while not turtle.forward() do
- print("couldn't move forward, sleeping for a while")
- sleep(MOVING_SLEEP)
- end
- end
- end
- function swapper_unpack()
- turtle.turnRight()
- while not(turtle.forward()) do
- print("couldn't move forward, sleeping for a while")
- sleep(1)
- end
- sleep(1)
- while not(turtle.forward()) do
- print("couldn't move forward, sleeping for a while")
- sleep(1)
- end
- turtle.turnLeft()
- sleep(WAIT_FOR_MOVER)
- while not turtle.forward() do
- sleep(MEETING_SLEEP)
- end
- swapper_recharge()
- end
- function swapper_cycle()
- for i=1,(STEPS_COUNT-1) do
- print("giving quarry time")
- sleep(STEP_SLEEP)
- print("recharging quarry")
- swapper_recharge()
- end
- print("giving quarry time")
- sleep(STEP_SLEEP)
- print("packing")
- swapper_pack()
- print("relocating")
- swapper_relocate()
- print("unpacking")
- swapper_unpack()
- end
- function mover_cleanup()
- turtle.select(TRASH_SLOT)
- turtle.dig()
- turtle.digUp()
- turtle.digDown()
- turtle.dropDown()
- turtle.drop()
- end
- function mover_pack()
- turtle.select(CHARGED_CELLS_ENDERCHEST_SLOT)
- turtle.digUp()
- turtle.select(EMPTY_CELLS_ENDERCHEST_SLOT)
- turtle.digDown()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turtle.select(QUARRY_SLOT)
- turtle.dig()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turtle.select(ITEMS_ENDERCHEST_SLOT)
- turtle.dig()
- end
- function mover_unpack()
- mover_cleanup()
- turtle.select(ITEMS_ENDERCHEST_SLOT)
- turtle.place()
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- mover_cleanup()
- turtle.select(QUARRY_SLOT)
- turtle.place()
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- mover_cleanup()
- turtle.select(EMPTY_CELLS_ENDERCHEST_SLOT)
- turtle.placeDown()
- turtle.select(CHARGED_CELLS_ENDERCHEST_SLOT)
- turtle.placeUp()
- turtle.turnLeft()
- turtle.back()
- sleep(MEETING_SLEEP)
- end
- function mover_relocate()
- for i=1,RELOCATE_DISTANCE do
- mover_cleanup()
- turtle.forward()
- end
- end
- function mover_cycle()
- sleep(STEPS_COUNT*STEP_SLEEP+QUARRY_STOP_SLEEP)
- while not(turtle.forward()) do
- sleep(MEETING_SLEEP)
- end
- sleep(MEETING_SLEEP)
- turtle.turnRight()
- mover_pack()
- sleep(2)
- mover_relocate()
- mover_unpack()
- end
- function check_fuel()
- if turtle.getFuelLevel() < MIN_FUEL_FOR_CYCLE then
- print("not enough fuel, waiting for fuel")
- while turtle.getFuelLevel() < MIN_FUEL_FOR_CYCLE do
- sleep(2)
- turtle.select(FUEL_SLOT)
- turtle.refuel()
- end
- end
- end
- -- ***********************************************************************
- if role=="swapper" then
- print("starting swapper")
- while true do
- check_fuel()
- swapper_cycle()
- end
- elseif role=="mover" then
- print("starting mover")
- while true do
- check_fuel()
- mover_cycle()
- end
- else
- print("invalid parameter, expecting 'mover' or 'swapper'")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement