Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- livingstuff v0.1
- local SLOT_INPUT = 1
- local SLOT_OUTPUT = 15
- local SLOT_TRASH = 3
- local SLEEP_TIME = 60
- function trydig(slot)
- turtle.select(slot)
- if turtle.detect() then
- turtle.dig()
- end
- end
- function trydigup(slot)
- turtle.select(slot)
- if turtle.detectUp() then
- turtle.digUp()
- end
- end
- function trydigdown(slot)
- turtle.select(slot)
- if turtle.detectDown() then
- turtle.digDown()
- end
- end
- function digforward(slot)
- trydig(slot)
- turtle.forward()
- end
- function digright(slot)
- turtle.turnRight()
- digforward(slot)
- end
- function digup(slot)
- trydigup(slot)
- turtle.up()
- end
- function digback(slot)
- turtle.turnRight()
- turtle.turnRight()
- digforward(slot)
- end
- function digleft(slot)
- turtle.turnLeft()
- digforward(slot)
- end
- function digdown(slot)
- trydigdown(slot)
- turtle.down()
- end
- function digloop(slot)
- for _ = 1, 4 do
- digright(slot)
- digforward(slot)
- end
- digup(slot)
- end
- function placedown()
- turtle.select(SLOT_TRASH)
- turtle.digDown()
- if turtle.getItemCount(SLOT_INPUT) > 0 then
- turtle.select(SLOT_INPUT)
- turtle.placeDown()
- elseif turtle.getItemCount(SLOT_INPUT + 1) > 0 then
- turtle.select(SLOT_INPUT + 1)
- turtle.placeDown()
- end
- end
- function placeloop()
- for _ = 1, 4 do
- digright(SLOT_TRASH)
- placedown()
- digforward(SLOT_TRASH)
- placedown()
- end
- digup(SLOT_TRASH)
- end
- -- always from neutral pos
- function deposit_trash()
- digback(SLOT_TRASH)
- digforward(SLOT_TRASH)
- digforward(SLOT_TRASH)
- digright(SLOT_TRASH)
- digforward(SLOT_TRASH)
- digdown(SLOT_TRASH)
- digdown(SLOT_TRASH)
- for i = SLOT_TRASH, SLOT_OUTPUT - 1 do
- turtle.select(i)
- turtle.dropRight()
- end
- digup(SLOT_TRASH)
- digup(SLOT_TRASH)
- digback(SLOT_TRASH)
- digforward(SLOT_TRASH)
- digleft(SLOT_TRASH)
- digforward(SLOT_TRASH)
- digforward(SLOT_TRASH)
- end
- function deposit_output()
- digright(SLOT_TRASH)
- for _ = 1, 5 do
- digforward(SLOT_TRASH)
- end
- digdown(SLOT_TRASH)
- for i = SLOT_OUTPUT, SLOT_OUTPUT + 1 do
- turtle.select(i)
- turtle.dropDown()
- end
- digup(SLOT_TRASH)
- digback(SLOT_TRASH)
- for _ = 1, 5 do
- digforward(SLOT_TRASH)
- end
- turtle.turnRight()
- end
- function start()
- turtle.select(1)
- -- count loops to make
- local items_left = turtle.getItemCount(SLOT_INPUT) + turtle.getItemCount(SLOT_INPUT + 1)
- local output_left = turtle.getItemCount(SLOT_OUTPUT) + turtle.getItemCount(SLOT_OUTPUT + 1)
- local trash_left = 0
- for i = SLOT_TRASH, SLOT_OUTPUT - 1 do
- trash_left = trash_left + turtle.getItemCount(i)
- end
- local loopcount = math.ceil(items_left / 8)
- -- Now we know how many times we want to put down items, then pick them all up
- -- Notably, this can never be more than 16: I's only checked once.
- -- This means 2 slots will always hold all initial items!
- if items_left == 0 then
- print("Zero items given?")
- return
- end
- if trash_left > 0 then
- deposit_trash()
- end
- if output_left > 0 then
- deposit_output()
- end
- -- start the choreography
- for i = 1, loopcount do
- digdown(SLOT_TRASH)
- placeloop()
- digup(SLOT_TRASH)
- placeloop()
- -- wait for transmutation
- os.sleep(SLEEP_TIME)
- -- dig down twice
- digdown(SLOT_OUTPUT)
- digdown(SLOT_OUTPUT)
- -- go through other blocks
- digloop(SLOT_OUTPUT)
- digloop(SLOT_OUTPUT)
- end
- deposit_output()
- deposit_trash()
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement