Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get Em2sZPSF Filter
- local TASK_ID_PATH = "/task_id.txt"
- local DISK_NAME = "Incoming Task"
- local strItemName = nil
- local strDisplayName = nil
- local numItems = nil
- local limitStack = 64
- local DISPLAYNAME_EXCEPTIONS = {
- ["minecraft:quartz"] = "Nether Quartz",
- ["minecraft:dragon_breath"] = "Dragon's Breath",
- ["minecraft:porkchop"] = "Raw Porkchop",
- ["minecraft:cod"] = "Raw Cod",
- ["minecraft:chicken"] = "Raw Chicken",
- ["minecraft:copper_block"] = "Block of Copper",
- ["minecraft:raw_copper_block"] = "Block of Raw Copper",
- ["minecraft:slime_ball"] = "Slimeball",
- ["minecraft:amethyst_block"] = "Block of Amethyst",
- ["minecraft:cooked_beef"] = "Steak",
- ["minecraft:redstone"] = "Redstone Dust",
- ["minecraft:redstone_block"] = "Block of Redstone",
- ["minecraft:lapis_block"] = "Block of Lapis Lazuli",
- ["minecraft:raw_iron_block"] = "Block of Raw Iron",
- ["minecraft:diamond_block"] = "Block of Diamond",
- ["minecraft:raw_gold_block"] = "Block of Raw Gold",
- -- Füge weitere Ausnahmen hier hinzu
- }
- local function isDefaultDisplayName(item)
- if not item or not item.name or not item.displayName then
- return false
- end
- -- Prüfe auf Ausnahmeliste
- local exception = DISPLAYNAME_EXCEPTIONS[item.name]
- if exception then
- return item.displayName == exception
- end
- local id = item.name:match("^[^:]+:(.+)$") -- Teil nach dem Doppelpunkt
- if not id then return false end
- -- Ersetze Unterstriche durch Leerzeichen und kapitalisiere Wörter
- local function toDisplayFormat(str)
- local words = {}
- for word in string.gmatch(str, "[^_]+") do
- table.insert(words, word:sub(1,1):upper() .. word:sub(2))
- end
- return table.concat(words, " ")
- end
- local expectedDisplay = toDisplayFormat(id)
- return item.displayName == expectedDisplay
- end
- local function getDefaultDisplayName(itemName)
- if not itemName then return nil end
- -- Extrahiere den Teil nach dem Doppelpunkt (z. B. "stone_axe")
- local id = itemName:match("^[^:]+:(.+)$")
- if not id then return nil end
- -- Ersetze Unterstriche durch Leerzeichen und kapitalisiere jedes Wort
- local words = {}
- for word in string.gmatch(id, "[^_]+") do
- table.insert(words, word:sub(1,1):upper() .. word:sub(2))
- end
- return table.concat(words, " ")
- end
- local function isMinecraftItem(item)
- return item and type(item.name) == "string" and item.name:sub(1, 10) == "minecraft:"
- end
- local function transportFirstType()
- local chestFront = peripheral.wrap("front")
- local chestBack = peripheral.wrap("back")
- local chestTop = peripheral.wrap("top")
- strItemName = nil
- strDisplayName = nil
- numItems = 0
- limitStack = 64
- local firstItemName = ""
- local bItemInChest = false
- local cnt = 1
- while cnt <= 54 do
- local item = chestFront.getItemDetail(cnt)
- if item then
- if (isDefaultDisplayName(item) or item.maxCount == 1) and isMinecraftItem(item) then
- firstItemName = item.name
- bItemInChest = true
- break
- else
- chestTop.pullItems("front", cnt)
- end
- end
- cnt = cnt + 1
- end
- if not bItemInChest then
- return false
- end
- if string.len(firstItemName) > 0 then
- local cnt = 1
- local cnt2 = 0
- strItemName = firstItemName
- strDisplayName = getDefaultDisplayName(firstItemName)
- while cnt <= 54 do
- local item = chestFront.getItemDetail(cnt)
- if item then
- if firstItemName == item.name then
- if isDefaultDisplayName(item) or item.maxCount == 1 then
- numItems = numItems + item.count
- limitStack = item.maxCount
- chestBack.pullItems("front", cnt)
- cnt2 = cnt2 + 1
- else
- chestTop.pullItems("front", cnt)
- end
- end
- if cnt2 >= 16 then
- break
- end
- end
- cnt = cnt + 1
- end
- end
- end
- local function chestEmpty(chest)
- for slot, item in pairs(chest.list()) do
- return false
- end
- return true
- end
- local function getTaskList(path)
- if not fs.exists(path) then return {} end
- local file = fs.open(path, "r")
- local data = textutils.unserialize(file.readAll())
- file.close()
- return data or {}
- end
- local function saveTaskList(path, taskList)
- local file = fs.open(path, "w")
- file.write(textutils.serialize(taskList))
- file.close()
- end
- local function addTaskToList(path, task)
- local tasks = getTaskList(path)
- table.insert(tasks, task)
- saveTaskList(path, tasks)
- end
- local function getDiskByLabel(label)
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "drive" then
- local disk = peripheral.wrap(side)
- if disk.getDiskLabel() == label then
- return disk, disk.getMountPath()
- end
- end
- end
- return nil, nil
- end
- -- Save a task (itemName, itemCount, stackLimit) to floppy disk
- local function saveTaskToDisk(itemName, itemCount, stackLimit, displayName)
- local disk, path = getDiskByLabel("Incoming Task")
- if not path then
- error("No disk detected under the computer!")
- return false
- end
- local fullPath = fs.combine(path, "task_list.txt")
- local task = {
- taskType = "store_items",
- itemName = itemName,
- itemDisplayName = displayName,
- itemCount = itemCount,
- itemStackSize = stackLimit
- }
- addTaskToList(fullPath, task)
- end
- -- Check if there are no task files currently on the disk (i.e., the slot is free)
- local function isTaskSlotFree()
- local disk, path = getDiskByLabel("Incoming Task")
- if not path then
- error("No disk detected under the computer!")
- return false
- end
- local fullPath = fs.combine(path, "task_list.txt")
- local taskList = getTaskList(fullPath)
- if #taskList == 0 then
- return true
- end
- return false
- end
- while true do
- if isTaskSlotFree() and chestEmpty(peripheral.wrap("back")) then
- transportFirstType()
- if strItemName and numItems and strDisplayName then
- saveTaskToDisk(strItemName, numItems, limitStack, strDisplayName)
- end
- else
- sleep(0.5)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment