mc_computer_progs/classic_tech/ar.lua
2021-11-14 17:43:36 +01:00

78 lines
2.2 KiB
Lua

local ar = peripheral.find "arController"
local pl_detector = peripheral.find "playerDetector"
local nrg_cell = peripheral.find "thermal:energy_cell"
local nrg_in = peripheral.wrap "energyDetector_0"
local nrg_out = peripheral.wrap "energyDetector_1"
if ar == nil or pl_detector == nil or nrg_cell == nil or nrg_in == nil or nrg_out == nil then
error "couldnt find all peripherals."
end
nrg_in.setTransferRateLimit(1000000)
nrg_out.setTransferRateLimit(1000000)
local cur_row = 0
local function draw_idx_string(string, x)
local x_or_default = 0
if x ~= nil then
x_or_default = x
end
return function()
ar.drawString(string, x_or_default, 10 * cur_row, 0xffffff)
cur_row = cur_row + 1
end
end
local function draw_idx_separator()
return function()
ar.horizontalLine(0, 200, 10 * cur_row, 0xffffff)
cur_row = cur_row + 1
end
end
local function draw_one_line_idx_icon(name)
return function()
ar.drawItemIcon(name, 0, 10 * cur_row)
cur_row = cur_row + 1
end
end
while true do
local draws = {
draw_one_line_idx_icon "minecraft:clock",
draw_idx_string(os.date(), 20),
draw_idx_separator(),
draw_one_line_idx_icon "minecraft:redstone_block",
draw_idx_string("Base Power:", 20),
draw_idx_string("Max: " .. nrg_cell.getEnergyCapacity()),
draw_idx_string("Current: " .. nrg_cell.getEnergy()),
draw_idx_string("%: " .. nrg_cell.getEnergy() / nrg_cell.getEnergyCapacity() * 100),
draw_idx_string("Production: " .. nrg_in.getTransferRate()),
draw_idx_string("Use: " .. nrg_out.getTransferRate()),
draw_idx_separator(),
draw_one_line_idx_icon "minecraft:player_head",
draw_idx_string("Players:", 20),
}
for _, p in pairs(pl_detector.getOnlinePlayers()) do
local pos = pl_detector.getPlayerPos(p)
if pos == nil then
table.insert(draws, draw_idx_string(p .. " @ ?"))
else
table.insert(draws, draw_idx_string(p .. " @ X: " .. pos.x .. " Y: " .. pos.y .. " Z: " .. pos.z))
end
end
cur_row = 0
ar.clear()
for _, l in ipairs(draws) do
l()
end
sleep(5)
end