Advertisement
Guest User

Chute dispenser EEPROM

a guest
Feb 17th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. -- Blueshop item chute controller
  2. -- TX = 0, RX = (Number of items)
  3. -- TX = (Number of items), RX = (0 if OK, 1 if stock too low)
  4. local network = component.proxy(component.list("modem")())
  5. local redstone = component.proxy(component.list("redstone")())
  6.  
  7. local strength = 255 -- 255 if using Project:Red, 15 if using Vanilla
  8. local stackSize = 64 -- How many items per stack, used by stock calculation
  9. local stock
  10.  
  11. network.open(120) -- Ensure that the network card is open on chute port (120)
  12. redstone.setOutput(0, 0) -- Set a known state for the dispenser output
  13. network.broadcast(120, network.address) -- Broadcast address for master unit
  14.  
  15. -- "modem_message" _ reply _ _ msg
  16. while true do
  17.   local signal = table.pack(computer.pullSignal())
  18.   if signal[1] == "modem_message" then -- New message over network
  19.     if signal[6] == 0 then -- Request system stock
  20.       network.send(signal[3], 120, checkStock())
  21.     elseif signal[6] <= stock then -- Request dispenser fire
  22.       for i = 1,signal[6],1 do
  23.         computer.pullSignal(0.1) -- Avoid system timeout errors
  24.         redstone.setOutput(0, strength) -- Best case 50% MSR, worst case 33% MSR
  25.         os.sleep(0.1)
  26.         redstone.setOutput(0, 0)
  27.         os.sleep(0.1)
  28.       end
  29.       network.send(signal[3], 120, 0)
  30.     else
  31.       network.send(signal[3], 120, -1)
  32.     end
  33.   end
  34. end
  35.  
  36. local function checkStock() -- Returns integer, containing lower-bound stock
  37.   local strength = redstone.getInput(4)
  38.   stock = math.ceil((stackSize * 54 / 14) * (strength - 1))
  39.   return max(strength, stock)
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement