Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Wrap peripherals
- local me = peripheral.wrap("bottom") -- ME Bridge below
- local drawer = peripheral.wrap("left") -- Drawer to the left
- local monitor = peripheral.find("monitor") -- Find connected monitor
- -- Setup monitor
- monitor.setTextScale(0.5)
- monitor.clear()
- local line = 1
- -- Helper function to log to monitor with timestamp
- local function log(message)
- local time = textutils.formatTime(os.time(), true)
- monitor.setCursorPos(1, line)
- monitor.write("[" .. time .. "] " .. message)
- line = line + 1
- if line > 20 then
- monitor.scroll(1)
- line = 20
- end
- end
- -- Example item name (Stone Essence from Mystical Agriculture)
- -- This will be overridden by whatever is in the drawer
- local exampleItem = "mysticalagriculture:stone_essence"
- -- Detect item stored in drawer
- local drawerContents = drawer.list()
- local itemName = nil
- for _, item in pairs(drawerContents) do
- itemName = item.name
- break -- only one slot in 1x1 drawer
- end
- if not itemName then
- log("No item found in drawer.")
- return
- end
- log("🔍 Detected item: " .. itemName .. " (e.g., " .. exampleItem .. ")")
- -- Step 1: Extract all matching items from ME into drawer
- local items = me.getItems()
- for _, item in pairs(items) do
- if item.name == itemName then
- local remaining = item.amount
- while remaining > 0 do
- local toExtract = math.min(remaining, 64)
- local extracted = me.exportItem({
- name = item.name,
- count = toExtract
- }, "left")
- log("Extracted " .. extracted .. " " .. itemName .. " to drawer")
- remaining = remaining - extracted
- if extracted == 0 then break end
- end
- end
- end
- -- Step 2: Re-insert all matching items from drawer back to ME
- for slot, item in pairs(drawer.list()) do
- if item.name == itemName then
- local remaining = item.count
- while remaining > 0 do
- local toInsert = math.min(remaining, 64)
- local inserted = me.importItem({
- name = item.name,
- count = toInsert
- }, "left", slot)
- log("Inserted " .. inserted .. " " .. itemName .. " from drawer slot " .. slot)
- remaining = remaining - inserted
- if inserted == 0 then break end
- end
- end
- end
- log("Cycle complete for item: " .. itemName)
Advertisement
Add Comment
Please, Sign In to add comment