CaptainSpaceCat

Honey Block Auto

Oct 14th, 2021 (edited)
896
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.16 KB | None | 0 0
  1. local latch_time = 120
  2. local SLOT_GLASS_BOTTLE = 1
  3. local SLOT_HONEY_BOTTLE = 4
  4. local SLOT_HONEY_BLOCK = 16
  5.  
  6. local function reset()
  7.     for i = 1, 16 do
  8.         turtle.select(i)
  9.         deet = turtle.getItemDetail()
  10.         if deet then
  11.             if deet.name == "minecraft:glass_bottle" then
  12.                 turtle.transferTo(SLOT_GLASS_BOTTLE)
  13.             elseif deet.name == "minecraft:honey_bottle" then
  14.                 turtle.transferTo(SLOT_HONEY_BOTTLE)
  15.             elseif deet.name == "minecraft:honey_block" then
  16.                 turtle.dropUp()
  17.             end
  18.         end
  19.     end
  20. end
  21.  
  22.  
  23. local function reclaim()
  24.     local indices = {1, 2, 5, 6}
  25.     for i = 1, #indices do
  26.         turtle.select(indices[i])
  27.         turtle.transferTo(SLOT_GLASS_BOTTLE)
  28.     end
  29. end
  30.  
  31.  
  32. local function craft()
  33.      --craft the honey block
  34.     turtle.select(SLOT_HONEY_BOTTLE)
  35.     turtle.transferTo(1, 1)
  36.     turtle.transferTo(2, 1)
  37.     turtle.transferTo(5, 1)
  38.     turtle.transferTo(6, 1)
  39.     turtle.select(SLOT_HONEY_BLOCK)
  40.     if not turtle.craft() then
  41.         error("Failed to craft honey block")
  42.         return false
  43.     end
  44.     return true
  45. end
  46.  
  47. local function delayfn(start, delay, name)
  48.     if os.clock() - start >= delay then
  49.         error("Timelatch " .. name .. " broken")
  50.         return false
  51.     end
  52.     return true
  53. end
  54.  
  55. --class that returns true for n seconds past when this is created
  56. local function timeLatch(n, name)
  57.     latch = {}
  58.     latch.eval = delayfn
  59.     latch.start = os.clock()
  60.     latch.delay = n
  61.     latch.name = name or "latch"
  62.     return latch
  63. end
  64.  
  65. local function suckBack()
  66.     turtle.select(SLOT_HONEY_BOTTLE)
  67.     latch = timeLatch(latch_time, "SuckLatch")
  68.     while latch.eval(latch.start, latch.delay, latch.name) do
  69.         turtle.suck()
  70.         if turtle.getItemCount() == 4 then
  71.             return true
  72.         end
  73.     end
  74.  
  75.     return false
  76. end
  77.  
  78.  
  79. while true do
  80.     reset()
  81.     while true do
  82.         turtle.select(SLOT_GLASS_BOTTLE)
  83.         turtle.drop()
  84.  
  85.        
  86.         if not suckBack() or not craft() then
  87.             break
  88.         end
  89.         turtle.dropUp()
  90.         reclaim()
  91.     end
  92. end
Add Comment
Please, Sign In to add comment