Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Multi Emitter 1.0.2 for AE2
- --written by Draddy
- local me --ME System
- local monitor --Monitor
- local modem = nil --Modem for Remote Monitor
- local cablePos --Redstone BundledCable
- local cols = 0 --set Redstone Colors
- local useRemote = true --switch on/off Remoteservice
- local activ={} --helping Array for emit status
- local file = "disk/emitList"--the List File
- local lastFileSize = 0 --size of list file on last read (so read can skipped it file isn't changed
- local meItems = {} --workspace after file is read MOVED TO emitList!
- --get the peripherals
- function initPeripherals()
- local per = peripheral.getNames()
- for i=1,#per do
- --Monitor
- if peripheral.getType(per[i]) == "monitor" then
- monitor = peripheral.wrap(per[i])
- --Modem(s)
- elseif peripheral.getType(per[i]) == "modem" then
- m = peripheral.wrap(per[i])
- if m.isWireless() and useRemote then
- modem = peripheral.wrap(per[i])
- os.loadAPI("disk/wirelessSend.lua")
- else
- cModem = peripheral.wrap(per[i])
- end
- --bundeld Redstone cable
- elseif peripheral.getType(per[i]) == "ccmp:saved_multipart" then
- cablePos = per[i]
- --ME System
- elseif string.find(peripheral.getType(per[i]), "appliedenergistics2:") then
- me = peripheral.wrap(per[i])
- end
- end
- end
- --readFile if changed since last read
- function readFile ()
- runs = true
- running = true
- while runs do
- f = fs.open(file, "r")
- if f then runs = false else err1="no file@ ".. getTime() end
- end
- if err1 then print(err1) end
- err1 = nil
- fileSize = fs.getSize(file)
- if fileSize ~= lastFileSize then
- lastFileSize = fileSize
- meItems = {}
- while running do
- t = f.readLine()
- if t == nil then
- running = false
- else
- tT = textutils.unserialise(t)
- table.insert(meItems, tT)
- end
- end
- print("file read@ " .. getTime())
- end
- end
- --clear Monitor(s)
- function clearMon()
- if modem then wirelessSend.remoteColors(colors.black, colors.white) end
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- monitor.setCursorPos(1,1)
- centerT(" Multi Emitter ", 1, colors.gray, colors.purple, "head")
- centerT("Count ", 2, colors.black, colors.purple, "left")
- centerT("Item", 2, colors.black, colors.purple, "left2")
- centerT("Signal", 2, colors.black, colors.purple, "right")
- end
- --bring text to Monitor(s)
- function centerT(text, line, txtback, txtcolor, pos)
- monX,monY = monitor.getSize()
- monitor.setBackgroundColor(txtback)
- monitor.setTextColor(txtcolor)
- length = string.len(text)
- dif = math.floor(monX-length)
- x = math.floor(dif/2)
- if modem then
- remX, remY = wirelessSend.remoteSize()
- rDif = math.floor(remX-length)
- rX = math.floor(rDif/2)
- end
- if pos == "head" then
- monitor.setCursorPos(x+1, line)
- monitor.write(text)
- if modem then wirelessSend.remoteOutput(text, txtback, txtcolor, rX+1, line, false) end
- elseif pos == "left" then
- monitor.setCursorPos(2, line)
- monitor.clearLine()
- monitor.write(text)
- if modem then wirelessSend.remoteOutput(text, txtback, txtcolor, 2, line, true) end
- elseif pos == "left2" then
- monitor.setCursorPos(10, line)
- monitor.write(text)
- if modem then wirelessSend.remoteOutput(text, txtback, txtcolor, 10, line, false) end
- elseif pos == "right" then
- monitor.setCursorPos(monX-length, line)
- monitor.write(text)
- if modem then wirelessSend.remoteOutput(text, txtback, txtcolor, remX-length, line, false) end
- end
- end
- --set new Redstone Outputs
- function setCable()
- rs.setBundledOutput(cablePos, cols)
- end
- --get values from ME System and set outputs
- function checkMe()
- local i = 3
- cols = 0
- tCol = colors.white
- for a = 1, #meItems do
- w = a
- pcall(getItem) --pcall to prevent nullPointer error
- if sItem == "null" then --if item not in ME System, set to emit/produce
- if i%2==1 then tCol=colors.lightGray else tCol=colors.white end
- centerT("0",i, colors.black, tCol, "left")
- centerT(meItems[a].displayName, i, colors.black, tCol, "left2")
- if meItems[a].emit == "low" then
- cols = cols+colors[meItems[a].color]
- activ[a] = true
- centerT("activ", i, colors.black, colors[meItems[a].color], "right")
- else
- centerT("inactiv", i, colors.black, colors[meItems[a].color], "right")
- activ[a] = false
- end
- i = i + 1
- else --item is in ME System - check values ...
- if i%2==1 then tCol=colors.lightGray else tCol=colors.white end
- centerT(tostring(sItem.count),i, colors.black, tCol, "left")
- centerT(meItems[a].displayName, i, colors.black, tCol, "left2")
- if not activ[a] then
- if ((sItem.count < meItems[a].min) and (meItems[a].emit == "low")) or
- ((sItem.count > meItems[a].min) and (meItems[a].emit == "high")) then
- cols = cols+colors[meItems[a].color]
- centerT("activ", i, colors.black, colors[meItems[a].color], "right")
- activ[a] = true
- else
- centerT("inactiv", i, colors.black, colors[meItems[a].color], "right")
- end
- else
- if ((sItem.count >= meItems[a].max) and (meItems[a].emit == "low")) or
- ((sItem.count <= meItems[a].max) and (meItems[a].emit == "high")) then
- activ[a] = false
- centerT("inactiv", i, colors.black, colors[meItems[a].color], "right")
- else
- cols = cols+colors[meItems[a].color]
- centerT("activ", i, colors.black, colors[meItems[a].color], "right")
- end
- end
- i = i + 1
- end
- end
- end
- -- find Item in the ME System
- function getItem()
- sItem = "null"
- sItem = me.findItem(meItems[w].name .. "@" .. meItems[w].damage).getMetadata()
- end
- --just get the ingame time
- function getTime()
- local time = os.time()
- local formattedTime = textutils.formatTime(time, false)
- return formattedTime
- end
- --let the magic begin
- function main()
- print("Starting Emitter at: " .. getTime())
- print("check for Items ... CTRL+T to abort")
- clearMon()
- for v=1, #meItems do activ[v] = meItems[v].initEmit end
- while 1 do
- os.startTimer(1)
- local event = os.pullEventRaw()
- if event == "terminate" then
- cols = 0
- setCable()
- centerT("Stopped@ "..getTime() .. "cable set to " ..cols, 9, colors.red, colors.white, "head")
- print("Emitter stop at: " .. getTime())
- return
- else
- readFile()
- checkMe()
- setCable()
- --sleep(1)
- end
- end
- end
- initPeripherals() --init
- monitor.clear() --clear screen(s)
- main() -- do the magic
- --eof
Advertisement
Add Comment
Please, Sign In to add comment