Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2025
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None | 0 0
  1. -- CONFIGURATION
  2. local MODEM_SIDE = "top"
  3. local CHEST_SIDE = "bottom"
  4. local HATCH_TYPE = "modern_industrialization:steel_item_input_hatch"
  5. local MAX_ATTEMPTS = 7
  6. local RETRY_DELAY = 1.5
  7.  
  8. -- Initialize modem
  9. local modem = peripheral.wrap(MODEM_SIDE)
  10. if not modem then error("No modem on "..MODEM_SIDE) end
  11. rednet.open(MODEM_SIDE)
  12.  
  13. -- Rubber sheet workaround
  14. local RUBBER_SHEET = "modern_industrialization:rubber_sheet"
  15. local RUBBER_FIX = false -- Set to true if rubber sheets fail
  16.  
  17. -- Enhanced diagnostics with slot analysis
  18. local function diagnoseTransferFailure(chest, hatchName, slot, item)
  19. print("--- TRANSFER FAILURE DIAGNOSTICS ---")
  20. print("Item: "..item.name.." x"..item.count)
  21.  
  22. local hatch = peripheral.wrap(hatchName)
  23. if not hatch then
  24. print("❌ Hatch inaccessible via network")
  25. return
  26. end
  27.  
  28. -- Detailed slot analysis
  29. print("Hatch slot status:")
  30. for s = 1, hatch.size() do -- Explicit slot iteration
  31. local itemDetail = hatch.getItemDetail(s)
  32. if itemDetail then
  33. print(string.format("Slot %d: %s x%d/%d (%s)",
  34. s, itemDetail.name, itemDetail.count, itemDetail.maxCount,
  35. itemDetail.name == item.name and "MATCH" or "DIFFERENT ITEM"))
  36. else
  37. print(string.format("Slot %d: Empty", s))
  38. end
  39. end
  40.  
  41. -- Rubber sheet specific test
  42. if item.name == RUBBER_SHEET then
  43. print("\nRubber Sheet Special Test:")
  44. local testItem = {name=RUBBER_SHEET, count=1}
  45.  
  46. -- Try inserting directly into each slot
  47. for s = 1, hatch.size() do
  48. local success, reason = pcall(hatch.insertItem, hatch, testItem, s)
  49. print(string.format("Slot %d insert: %s",
  50. s, success and "✅ Success" or "❌ Failed: "..(reason or "unknown")))
  51. end
  52. end
  53. end
  54.  
  55. -- Smart transfer with slot management
  56. local function transferItems(hatchName)
  57. local chest = peripheral.wrap(CHEST_SIDE)
  58. if not chest then error("No chest on "..CHEST_SIDE) end
  59.  
  60. print("\nStarting transfer to "..hatchName)
  61. local totalTransferred = 0
  62. local hatch = peripheral.wrap(hatchName)
  63.  
  64. for slot, item in pairs(chest.list()) do
  65. local remaining = item.count
  66. local attempts = 0
  67.  
  68. while remaining > 0 and attempts < 3 do
  69. attempts = attempts + 1
  70. local transferAmount = math.min(remaining, 64)
  71.  
  72. -- Rubber sheet workaround
  73. if RUBBER_FIX and item.name == RUBBER_SHEET then
  74. local success = false
  75.  
  76. -- Try each hatch slot individually
  77. for s = 1, hatch.size() do
  78. local targetSlot = hatch.getItemDetail(s)
  79. if not targetSlot or targetSlot.name == RUBBER_SHEET then
  80. success = pcall(chest.pushItems, hatchName, slot, transferAmount, s)
  81. if success then break end
  82. end
  83. end
  84.  
  85. if success then
  86. print("✓ Rubber sheets transferred with slot workaround")
  87. totalTransferred = totalTransferred + transferAmount
  88. remaining = remaining - transferAmount
  89. end
  90. else
  91. -- Standard transfer
  92. local success, transferred = pcall(chest.pushItems, hatchName, slot, transferAmount)
  93. if success and transferred > 0 then
  94. print("✓ Transferred "..transferred.."x "..item.name)
  95. totalTransferred = totalTransferred + transferred
  96. remaining = remaining - transferred
  97. else
  98. print("⚠ Failed to transfer "..transferAmount.."x "..item.name)
  99. if attempts >= 2 then
  100. diagnoseTransferFailure(chest, hatchName, slot, item)
  101. end
  102. end
  103. end
  104.  
  105. os.sleep(0.5) -- Brief pause between attempts
  106. end
  107. end
  108.  
  109. return totalTransferred
  110. end
  111.  
  112. -- Hatch finder with multiblock validation
  113. local function findHatch()
  114. for attempt = 1, MAX_ATTEMPTS do
  115. local peripherals = modem.getNamesRemote() or {}
  116.  
  117. for _, name in ipairs(peripherals) do
  118. if peripheral.getType(name) == HATCH_TYPE then
  119. -- Validate multiblock connection
  120. local hatch = peripheral.wrap(name)
  121. if pcall(hatch.size) then -- Basic functionality check
  122. print("Validated hatch: "..name)
  123. return name
  124. end
  125. end
  126. end
  127.  
  128. os.sleep(RETRY_DELAY)
  129. end
  130. return nil
  131. end
  132.  
  133. -- Main execution
  134. print("\n===== MI INPUT HATCH TRANSFER SYSTEM =====")
  135. local hatchName = findHatch()
  136.  
  137. if not hatchName then
  138. print("❌ Hatch not found after "..MAX_ATTEMPTS.." attempts")
  139. return
  140. end
  141.  
  142. print("\nTransferring items...")
  143. local startTime = os.clock()
  144. local transferred = transferItems(hatchName)
  145. local duration = os.clock() - startTime
  146.  
  147. print("\nResult: "..transferred.." items transferred in "..string.format("%.2f", duration).."s")
  148.  
  149. -- Enable rubber fix if any rubber sheets failed
  150. if transferred > 0 and RUBBER_FIX == false then
  151. print("\nTip: If rubber sheets failed, set RUBBER_FIX = true")
  152. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement