Advertisement
kaibochan

storage.lua

Nov 6th, 2022 (edited)
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. shell.run("clear")
  2.  
  3. print("running...")
  4.  
  5. rednet.open("bottom")
  6. storage = peripheral.wrap("top")
  7.  
  8. while true do
  9.     _, msg, _ = rednet.receive("storage")
  10.  
  11.     local mArg = {}
  12.     for w in msg:gmatch("%S+") do
  13.         table.insert(mArg, w)
  14.     end
  15.  
  16.     local query = mArg[2] or ""
  17.     for i = 3, #mArg do
  18.         query = query.." "..string.lower(mArg[i])
  19.     end
  20.  
  21.     if mArg[1] == "find" then
  22.         local all = storage.list()
  23.         local foundMatch = false
  24.  
  25.         for k, item in pairs(all) do
  26.             for l = 2, #mArg do
  27.                 local i, j = string.find(item.name, mArg[l])
  28.                 if i and j then
  29.                     foundMatch = true
  30.                     break
  31.                 end
  32.             end
  33.  
  34.             if foundMatch then break end
  35.         end
  36.  
  37.         if foundMatch then
  38.             redstone.setOutput("front", true)
  39.         end
  40.  
  41.     --search by display name
  42.     elseif mArg[1] == "query" then
  43.         local foundMatch = false
  44.  
  45.         for i = 1, storage.size() do
  46.             local item = storage.getItemDetail(i)
  47.             if item then
  48.                 local i, j = string.find(string.lower(item.displayName), query)
  49.                 if i and j then
  50.                     foundMatch = true
  51.                     break
  52.                 end
  53.             end
  54.         end
  55.  
  56.         if foundMatch then
  57.             redstone.setOutput("front", true)
  58.         end
  59.  
  60.     elseif mArg[1] == "reset" then
  61.         redstone.setOutput("front", false)
  62.     elseif mArg[1] == "light" then
  63.         redstone.setOutput("front", true)
  64.     end
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement