Advertisement
MagmaLP

löschen später

Dec 2nd, 2023 (edited)
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.15 KB | None | 0 0
  1. os.loadAPI("ocs/apis/sensor")
  2. sen = sensor.wrap("top")
  3.  
  4. term.setCursorPos(1,1)
  5. term.clear()
  6. print("Neustart: System - Einrichtung")
  7. print(" ")
  8. print("Welche Seite wird erstellt: ")
  9. print("1-9 sind möglich")
  10. term.setTextColor(colors.red)
  11. Page = tonumber(read())
  12. term.setTextColor(colors.lightBlue)
  13.  
  14. --------------------------------------------------
  15. function RequestItems()
  16.     -- CONSTANTS
  17.     local PIPE_SIDE = "right"
  18.  
  19.     -- IMPLEMENTATION
  20.     function convertNBT(nbt)
  21.         local conv = {}
  22.         if (nbt == nil) then
  23.             return nil
  24.         elseif (nbt["type"] == "NBTTagCompound") or (nbt["type"] == "NBTTagList") then
  25.             for key, value in pairs(nbt["value"]) do
  26.                 conv[key] = convertNBT(value)
  27.             end
  28.         else
  29.             conv = nbt["value"]
  30.         end
  31.         return conv
  32.     end
  33.  
  34.     function getItems(pipe)
  35.         pipe.getAvailableItems()
  36.         local event, result = os.pullEvent("available_items_return")
  37.         return result
  38.     end
  39.  
  40.     function inList(item)
  41.         local id = item.id
  42.         local dmg = item.dmg
  43.         local idKey = tostring(id)
  44.         local exists, requestAmount = false, 0
  45.  
  46.         if REQUEST_IDS[id] then
  47.             if type(REQUEST_IDS[id]) == "table" then
  48.                 local variantKey = idKey .. ":" .. tostring(dmg)
  49.                 if REQUEST_IDS[id][variantKey] then
  50.                     exists = true
  51.                     requestAmount = REQUEST_IDS[id][variantKey]
  52.                 end
  53.             else
  54.                 exists = true
  55.                 requestAmount = REQUEST_IDS[id]
  56.             end
  57.         end
  58.  
  59.         return exists, requestAmount
  60.     end
  61.  
  62.     -- MAIN
  63.     local pipe = peripheral.wrap(PIPE_SIDE)
  64.     for i, result in pairs(getItems(pipe)) do
  65.         local iid, amount = unpack(result)
  66.         local item = {
  67.             id = pipe.getItemID(iid),
  68.             dmg = pipe.getItemDamage(iid),
  69.             nbt = convertNBT(pipe.getNBTTagCompound(iid))
  70.         }
  71.         local exists, requestAmount = inList(item)
  72.         if exists then
  73.             pipe.makeRequest(iid, requestAmount)
  74.             sleep(0.5)
  75.         end
  76.     end
  77. end
  78. --------------------------------------------------
  79. function gespeichert()
  80.     term.setTextColor(colors.lime)
  81.     print("gespeichert")
  82.     term.setTextColor(colors.lightBlue)    
  83. end
  84.  
  85. if fs.exists("ItemsInPage1") == false then
  86.     local file = fs.open("ItemsInPage1", "w")
  87.     file.close()
  88.     gespeichert()
  89. else
  90.     print("Es wurden bereits Items für Seite 1 festgelegt!")
  91.     print("Bestätige mit 'ja' um fortzufahren")
  92.     Eingabe = io.read()
  93.     if Eingabe == "Ja" or Eingabe == "ja" then
  94.         local file = fs.open("ItemsInPage1", "w")
  95.         file.close()
  96.         gespeichert()
  97.     else
  98.         shell.run("1")
  99.     end
  100. end
  101.    
  102.  
  103. s = sen.getTargets()
  104. function getS()
  105.     for v, k in pairs(s) do
  106.         if k.Name == "ME Wireless Access Point" then  
  107.             target = v
  108.         end
  109.     end
  110.     return target
  111. end
  112.  
  113. f = getS()
  114. s1 = sen.getTargetDetails(target)
  115. MaxItems = 0
  116.  
  117. REQUEST_IDS = {
  118.     [20] = {     ["20:0"] = 32       },
  119.     }
  120. RequestItems()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement