Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- display_tanks_wired_v3 v3.0 for OpenPeripheral 0.4.1
- Copyright (C) 2016 Duisburger98
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- --]]
- -- The text scale of your monitor (between 0.5 and 5)
- monitor_scale = 1
- -- Whether to show or not the percentage in numberic form above the graphs
- -- Note: This will only work if there is enough horizontal space to write the numbers
- -- So if the graphs width is less than 4 characters you won't see the numbers
- -- even if you set this to true
- show_percentage = true
- -- Monitor refresh frequency (in seconds)
- sleep_timeout = 0.5
- -- The colors you want to see your liquids in
- -- You can add more liquids, or change the colors here
- tank_colors={
- {name="Lava", color=colors.red},
- {name="Water", color=colors.blue},
- {name="Biofuel", color=colors.orange},
- {name="item.mobessenceitem", color=colors.green},
- {name="Creosote Oil", color=colors.brown},
- {name="Fuel", color=colors.yellow},
- {name="Oil", color=colors.gray},
- {name="Biomass", color=colors.green},
- {name="Sludge", color=colors.blue},
- {name="Sewage", color=colors.brown},
- {name="Liquid DNA", color=colors.pink},
- {name="Honey", color=colors.yellow},
- {name="Fruit Juice", color=colors.lime},
- {name="Milk", color=colors.white},
- {name="Seed Oil", color=colors.yellow},
- {name="Ethanol", color=colors.orange},
- {name="Pink Slime", color=colors.pink},
- {name="Molten Iron", color=colors.red},
- {name="Molten Gold", color=colors.yellow},
- {name="Molten Ardite", color=colors.brown},
- {name="Molten Copper", color=colors.orange},
- {name="Molten Bronze", color=colors.brown},
- {name="Molten Aluminum Brass", color=colors.yellow},
- {name="Molten Manyullyn", color=colors.purple},
- {name="Molten Alumite", color=colors.pink},
- {name="Molten Aluminum", color=colors.pink},
- {name="Molten Obsidian", color=colors.purple},
- {name="Molten Cobalt", color=colors.blue},
- {name="Molten Steel", color=colors.lightGray},
- {name="Molten Glass", color=colors.lightBlue},
- {name="Seared Stone", color=colors.gray},
- {name="Liquified Emerald", color=colors.lime},
- {name="Blood", color=colors.red},
- {name="Molten Nickel", color=colors.yellow},
- {name="Molten Lead", color=colors.purple},
- {name="Molten Silver", color=colors.cyan},
- {name="fluid.platinum.molten", color=colors.cyan},
- {name="Molten Invar", color=colors.lightGray},
- {name="Molten Electrum", color=colors.yellow},
- {name="Resonant Ender", color=colors.green},
- {name="Liquid Blueslime", color=colors.lightBlue},
- {name="Pig Iron", color=colors.pink},
- {name="Liquid XP", color=colors.lime},
- {name="Destabilized Redstone", color=colors.red},
- {name="Energized Glowstone", color=colors.yellow},
- {name="Blazing Pyrotheum", color=colors.orange},
- {name="Gelid Cryotheum", color=colors.cyan},
- {name="coal", color=colors.gray},
- }
- -----------------------------------------
- -- DO NOT MODIFY ANYTHING FROM HERE ON --
- -----------------------------------------
- function tableLength(T)
- local count = 0
- for _ in pairs(T) do
- count = count + 1
- end
- return count
- end
- function getColor(data)
- for _, v in pairs(tank_colors) do
- if (v.name == data.name) or
- (v.name == data.rawName) then
- return v.color
- end
- end
- return colors.white
- end
- function drawGraph()
- local graph_width=0
- local tanks_num = tableLength(unique_tank_hash)
- local percentage_line = 0
- if tanks_num == 0 then
- return
- end
- while graph_width <= 0 do
- graph_width = math.floor((width-tanks_num+1) / tanks_num)
- tanks_num = tanks_num - 1
- end
- tanks_num = tanks_num + 1
- if (show_percentage) and
- (graph_width > 4) then
- percentage_line = 1
- end
- local count=0
- for k, v in pairs(unique_tank_hash) do
- local x = (count * graph_width) + 1 + count
- local x_end = x + graph_width -1
- if v.amount == nil then
- v.amount = 0
- end
- if v.capacity == nil then
- v.capacity = 1
- end
- percent = v.amount / v.capacity
- percentage = (height-percentage_line) * percent
- y = (height-percentage_line) - math.floor(percentage + 0.5) + percentage_line
- if percentage_line == 1 then
- local round_percent = math.floor((percent*100) + 0.5)
- local text = round_percent.."%"
- local x_pos = x + math.floor((graph_width-string.len(text))/2)
- monitor.setCursorPos(x_pos,1)
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- monitor.write(text)
- end
- for i=1+percentage_line,height do
- for j=x,x_end do
- local c = colors.black
- if i > y then
- c = getColor(v)
- end
- monitor.setBackgroundColor(c)
- monitor.setCursorPos(j, i)
- monitor.write(" ")
- end
- end
- count = count + 1
- if count >= tanks_num then
- return
- end
- end
- end
- function getTanks()
- tanks={}
- for i, name in ipairs(peripheral.getNames()) do
- local methods = peripheral.getMethods(name)
- if methods then
- for k, v in pairs(methods) do
- if v == "getTankInfo" then
- local p = peripheral.wrap(name)
- local info = p.getTankInfo("unknown")
- for m,n in ipairs(info) do
- local data={position=name, data=n}
- table.insert(tanks, data)
- end
- end
- end
- end
- end
- return tanks
- end
- while true do
- tank_data = getTanks()
- unique_tank_hash = {}
- for i, v in ipairs(tank_data) do
- tank=v.data
- tank_position=v.position
- local hash={tank_position, i}
- unique_tank_hash[textutils.serialize(hash)] = tank
- end
- monitor = peripheral.find("monitor")
- if monitor then
- monitor.setTextScale(monitor_scale)
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- width, height = monitor.getSize()
- drawGraph()
- end
- sleep(sleep_timeout)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement