TheNumbat

Untitled

Jul 15th, 2026 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 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_0" -- inventory holding items to feed
  13. local MACHINE = "gtceu:hv_input_bus_0" -- the GT input bus to feed into
  14. local MACHINE_SLOT = 1 -- which bus slot to feed
  15. local OUTPUT = "ae2:interface_0" -- 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.  
  20. local OUTPUT_ITEMS = {
  21. ["kubejs:cyan_prismatic_core"] = true,
  22. ["kubejs:active_prismatic_core"] = true,
  23. }
  24.  
  25. local SEQUENCE = {
  26. { name = "kubejs:inert_prismatic_core", count = 1 },
  27. { name = "kubejs:chromatic_stabilizer", count = 1 },
  28. { name = "kubejs:red_prismatic_core", count = 1 },
  29. { name = "kubejs:inert_prismatic_core", count = 1 },
  30. { name = "kubejs:yellow_prismatic_core", count = 1 },
  31. { name = "kubejs:chromatic_stabilizer", count = 1 },
  32. { name = "kubejs:green_prismatic_core", count = 1 },
  33. { name = "kubejs:yellow_prismatic_core", count = 1 },
  34. { name = "kubejs:cyan_prismatic_core", count = 1 },
  35. { name = "kubejs:chromatic_stabilizer", count = 1 },
  36. { name = "kubejs:blue_prismatic_core", count = 1 },
  37. { name = "kubejs:chromatic_stabilizer", count = 1 },
  38. { name = "kubejs:green_prismatic_core", count = 1 },
  39. { name = "kubejs:chromatic_stabilizer", count = 1 },
  40. { name = "kubejs:red_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. Moving selected items to output...")
  105.  
  106. -- Move only whitelisted items from the buffer to the output peripheral.
  107. local drained = 0
  108. for slot, item in pairs(buffer.list()) do
  109. if OUTPUT_ITEMS[item.name] then
  110. drained = drained + buffer.pushItems(OUTPUT, slot)
  111. end
  112. end
  113. print(("Moved %d item(s) to %s."):format(drained, OUTPUT))
Advertisement
Add Comment
Please, Sign In to add comment