TheNumbat

Untitled

Jul 24th, 2026 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. -- sequence_feeder.lua
  2. -- Feed items into a GregTech input bus in STRICT order, one step at a time,
  3. -- using ComputerCraft (CC:Tweaked). Each step is pushed only after the
  4. -- previous one has been consumed by the machine.
  5. --
  6. -- Wiring: put a wired modem on the GT input bus AND on the buffer chest/barrel,
  7. -- connect them (and a modem on this computer) with networking cable.
  8. -- Run `peripheral.getNames()` in the Lua prompt to find the exact names,
  9. -- then fill them in below.
  10.  
  11. --========================= CONFIG =========================--
  12. local BUFFER = "minecraft:barrel_1" -- inventory holding items to feed
  13. local MACHINE = "gtceu:luv_dual_input_hatch_1" -- the GT input bus to feed into
  14. local MACHINE_SLOT = 1 -- which bus slot to feed
  15. local OUTPUT = "ae2:interface_1" -- where leftover items go when done
  16. local POLL = 0.5 -- seconds between checks
  17. local TIMEOUT = 0 -- max seconds to wait per step (0 = wait forever)
  18. local NAG = 15 -- print a "still waiting" note every N seconds
  19. local RS_SIDE = "right" -- side to pulse redstone on when done
  20. local RS_PULSE = 0.5 -- seconds to hold redstone on
  21.  
  22. local OUTPUT_ITEMS = {
  23. ["kubejs:chromatic_capacitor_empty"] = true,
  24. }
  25.  
  26. local SEQUENCE = {
  27. { name = "kubejs:chromatic_capacitor_yellow", count = 1 },
  28. { name = "kubejs:active_prismatic_core", count = 1 },
  29. { name = "kubejs:chromatic_capacitor_yellow", count = 1 },
  30. { name = "kubejs:orange_prismatic_core", count = 1 },
  31. { name = "kubejs:chromatic_stabilizer", count = 2 },
  32. { name = "kubejs:chromatic_capacitor_green", count = 1 },
  33. { name = "kubejs:lime_prismatic_core", count = 1 },
  34. { name = "kubejs:chromatic_capacitor_cyan", count = 1 },
  35. { name = "kubejs:teal_prismatic_core", count = 1 },
  36. { name = "kubejs:chromatic_stabilizer", count = 2 },
  37. { name = "kubejs:chromatic_capacitor_blue", count = 1 },
  38. { name = "kubejs:azure_prismatic_core", count = 1 },
  39. { name = "kubejs:chromatic_capacitor_magenta", count = 1 },
  40. { name = "kubejs:indigo_prismatic_core", count = 1 },
  41. }
  42.  
  43. --==========================================================--
  44.  
  45. local buffer = peripheral.wrap(BUFFER) or error("No inventory named " .. BUFFER)
  46. local machine = peripheral.wrap(MACHINE) or error("No inventory named " .. MACHINE)
  47. local output = peripheral.wrap(OUTPUT) or error("No inventory named " .. OUTPUT)
  48.  
  49. -- Find first buffer slot containing `name`.
  50. local function findSlot(inv, name)
  51. for slot, item in pairs(inv.list()) do
  52. if item.name == name then return slot end
  53. end
  54. return nil
  55. end
  56.  
  57. -- True when the target bus slot is empty (previous item consumed).
  58. local function slotEmpty()
  59. return machine.list()[MACHINE_SLOT] == nil
  60. end
  61.  
  62. -- Block until `cond()` is true. Waits forever if TIMEOUT == 0.
  63. -- Prints `msg` every NAG seconds so you can see what it's stuck on.
  64. local function waitFor(cond, msg)
  65. local waited = 0
  66. while not cond() do
  67. sleep(POLL)
  68. waited = waited + POLL
  69. if NAG > 0 and waited % NAG < POLL then
  70. print(" ...waiting: " .. msg)
  71. end
  72. if TIMEOUT > 0 and waited >= TIMEOUT then
  73. error("Timed out: " .. msg)
  74. end
  75. end
  76. end
  77.  
  78. for i, step in ipairs(SEQUENCE) do
  79. print(("Step %d/%d: %s x%d"):format(i, #SEQUENCE, step.name, step.count))
  80.  
  81. -- make sure the slot is clear before pushing
  82. waitFor(slotEmpty, "slot " .. MACHINE_SLOT .. " to clear")
  83.  
  84. local remaining = step.count
  85. while remaining > 0 do
  86. local src = findSlot(buffer, step.name)
  87. if not src then
  88. -- not in the buffer yet (e.g. an intermediate still being produced); wait
  89. waitFor(function() return findSlot(buffer, step.name) ~= nil end,
  90. step.name .. " to appear in buffer")
  91. else
  92. local moved = buffer.pushItems(MACHINE, src, remaining, MACHINE_SLOT)
  93. if moved == 0 then
  94. sleep(POLL) -- slot busy/full; wait for the machine to pull, then retry
  95. else
  96. remaining = remaining - moved
  97. end
  98. end
  99. end
  100.  
  101. waitFor(slotEmpty, step.name .. " to be consumed") -- wait for the machine to eat it
  102. end
  103.  
  104. print("Sequence complete. Pulsing redstone on " .. RS_SIDE .. "...")
  105.  
  106. -- Pulse redstone on/off before moving output.
  107. redstone.setOutput(RS_SIDE, true)
  108. sleep(RS_PULSE)
  109. redstone.setOutput(RS_SIDE, false)
  110.  
  111. print("Moving selected items to output...")
  112.  
  113. -- Move only whitelisted items from the buffer to the output peripheral.
  114. local drained = 0
  115. for slot, item in pairs(buffer.list()) do
  116. if OUTPUT_ITEMS[item.name] then
  117. drained = drained + buffer.pushItems(OUTPUT, slot)
  118. end
  119. end
  120. print(("Moved %d item(s) to %s."):format(drained, OUTPUT))
Advertisement
Add Comment
Please, Sign In to add comment