local maxItem = 2176 --######################-- local IMPORT = true local chest = {} local hasChest = false local hasRChest = false local rChestName = "" local Int = {} local hasInt = false local hasRInt = false local rIntName = "" local directions = {"top", "bottom", "front", "back", "left", "right"} local validItems ={"Snowball","Paint Ball"} local IIDs = { "minecraft:snowball", "appliedenergistics2:item.ItemPaintBall", "appliedenergistics2:item.ItemPaintBall", "appliedenergistics2:item.ItemPaintBall", "appliedenergistics2:item.ItemPaintBall", "appliedenergistics2:item.ItemPaintBall", "appliedenergistics2:item.ItemPaintBall", "appliedenergistics2:item.ItemPaintBall", "appliedenergistics2:item.ItemPaintBall", "appliedenergistics2:item.ItemPaintBall", "appliedenergistics2:item.ItemPaintBall", "appliedenergistics2:item.ItemPaintBall", "appliedenergistics2:item.ItemPaintBall", "appliedenergistics2:item.ItemPaintBall", "appliedenergistics2:item.ItemPaintBall", "appliedenergistics2:item.ItemPaintBall", "appliedenergistics2:item.ItemPaintBall" } local IDMGs = { 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } local exportDirection = "south" local function findPeripherals() for k, v in pairs(peripheral.getNames()) do if string.find(v, "draconic_chest") then hasChest = true hasRChest = true rChestName = v term.setCursorPos(1, 1) term.write("INFO: Found remote "..v) os.sleep(1) elseif string.find(v, "tileinterface") then hasInt = true hasRInt = true rIntName = v term.setCursorPos(1, 2) term.write("INFO: Found remote "..v) os.sleep(1) end end end local function findInt() if hasRInt then return end for k, v in pairs(directions) do local p = peripheral.wrap(v) if p ~= nil then if string.find(peripheral.getType(v), "tileinterface") then Int = p hasInt = true return end end end term.setCursorPos(1, 2) term.write("ERROR: No Interface detected!") os.sleep(5) end local function findChest() if hasRChest then return end for k, v in pairs(directions) do local p = peripheral.wrap(v) if p ~= nil then if string.find(peripheral.getType(v), "draconic_chest") then chest = p hasChest = true return end end end term.setCursorPos(1, 1) term.write("WARNING: No Draconic Chest detected!") os.sleep(5) end function invSize() local chest if hasChest then chest = peripheral.call(rChestName, "getInventorySize") else chest = chest.getInventorySize() end return chest end function StackSlot(Slot) local chest if hasChest then chest = peripheral.call(rChestName, "getStackInSlot", Slot) else chest = chest.getStackInSlot(Slot) end return chest end function string.starts(String,Start) pre = string.sub(Start,1,string.len(String)) return pre == Start end function tablelength(T) local count = 0 for _ in pairs(T) do count = count + 1 end return count end function contains(table, String) for i = 1, tablelength(table), 1 do if string.starts(String, table[i]) then return true end end return false end function isValidItem(itemStack) if contains(validItems, itemStack.display_name) then return true end return false end function setGreen(sSide) rs.setBundledOutput(sSide, colors.green) end function chestEmpty() ic = 0 for i = 1, invSize() - 1, 1 do stack = StackSlot(i) if stack ~= nil then if isValidItem(stack) then ic = ic + stack.qty end end end return ic == 0 end function setRed(sSide) rs.setBundledOutput(sSide, colors.red) end function setNull(sSide) rs.setBundledOutput(sSide, 0) end function chestValid(validItemCount) if validItemCount > maxItem then term.setCursorPos(1, 3) term.write("ERROR - Chest inventory exceeds set storage limits!") elseif validItemCount == maxItem then setGreen("bottom") IMPORT = false end end local function init() findPeripherals() findChest() findInt() end init() function refill() for _, aes in pairs(Int.getAvailableItems()) do for i = 1, tablelength(IIDs), 1 do id = IIDs[i] dmg = IDMGs[i] if aes.fingerprint.id == id and aes.fingerprint.dmg == dmg then valS = 0 for j = 1, invSize() - 1, 1 do stack = StackSlot(j) if stack ~= nil then if stack.id == id and stack.dmg == dmg then valS = valS + stack.qty --print(aReq) --print(valS) end end end aReq = 128 - valS if aReq > 0 then --print(aes.size) --print(aReq) if aes.size > aReq then --Transfer items from ME to Chest (*aReq) Int.exportItem(aes.fingerprint, exportDirection, aReq) else --Transfer and request recrafting Int.requestCrafting(aes.fingerprint, 512) end end end end end end while true do if IMPORT then slot = 0 slotqt = 0 valI = 0 for CurrSlot = 1, invSize() -1, 1 do tableIS = StackSlot(CurrSlot) if tableIS ~= nil then slotqt = tableIS.qty slot = slot + slotqt if isValidItem(tableIS) then --print("valid") valI = valI + slotqt else term.setCursorPos(1, 3) term.write("Invalid Items found! (Please kill the person responsible.)") end --print("Slot Stack size: "..slotqt) --print("Total Item count: "..slot) --print("Valid Items: "..valI) end end if valI >= maxItem then chestValid(valI) else term.setCursorPos(1, 3) term.write("Refilling chest") refill() end else prevImport = IMPORT IMPORT = chestEmpty() end if not IMPORT then term.setCursorPos(1, 3) term.write("Import Process on hold until chest is emptied") sleep(2) elseif prevImport == false then term.setCursorPos(1, 3) term.write("Pausing Operations for Refilling Color Applicator") setRed("bottom") sleep(1) setNull("bottom") else sleep(5) end end