Advertisement
MagmaLP

CC Logistic Extraction Test

Nov 22nd, 2023 (edited)
648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.96 KB | None | 0 0
  1. -- CONSTANTS
  2. local INTERVAL = 120
  3. local PIPE_SIDE = "bottom"
  4. local REQUEST_IDS = {
  5.  
  6.     -- Beispiel für IDs mit Varianten
  7.     [183] = {      
  8.         ["183:1"] = 5,  -- Beispiel-Menge: 5 für ID 183:1
  9.         ["183:2"] = 3,  -- Beispiel-Menge: 3 für ID 183:2
  10.     },
  11.  
  12.     -- ... andere IDs ...
  13.     [267] = 10,   -- Iron (Beispiel-Menge: 10)
  14. }
  15.  
  16. -- IMPLEMENTATION
  17. function convertNBT(nbt)
  18.     local conv = {}
  19.     if (nbt == nil) then
  20.         return nil
  21.     elseif (nbt["type"] == "NBTTagCompound") or (nbt["type"] == "NBTTagList") then
  22.         for key, value in pairs(nbt["value"]) do
  23.             conv[key] = convertNBT(value)
  24.         end
  25.     else
  26.         conv = nbt["value"]
  27.     end
  28.     return conv
  29. end
  30.  
  31. function getItems(pipe)
  32.     pipe.getAvailableItems()
  33.     local event, result = os.pullEvent("available_items_return")
  34.     return result
  35. end
  36.  
  37. function inList(item)
  38.     local id = item.id
  39.     local dmg = item.dmg
  40.     local idKey = tostring(id)
  41.     local exists, requestAmount = false, 0
  42.  
  43.     if REQUEST_IDS[id] then
  44.         if type(REQUEST_IDS[id]) == "table" then
  45.             local variantKey = idKey .. ":" .. tostring(dmg)
  46.             if REQUEST_IDS[id][variantKey] then
  47.                 exists = true
  48.                 requestAmount = REQUEST_IDS[id][variantKey]
  49.             end
  50.         else
  51.             exists = true
  52.             requestAmount = REQUEST_IDS[id]
  53.         end
  54.     end
  55.  
  56.     return exists, requestAmount
  57. end
  58.  
  59. -- MAIN
  60. local pipe = peripheral.wrap(PIPE_SIDE)
  61. while true do
  62.     for i, result in pairs(getItems(pipe)) do
  63.         local iid, amount = unpack(result)
  64.         local item = {
  65.             id = pipe.getItemID(iid),
  66.             dmg = pipe.getItemDamage(iid),
  67.             nbt = convertNBT(pipe.getNBTTagCompound(iid))
  68.         }
  69.         local exists, requestAmount = inList(item)
  70.         if exists then
  71.             pipe.makeRequest(iid, requestAmount)
  72.             sleep(2)
  73.         end
  74.     end
  75.     sleep(INTERVAL)
  76. end
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement