Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local latch_time = 120
- local SLOT_GLASS_BOTTLE = 1
- local SLOT_HONEY_BOTTLE = 4
- local SLOT_HONEY_BLOCK = 16
- local function reset()
- for i = 1, 16 do
- turtle.select(i)
- deet = turtle.getItemDetail()
- if deet then
- if deet.name == "minecraft:glass_bottle" then
- turtle.transferTo(SLOT_GLASS_BOTTLE)
- elseif deet.name == "minecraft:honey_bottle" then
- turtle.transferTo(SLOT_HONEY_BOTTLE)
- elseif deet.name == "minecraft:honey_block" then
- turtle.dropUp()
- end
- end
- end
- end
- local function reclaim()
- local indices = {1, 2, 5, 6}
- for i = 1, #indices do
- turtle.select(indices[i])
- turtle.transferTo(SLOT_GLASS_BOTTLE)
- end
- end
- local function craft()
- --craft the honey block
- turtle.select(SLOT_HONEY_BOTTLE)
- turtle.transferTo(1, 1)
- turtle.transferTo(2, 1)
- turtle.transferTo(5, 1)
- turtle.transferTo(6, 1)
- turtle.select(SLOT_HONEY_BLOCK)
- if not turtle.craft() then
- error("Failed to craft honey block")
- return false
- end
- return true
- end
- local function delayfn(start, delay, name)
- if os.clock() - start >= delay then
- error("Timelatch " .. name .. " broken")
- return false
- end
- return true
- end
- --class that returns true for n seconds past when this is created
- local function timeLatch(n, name)
- latch = {}
- latch.eval = delayfn
- latch.start = os.clock()
- latch.delay = n
- latch.name = name or "latch"
- return latch
- end
- local function suckBack()
- turtle.select(SLOT_HONEY_BOTTLE)
- latch = timeLatch(latch_time, "SuckLatch")
- while latch.eval(latch.start, latch.delay, latch.name) do
- turtle.suck()
- if turtle.getItemCount() == 4 then
- return true
- end
- end
- return false
- end
- while true do
- reset()
- while true do
- turtle.select(SLOT_GLASS_BOTTLE)
- turtle.drop()
- if not suckBack() or not craft() then
- break
- end
- turtle.dropUp()
- reclaim()
- end
- end
Add Comment
Please, Sign In to add comment