Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ============================================
- -- ENCHANTMENT EXTRACTOR SORTER
- -- ============================================
- -- Checks armory cabinet every 30 seconds
- -- Enchanted items -> Extractor
- -- Non-enchanted items -> Trash
- -- ============================================
- -- ============================================
- -- CONFIGURATION - ADJUST THESE!
- -- ============================================
- local CONFIG = {
- -- Peripheral names (use "peripheral.getNames()" to find them)
- -- Or use sides like "top", "bottom", "left", "right", "front", "back"
- cabinetName = nil, -- Will auto-detect, or set manually
- disenchanterName = nil, -- Will auto-detect (works with disenchanter or extractor)
- trashName = "bottom", -- Trash can below computer
- -- Timing
- checkInterval = 30, -- Seconds between checks
- -- Debug mode (prints extra info)
- debug = true,
- }
- -- ============================================
- -- PERIPHERAL DETECTION
- -- ============================================
- local cabinet = nil
- local disenchanter = nil
- local trash = nil
- local function findPeripherals()
- local names = peripheral.getNames()
- print("Scanning peripherals...")
- for _, name in ipairs(names) do
- local pType = peripheral.getType(name)
- if CONFIG.debug then
- print(" Found: " .. name .. " (" .. pType .. ")")
- end
- -- Auto-detect cabinet (Functional Storage) - check TYPE
- if not cabinet and (pType:find("armory_cabinet") or pType:find("functionalstrorage")) then
- if CONFIG.cabinetName == nil or name == CONFIG.cabinetName then
- cabinet = peripheral.wrap(name)
- CONFIG.cabinetName = name
- print("Cabinet: " .. name)
- end
- end
- -- Auto-detect disenchanter/extractor - check TYPE
- if not disenchanter and (pType:find("disenchanter") or pType:find("enchantment_extractor")) then
- if CONFIG.disenchanterName == nil or name == CONFIG.disenchanterName then
- disenchanter = peripheral.wrap(name)
- CONFIG.disenchanterName = name
- print("Extractor: " .. name)
- end
- end
- -- Auto-detect trash - check TYPE
- if not trash and pType:find("trash") then
- if CONFIG.trashName == nil or name == CONFIG.trashName then
- trash = peripheral.wrap(name)
- CONFIG.trashName = name
- print("Trash: " .. name)
- end
- end
- end
- -- Fallback: wrap trash by configured name if not auto-detected
- if not trash and CONFIG.trashName then
- trash = peripheral.wrap(CONFIG.trashName)
- if trash then
- print("Trash: " .. CONFIG.trashName)
- end
- end
- -- Check what we found
- local ok = true
- if not cabinet then
- print("ERROR: Cabinet not found!")
- ok = false
- end
- if not disenchanter then
- print("ERROR: Extractor not found!")
- ok = false
- end
- if not trash then
- print("ERROR: Trash not found!")
- ok = false
- end
- return ok
- end
- -- ============================================
- -- ENCHANTMENT DETECTION
- -- ============================================
- local function hasEnchantments(itemDetail)
- if not itemDetail then return false end
- -- Check for enchantments table
- if itemDetail.enchantments and #itemDetail.enchantments > 0 then
- return true
- end
- -- Some mods use different field names
- if itemDetail.nbt then
- -- Items with NBT data containing enchantments
- -- The presence of certain NBT often indicates enchantments
- if type(itemDetail.nbt) == "string" and itemDetail.nbt:find("ench") then
- return true
- end
- end
- -- Check display name for "Enchanted" (fallback)
- if itemDetail.displayName and itemDetail.displayName:find("Enchanted") then
- return true
- end
- return false
- end
- -- ============================================
- -- ITEM SORTING
- -- ============================================
- local function sortItems()
- if not cabinet then
- print("No cabinet connected!")
- return
- end
- local items = cabinet.list()
- if not items or next(items) == nil then
- if CONFIG.debug then
- print("Cabinet is empty")
- end
- return
- end
- local enchantedCount = 0
- local trashedCount = 0
- for slot, item in pairs(items) do
- -- Get detailed item info to check enchantments
- local detail = cabinet.getItemDetail(slot)
- if detail then
- if hasEnchantments(detail) then
- -- Move to extractor
- if disenchanter then
- local moved = cabinet.pushItems(CONFIG.disenchanterName, slot)
- if moved and moved > 0 then
- enchantedCount = enchantedCount + moved
- if CONFIG.debug then
- print(" -> Extractor: " .. detail.displayName)
- end
- end
- end
- else
- -- Move to trash
- if trash then
- local moved = cabinet.pushItems(CONFIG.trashName, slot)
- if moved and moved > 0 then
- trashedCount = trashedCount + moved
- if CONFIG.debug then
- print(" -> Trash: " .. detail.displayName)
- end
- end
- end
- end
- end
- end
- if enchantedCount > 0 or trashedCount > 0 then
- print(string.format("Sorted: %d enchanted, %d trashed", enchantedCount, trashedCount))
- end
- end
- -- ============================================
- -- MAIN LOOP
- -- ============================================
- local function main()
- term.clear()
- term.setCursorPos(1, 1)
- print("=== ENCHANTMENT EXTRACTOR SORTER ===")
- print("")
- if not findPeripherals() then
- print("")
- print("Fix peripheral connections and reboot.")
- print("")
- print("Available peripherals:")
- for _, name in ipairs(peripheral.getNames()) do
- print(" " .. name)
- end
- return
- end
- print("")
- print("Running every " .. CONFIG.checkInterval .. " seconds...")
- print("Press Ctrl+T to stop")
- print("")
- while true do
- local time = textutils.formatTime(os.time(), false)
- print("[" .. time .. "] Checking cabinet...")
- sortItems()
- os.sleep(CONFIG.checkInterval)
- end
- end
- -- Run
- main()
Advertisement
Add Comment
Please, Sign In to add comment