Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- === CONFIG ===
- local ORB_SIDE = "right"
- local SOURCE_SIDE = "bottom"
- local MAX_ORB_SLOTS = 6
- local CHECK_INTERVAL = 2
- -- === INIT ===
- local orb = peripheral.wrap(ORB_SIDE)
- if not orb then
- error("No peripheral on " .. ORB_SIDE .. " (expected Powah Charging Orb)")
- end
- -- Sanity check: does it support inventory methods?
- if not orb.list or not orb.pullItems then
- error("Peripheral on " .. ORB_SIDE .. " is not inventory-compatible")
- end
- -- === FUNCTIONS ===
- -- Counts how many occupied slots are in the orb
- local function getOrbItemCount()
- local success, items = pcall(orb.list)
- if not success or not items then
- print("Failed to read orb inventory")
- return -1
- end
- local count = 0
- for slot, item in pairs(items) do
- if item then
- count = count + 1
- end
- end
- return count
- end
- -- Tries to find an item in the source inventory and insert it into the orb
- local function moveOneItem()
- for slot = 1, 27 do
- local detail = peripheral.call(SOURCE_SIDE, "getItemDetail", slot)
- if detail then
- print("Found item in source slot " .. slot .. ": " .. detail.name)
- local moved = orb.pullItems(SOURCE_SIDE, slot, 1)
- if moved > 0 then
- print("Moved 1 item into orb.")
- else
- print("Item move failed.")
- end
- return
- end
- end
- print("No items found in source to move.")
- end
- -- === MAIN LOOP ===
- while true do
- print("Checking orb inventory...")
- local orbCount = getOrbItemCount()
- if orbCount == -1 then
- print("Skipping this cycle due to read error.")
- elseif orbCount == 5 then
- print("Orb has exactly 5 items. Attempting to insert 1 more...")
- moveOneItem()
- else
- print("Orb has " .. orbCount .. " item(s). Waiting...")
- end
- sleep(CHECK_INTERVAL)
- end
Add Comment
Please, Sign In to add comment