Advertisement
k2green

RS raw/ore depositor

Aug 18th, 2023 (edited)
1,036
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.51 KB | Gaming | 0 0
  1. local args = { ... }
  2.  
  3. local function split(str, delimeter)
  4.     local parts = {}
  5.     local current = ""
  6.  
  7.     if str ~= nil then
  8.         for i=1, #str do
  9.             local c = string.sub(str, i, i)
  10.  
  11.             if c == delimeter and #current ~= 0 then
  12.                 table.insert(parts, current)
  13.                 current = ""
  14.             else
  15.                 current = current .. c
  16.             end
  17.         end
  18.     end
  19.  
  20.     if #current ~= 0 then
  21.         table.insert(parts, current)
  22.     end
  23.  
  24.     return parts
  25. end
  26.  
  27. local function contains(list, value)
  28.     for k,v in ipairs(list) do
  29.         if v == value then
  30.             return true
  31.         end
  32.     end
  33.  
  34.     return false
  35. end
  36.  
  37. local function shouldSmelt(list, ignoreList)
  38.     local output = false
  39.  
  40.     for k1, name in ipairs(list) do
  41.         if name == "raw" or name == "ore" then
  42.             output = true
  43.         end
  44.  
  45.         if contains(ignoreList, name) then
  46.             return false
  47.         end
  48.     end
  49.  
  50.     return output
  51. end
  52.  
  53. local function getSide(splitName, sideA, sideB)
  54.     if contains(splitName, "block") then
  55.         return sideA
  56.     else
  57.         return sideB
  58.     end
  59. end
  60.  
  61. if #args < 3 then
  62.     term.setTextColor(colors.red)
  63.     term.write("Usage: rsOreDepositor <rs bridge side> <single raw item output side> <raw block output side>")
  64.     term.setTextColor(colors.white)
  65. else
  66.     local ignoreList = {}
  67.  
  68.     if fs.exists("ignoreList.txt") then
  69.         local file = fs.open("ignoreList.txt", "r")
  70.        
  71.         while true do
  72.             local line = file.readLine()
  73.  
  74.             if line == nil then
  75.                 break
  76.             else
  77.                 table.insert(ignoreList, line)
  78.             end
  79.         end
  80.  
  81.         file.close()
  82.     end
  83.  
  84.     local rsBridge = peripheral.wrap(args[1])
  85.    
  86.     while true do
  87.         local items = rsBridge.listItems()
  88.  
  89.         for k,v in ipairs(items) do
  90.             local split1 = split(v.name, ':')
  91.             local split2 = split(split1[2], "_")
  92.             local shouldSmelt = shouldSmelt(split2, ignoreList)
  93.            
  94.             if shouldSmelt then
  95.                 local side = getSide(split2, args[3], args[2])
  96.                 local amount = v.amount
  97.  
  98.                 while amount > 0 do
  99.                     local nextAmount = math.min(64, amount)
  100.                     rsBridge.exportItem({name=v.name,amount=nextAmount}, side)
  101.                     amount = amount - nextAmount
  102.                 end
  103.             end
  104.         end
  105.  
  106.         sleep(10)
  107.     end
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement