Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- CONFIGURATION
- local MODEM_SIDE = "top"
- local CHEST_SIDE = "bottom"
- local HATCH_TYPE = "modern_industrialization:steel_item_input_hatch"
- local MAX_ATTEMPTS = 7
- local RETRY_DELAY = 1.5
- -- Initialize modem
- local modem = peripheral.wrap(MODEM_SIDE)
- if not modem then error("No modem on "..MODEM_SIDE) end
- rednet.open(MODEM_SIDE)
- -- Rubber sheet workaround
- local RUBBER_SHEET = "modern_industrialization:rubber_sheet"
- local RUBBER_FIX = false -- Set to true if rubber sheets fail
- -- Enhanced diagnostics with slot analysis
- local function diagnoseTransferFailure(chest, hatchName, slot, item)
- print("--- TRANSFER FAILURE DIAGNOSTICS ---")
- print("Item: "..item.name.." x"..item.count)
- local hatch = peripheral.wrap(hatchName)
- if not hatch then
- print("❌ Hatch inaccessible via network")
- return
- end
- -- Detailed slot analysis
- print("Hatch slot status:")
- for s = 1, hatch.size() do -- Explicit slot iteration
- local itemDetail = hatch.getItemDetail(s)
- if itemDetail then
- print(string.format("Slot %d: %s x%d/%d (%s)",
- s, itemDetail.name, itemDetail.count, itemDetail.maxCount,
- itemDetail.name == item.name and "MATCH" or "DIFFERENT ITEM"))
- else
- print(string.format("Slot %d: Empty", s))
- end
- end
- -- Rubber sheet specific test
- if item.name == RUBBER_SHEET then
- print("\nRubber Sheet Special Test:")
- local testItem = {name=RUBBER_SHEET, count=1}
- -- Try inserting directly into each slot
- for s = 1, hatch.size() do
- local success, reason = pcall(hatch.insertItem, hatch, testItem, s)
- print(string.format("Slot %d insert: %s",
- s, success and "✅ Success" or "❌ Failed: "..(reason or "unknown")))
- end
- end
- end
- -- Smart transfer with slot management
- local function transferItems(hatchName)
- local chest = peripheral.wrap(CHEST_SIDE)
- if not chest then error("No chest on "..CHEST_SIDE) end
- print("\nStarting transfer to "..hatchName)
- local totalTransferred = 0
- local hatch = peripheral.wrap(hatchName)
- for slot, item in pairs(chest.list()) do
- local remaining = item.count
- local attempts = 0
- while remaining > 0 and attempts < 3 do
- attempts = attempts + 1
- local transferAmount = math.min(remaining, 64)
- -- Rubber sheet workaround
- if RUBBER_FIX and item.name == RUBBER_SHEET then
- local success = false
- -- Try each hatch slot individually
- for s = 1, hatch.size() do
- local targetSlot = hatch.getItemDetail(s)
- if not targetSlot or targetSlot.name == RUBBER_SHEET then
- success = pcall(chest.pushItems, hatchName, slot, transferAmount, s)
- if success then break end
- end
- end
- if success then
- print("✓ Rubber sheets transferred with slot workaround")
- totalTransferred = totalTransferred + transferAmount
- remaining = remaining - transferAmount
- end
- else
- -- Standard transfer
- local success, transferred = pcall(chest.pushItems, hatchName, slot, transferAmount)
- if success and transferred > 0 then
- print("✓ Transferred "..transferred.."x "..item.name)
- totalTransferred = totalTransferred + transferred
- remaining = remaining - transferred
- else
- print("⚠ Failed to transfer "..transferAmount.."x "..item.name)
- if attempts >= 2 then
- diagnoseTransferFailure(chest, hatchName, slot, item)
- end
- end
- end
- os.sleep(0.5) -- Brief pause between attempts
- end
- end
- return totalTransferred
- end
- -- Hatch finder with multiblock validation
- local function findHatch()
- for attempt = 1, MAX_ATTEMPTS do
- local peripherals = modem.getNamesRemote() or {}
- for _, name in ipairs(peripherals) do
- if peripheral.getType(name) == HATCH_TYPE then
- -- Validate multiblock connection
- local hatch = peripheral.wrap(name)
- if pcall(hatch.size) then -- Basic functionality check
- print("Validated hatch: "..name)
- return name
- end
- end
- end
- os.sleep(RETRY_DELAY)
- end
- return nil
- end
- -- Main execution
- print("\n===== MI INPUT HATCH TRANSFER SYSTEM =====")
- local hatchName = findHatch()
- if not hatchName then
- print("❌ Hatch not found after "..MAX_ATTEMPTS.." attempts")
- return
- end
- print("\nTransferring items...")
- local startTime = os.clock()
- local transferred = transferItems(hatchName)
- local duration = os.clock() - startTime
- print("\nResult: "..transferred.." items transferred in "..string.format("%.2f", duration).."s")
- -- Enable rubber fix if any rubber sheets failed
- if transferred > 0 and RUBBER_FIX == false then
- print("\nTip: If rubber sheets failed, set RUBBER_FIX = true")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement