Advertisement
systox

japi - github

Jan 31st, 2020
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.46 KB | None | 0 0
  1. sides = {
  2.     "front",
  3.     "bottom",
  4.     "left",
  5.     "right",
  6.     "top",
  7.     "back"
  8. }
  9.  
  10. enchatmentIDs = {
  11.     [0] = "protection",
  12.     [1] = "fire protection",
  13.     [2] = "feather falling",
  14.     [3] = "blast protection",
  15.     [4] = "projectile protection",
  16.     [5] = "respiration",
  17.     [6] = "aqua affinity",
  18.     [7] = "thorns",
  19.  
  20.     [16] = "sharpness",
  21.     [17] = "smite",
  22.     [18] = "bane of arthropods",
  23.     [19] = "knockback",
  24.     [20] = "fire aspect",
  25.     [21] = "looting",
  26.  
  27.     [32] = "efficiency",
  28.     [33] = "silk touch",
  29.     [34] = "unbreaking",
  30.     [35] = "fortune",
  31.  
  32.     [48] = "power",
  33.     [49] = "punch",
  34.     [50] = "flame",
  35.     [51] = "infinity",
  36.    
  37.     [79] = "disjunction",
  38.     [80] = "vorpal"
  39. }
  40.  
  41. modules = {
  42.     ["logisticPipes"] = {
  43.         ["localVars"] = { requestSide = "", pipe = nil },
  44.         ["request"] = {
  45.  
  46.             ["setRequestSide"] = function(requestSide)
  47.                 if checkSide(requestSide) then
  48.                     modules.logisticPipes.localVars.requestSide = requestSide
  49.                     return true
  50.                 else
  51.                     return false
  52.                 end
  53.             end,
  54.  
  55.             ["getRequestSide"] = function()
  56.                 return modules.logisticPipes.localVars.requestSide
  57.             end,
  58.            
  59.             ["initPipe"] = function()
  60.                 modules.logisticPipes.localVars.pipe = peripheral.wrap(modules.logisticPipes.localVars.requestSide)
  61.             end,
  62.  
  63.             ["getItems"] = function(get_nbt, get_damage, get_iid)
  64.                 local pipe = modules.logisticPipes.localVars.pipe
  65.                
  66.                 pipe.getAvailableItems()
  67.                
  68.                 local event, items = os.pullEvent("available_items_return")
  69.                 local converted_items = {}
  70.                 if get_nbt == nil then get_nbt = false end
  71.  
  72.                 for k,v in pairs(items) do
  73.                     itemObject = {
  74.                         ["id"] = pipe.getItemID(v[1]),
  75.                         ["amout"] = v[2]
  76.                     }
  77.  
  78.                     if get_nbt then
  79.                         nbt = convertNBT(pipe.getNBTTagCompound(v[1]))
  80.                         if nbt then itemObject["nbt"] = nbt end
  81.                     end
  82.  
  83.                     if get_damage then
  84.                         damage = pipe.getItemDamage(v[1])
  85.                         if damage then itemObject["damage"] = damage end
  86.                     end
  87.  
  88.                     if get_iid then
  89.                         itemObject["iid"] = v[1]
  90.                     end
  91.  
  92.                     table.insert( converted_items,  itemObject)
  93.                 end
  94.  
  95.                 return converted_items
  96.             end
  97.         },
  98.  
  99.         ["convert"] = {
  100.             ["getSpecificItem"] = function(items, id, multiple)
  101.                 foundItems = {}
  102.  
  103.                 for k,v in pairs(items) do
  104.                     if v["id"] == id then
  105.                         table.insert(foundItems, v)
  106.                     end
  107.                 end
  108.  
  109.                 if multiple then
  110.                     return foundItems
  111.                 else
  112.                     return foundItems[1]
  113.                 end
  114.             end,
  115.  
  116.             ["getEnchantments"] = function(item)
  117.                 senchantments = item["nbt"]["StoredEnchantments"] or item["nbt"]["ench"]
  118.                
  119.                 if senchantments == nil then
  120.                     return {}
  121.                 end
  122.  
  123.                 enchatments = {}
  124.  
  125.                 for k,v in pairs(senchantments) do
  126.                     if enchatmentIDs[v["id"]] then
  127.                         table.insert(enchatments, { ["Name"] = enchatmentIDs[v["id"]], ["Level"] = v["lvl"] })
  128.                     else
  129.                         table.insert(enchatments, { ["Name"] = v["id"], ["Level"] = v["lvl"] })
  130.                     end
  131.                 end
  132.  
  133.                 return enchatments
  134.             end
  135.         }
  136.     },
  137.  
  138.     ["appliedEnergistics"] = {
  139.         ["localVars"] = { sensorSide = "", sensor = nil, acp = nil, apiLoaded = false },
  140.         ["localFuncs"] = {
  141.             ["getSens"] = function(x,y,z)
  142.                 if not modules.appliedEnergistics.localVars.sensor then
  143.                     return false
  144.                 end
  145.  
  146.                 for k,v in pairs(modules.appliedEnergistics.localVars.sensor.getTargets()) do
  147.                     if x and y and z then
  148.                         if v.Position.x == x and v.Position.y == y and v.Position.z == z and v.Name == "Me Wireless Access Point" then
  149.                             return k
  150.                         end
  151.                     elseif v.Name == "ME Wireless Access Point" then
  152.                         return k
  153.                     end
  154.                 end
  155.             end
  156.         },
  157.         ["sensor"] = {
  158.             ["setSensorSide"] = function(sensorSide)
  159.                 if checkSide(sensorSide) then
  160.                     modules.appliedEnergistics.localVars.sensorSide = sensorSide
  161.                     return true
  162.                 else
  163.                     return false
  164.                 end
  165.             end,
  166.  
  167.             ["getSensorSide"] = function()
  168.                 return modules.appliedEnergistics.localVars.sensorSide
  169.             end,
  170.            
  171.             ["initSensor"] = function(x,y,z)
  172.                 if fs.exists("ocs/apis/sensor") then
  173.                     if not modules.appliedEnergistics.localVars.apiLoaded then
  174.                         os.loadAPI("ocs/apis/sensor")
  175.                         modules.appliedEnergistics.localVars.apiLoaded = true
  176.                     end
  177.  
  178.                     modules.appliedEnergistics.localVars.sensor = sensor.wrap(modules.appliedEnergistics.localVars.sensorSide)
  179.                     modules.appliedEnergistics.localVars.acp = modules.appliedEnergistics.localFuncs.getSens(x,y,z)
  180.                    
  181.                     return true
  182.                 else
  183.                     return false
  184.                 end
  185.             end,
  186.  
  187.             ["getItems"] = function()
  188.                 return modules.appliedEnergistics.localVars.sensor.getTargetDetails(modules.appliedEnergistics.localVars.acp).Items
  189.             end
  190.         },
  191.  
  192.         ["convert"] = {
  193.             ["getSpecificItem"] = function(items, name, multiple)
  194.                 foundItems = {}
  195.  
  196.                 for k,v in pairs(items) do
  197.                     if v["Name"] == name then
  198.                         table.insert(foundItems, v)
  199.                     end
  200.                 end
  201.  
  202.                 if multiple then
  203.                     return foundItems
  204.                 else
  205.                     return foundItems[1]
  206.                 end
  207.             end
  208.         }
  209.     }
  210. }
  211.  
  212. function convertNBT(nbt)
  213.     local conv = {}
  214.     if (nbt == nil) then
  215.         return nil
  216.     elseif (nbt["type"] == "NBTTagCompound") or (nbt["type"] == "NBTTagList") then
  217.         for key, value in pairs(nbt["value"]) do
  218.             conv[key] = convertNBT(value)
  219.         end
  220.     else
  221.         conv = nbt["value"]
  222.     end
  223.     return conv
  224. end
  225.  
  226. local function tablelength(T)
  227.     local count = 0
  228.     for _ in pairs(T) do count = count + 1 end
  229.     return count
  230. end
  231.  
  232. local function contains(value, table)
  233.     for k,v in pairs(table) do
  234.         if v == value then
  235.             return true
  236.         end
  237.     end
  238.     return false
  239. end
  240.  
  241. function checkSide(side)
  242.     return contains(side, sides)
  243. end
  244.  
  245. function getModule(modName)
  246.     if modules[modName] then
  247.         return modules[modName]
  248.     end
  249. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement