Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Item (name,damage,hash)
- local tab = {}
- tab.mode = "above"
- tab.amount = 50
- tab.fingerprint = Fingerprint(name,damage,hash)
- tab.redstone = {}
- tab.redstone.def = true
- tab.redstone.side = "top"
- tab.redstone.bundled = 0
- return tab
- end
- function Fingerprint (name,damage,hash)
- local tab = {}
- tab.id = name
- tab.dmg = damage
- tab.nbt_hash = hash
- return tab
- end
- function Set_Redstone(state,item)
- if item.redstone.bundled==0 then
- rs.setOutput(item.redstone.side,state)
- else
- signal = rs.testBundledInput(item.redstone.side,item.redstone.bundled)
- if signal ~= state then
- if signal ==true then
- rs.setBundledOutput(item.redstone.side,rs.getBundledInput(item.redstone.side) - item.redstone.bundled)
- else
- rs.setBundledOutput(item.redstone.side,rs.getBundledInput(item.redstone.side) + item.redstone.bundled)
- end
- end
- end
- end
- local items = {}
- items.levels = {}
- function PrepareConfig ()
- items.levels[1] = Item("minecraft:redstone",0,nil)
- items.interval = 5
- cfg=fs.open("config.cfg","w")
- cfg.write(textutils.serialize(items))
- cfg.flush()
- cfg.close()
- end
- function LoadConfig()
- local cfg = fs.open("config.cfg", "r")
- items = textutils.unserialize( cfg.readAll() )
- cfg.close()
- end
- local aeInterface
- function Peripherals ()
- per_list = peripheral.getNames()
- for i = 1, #per_list do
- if peripheral.getType(per_list[i]) == "tileinterface" then
- aeInterface = peripheral.wrap(per_list[i])
- return
- end
- end
- error("missing Peripherals")
- end
- function RefreshAmount ()
- for i=1, #items.levels do
- detail = aeInterface.getItemDetail(items.levels[i].fingerprint)
- if detail ~= nil then
- items.levels[i].currentAmount = detail.basic().qty
- else
- items.levels[i].currentAmount = 0
- end
- end
- end
- function LevelEmitter()
- RefreshAmount()
- for i=1,#items.levels do
- if items.levels[i].mode =="above" then
- if items.levels[i].amount<items.levels[i].currentAmount then
- Set_Redstone(true,items.levels[i])
- else
- Set_Redstone(false,items.levels[i])
- end
- else
- if items.levels[i].amount>items.levels[i].currentAmount then
- Set_Redstone(true,items.levels[i])
- else
- Set_Redstone(false,items.levels[i])
- end
- end
- end
- end
- function Reset_Redstone ()
- sides = rs.getSides()
- for i=1,#sides do
- rs.setOutput(sides[i],false)
- rs.setBundledOutput(sides[i],0)
- end
- for i = 1, #items.levels do
- Set_Redstone(items.levels[i].redstone.def,items.levels[i])
- end
- end
- if fs.exists("config.cfg") then
- LoadConfig()
- Reset_Redstone()
- Peripherals()
- sleep(5)
- while true do
- LevelEmitter()
- sleep(items.interval)
- end
- else
- PrepareConfig()
- print (" File 'config.cfg' was generated. Edit it to suit your needs and launch app again")
- end
Advertisement
Add Comment
Please, Sign In to add comment