SHOW:
|
|
- or go back to the newest paste.
| 1 | --[[ | |
| 2 | Simple Energy storage display for redstone energy cells | |
| 3 | and on-demand engine control | |
| 4 | The engine control part is optional, don't connect a rednet | |
| 5 | cable if you only want to display energy storage. | |
| 6 | ||
| 7 | by got_m1lk | |
| 8 | --]] | |
| 9 | ||
| 10 | --Specify side of wired modem | |
| 11 | -- Valid: "left", "right", "front", "back", "top", "bottom" | |
| 12 | local modemside = "left" | |
| 13 | ||
| 14 | --Specify side of rednet cable | |
| 15 | - | local rednetside = "bottom" |
| 15 | + | local rednetside = "back" |
| 16 | ||
| 17 | --Specify side of monitor | |
| 18 | --If the monitor is attached to the modem specify peripheral-ID instead. | |
| 19 | local monitorside = "top" | |
| 20 | ||
| 21 | --Adjust the textscale if you have a bigger/smaller monitor | |
| 22 | --Increments of 0.5 | |
| 23 | local textsize = 1 | |
| 24 | ||
| 25 | --Specify at what percentage the engines turn on | |
| 26 | local min = 25 | |
| 27 | ||
| 28 | --Specify at what percentage the engines turn off | |
| 29 | local max = 95 | |
| 30 | ||
| 31 | --Specify the peripheral-IDs of you redstone cells | |
| 32 | --Remove/add units from the table to fit it to the amount | |
| 33 | -- of cells you are using | |
| 34 | local storageUnits = {
| |
| 35 | {
| |
| 36 | - | ["id"] = "redstone_energy_cell_0", |
| 36 | + | ["id"] = "cofh_thermalexpansion_energycell_0", |
| 37 | ["name"] = "Cell1" | |
| 38 | }, | |
| 39 | {
| |
| 40 | - | ["id"] = "redstone_energy_cell_1", |
| 40 | + | ["id"] = "cofh_thermalexpansion_energycell_1", |
| 41 | ["name"] = "Cell2" | |
| 42 | } | |
| 43 | ||
| 44 | - | ["id"] = "redstone_energy_cell_2", |
| 44 | + | |
| 45 | - | ["name"] = "Cell3" |
| 45 | + | |
| 46 | ||
| 47 | local mon = peripheral.wrap(monitorside) | |
| 48 | - | ["id"] = "redstone_energy_cell_3", |
| 48 | + | |
| 49 | - | ["name"] = "Cell4" |
| 49 | + | |
| 50 | - | } |
| 50 | + | |
| 51 | mon.clear() | |
| 52 | mon.setTextScale(textsize) | |
| 53 | mon.setTextColor(512) | |
| 54 | mon.setCursorPos(1,2) | |
| 55 | mon.write(" Energy Remaining:")
| |
| 56 | mon.setCursorPos(1,10) | |
| 57 | mon.write(" Engine Status:")
| |
| 58 | mon.setTextColor(2) | |
| 59 | rs.setBundledOutput(rednetside,colors.black) | |
| 60 | ||
| 61 | while true do | |
| 62 | ||
| 63 | capacity = 0 | |
| 64 | amount = 0 | |
| 65 | ||
| 66 | for i=#storageUnits,1,-1 do | |
| 67 | storageUnit = storageUnits[i] | |
| 68 | capacity = capacity + net.callRemote(storageUnit["id"], "getMaxEnergyStored") | |
| 69 | amount = amount + net.callRemote(storageUnit["id"], "getEnergyStored") | |
| 70 | end | |
| 71 | ||
| 72 | ||
| 73 | percentage = tonumber((amount / capacity) *100) | |
| 74 | percentage = math.floor(percentage) | |
| 75 | ||
| 76 | ||
| 77 | if percentage <= min then | |
| 78 | rs.setBundledOutput(rednetside,colors.white) | |
| 79 | end | |
| 80 | ||
| 81 | if percentage >= max then | |
| 82 | rs.setBundledOutput(rednetside,colors.black) | |
| 83 | end | |
| 84 | ||
| 85 | ||
| 86 | percentage = string.match(tostring(percentage),'[^%.]+') | |
| 87 | mon.setCursorPos(8,4) | |
| 88 | mon.clearLine() | |
| 89 | mon.setTextColor(2) | |
| 90 | mon.write(percentage .. "%") | |
| 91 | mon.setCursorPos(1,6) | |
| 92 | mon.clearLine() | |
| 93 | mon.setTextColor(512) | |
| 94 | mon.write("Energy: ")
| |
| 95 | mon.setTextColor(2) | |
| 96 | mon.write(string.match(tostring(amount),'[^%.]+') .. " MJ") | |
| 97 | mon.setCursorPos(1,7) | |
| 98 | mon.clearLine() | |
| 99 | mon.setTextColor(512) | |
| 100 | mon.write(" Size: ")
| |
| 101 | mon.setTextColor(2) | |
| 102 | mon.write(string.match(tostring(capacity),'[^%.]+') .." MJ") | |
| 103 | ||
| 104 | if rs.getBundledInput(rednetside) == colors.black then | |
| 105 | mon.setTextColor(colors.red) | |
| 106 | mon.setCursorPos(8,11) | |
| 107 | mon.write("OFF")
| |
| 108 | elseif rs.getBundledInput(rednetside) == colors.white then | |
| 109 | mon.setTextColor(colors.lime) | |
| 110 | mon.setCursorPos(8,11) | |
| 111 | mon.write(" ON")
| |
| 112 | end | |
| 113 | ||
| 114 | ||
| 115 | sleep(1) | |
| 116 | end |