Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- Find any connected redstone energy cells.
- -- @return the number of newly found energy cells
- --
- function updateConnectedRedstoneEnergyCells(cells)
- local count = 0
- local found = {}
- for _, name in pairs(peripheral.getNames()) do
- if peripheral.getType(name) == "redstone_energy_cell" then
- local handle = peripheral.wrap(name)
- found[name] = true
- if cells[name] == nil then
- cells[name] = handle
- count = count + 1
- end
- end
- end
- -- remove cells that have been removed from the system
- for name, _ in pairs(cells) do
- if found[name] == nil then
- cells[name] = nil
- end
- end
- return count
- end
- --- Get the number of connected redstone energy cells
- --
- function numConnectedRedstoneEnergyCells(cells)
- local count = 0
- for _, cell in pairs(cells) do
- count = count + 1
- end
- return count
- end
- --- Get the total amount of energy stored in the system
- -- @return int the amount of energy stored
- function getEnergyStored(cells)
- local energy = 0
- for _, cell in pairs(cells) do
- energy = energy + cell.getEnergyStored()
- end
- return energy
- end
- --- Get the max amount of energy that can be stored in the system
- -- @return int the max amount of energy stored
- function getMaxEnergyStored(cells)
- local energy = 0
- for _, cell in pairs(cells) do
- energy = energy + cell.getMaxEnergyStored()
- end
- return energy
- end
- --- Get the percentage of energy stored in the system as a float ( 0 <= x <= 100 )
- -- @return float the percentage of energy stored in the system ( 0 <= x <= 100 )
- function getPercentEnergyStored(cells)
- local energy = getEnergyStored(cells)
- local maxEnergy = getMaxEnergyStored(cells)
- if energy == 0 then
- return 0
- end
- return round((energy / maxEnergy) * 100, 2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement