Add load command to the controller battery

This commit is contained in:
Joachim Stolberg 2020-10-08 21:02:17 +02:00
parent eb1ed8890c
commit ce9fddf6a7
4 changed files with 25 additions and 10 deletions

View File

@ -24,8 +24,9 @@ end
local function on_timer(pos, elapsed)
local meta = minetest.get_meta(pos)
local number = meta:get_string("node_number")
local percent = calc_percent(meta:get_int("content"))
meta:set_string("infotext", S("Battery").." ("..percent.."%)")
meta:set_string("infotext", S("Battery").." "..number..": "..percent.." %")
if percent == 0 then
local node = minetest.get_node(pos)
node.name = "techage:ta4_battery_empty"
@ -75,10 +76,16 @@ minetest.register_node("techage:ta4_battery", {
end
end
M(pos):set_int("content", content)
local number = techage.add_node(pos, "techage:ta4_battery")
M(pos):set_string("node_number", number)
on_timer(pos, 1)
minetest.get_node_timer(pos):start(30)
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos, oldnode, oldmetadata)
end,
on_timer = on_timer,
preserve_metadata = function(pos, oldnode, oldmetadata, drops)
@ -154,9 +161,17 @@ else
})
end
techage.register_node({"techage:ta4_battery"},
{
techage.register_node({"techage:ta4_battery"}, {
on_node_load = function(pos)
minetest.get_node_timer(pos):start(30)
end,
on_recv_message = function(pos, src, topic, payload)
if topic == "load" then
local meta = minetest.get_meta(pos)
return calc_percent(meta:get_int("content"))
else
return "unsupported"
end
end,
})

View File

@ -358,7 +358,7 @@ In addition to Lua standard function the Lua Controller provides the following f
| "state" | one of: "empty", "loaded", "full" | State of a chest or Sensor Chest |
| "fuel" | number | fuel value of a fuel consuming block |
| "depth" | number | Read the current depth value of a quarry block (1..80) |
| "load" | number | Read the load value in percent (0..100) of a tank/storage block, a silo block, an accu block, or of the Signs Bot Box. Silo and tank return two values: The percentage value and the absolute value in units.<br /> Example: percent, absolute = $read_data("223", "load") |
| "load" | number | Read the load value in percent (0..100) of a tank, silo, accu, or battery block, or from the Signs Bot Box. Silo and tank return two values: The percentage value and the absolute value in units.<br /> Example: percent, absolute = $read_data("223", "load") |
| "delivered" | number | Read the current delivered power value of a generator block. A power consuming block (accu) provides a negative value |
| "action" | player-name, action-string | only for Sensor Chests |
| "stacks" | Array with up to 4 Stores with the inventory content (see example) | only for Sensor Chests |

Binary file not shown.

View File

@ -237,10 +237,10 @@ local function read_state(itemstack, user, pointed_thing)
fuel = dump(fuel)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": fuel = "..fuel.." ")
end
local load = techage.send_single("0", number, "load", nil)
local load, abs = techage.send_single("0", number, "load", nil)
if load and load ~= "" and load ~= "unsupported" then
load = dump(load)
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": load = "..load.." % ")
load, abs = dump(load), abs and dump(abs) or "--"
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": load = "..load.." % / "..abs.." units ")
end
local delivered = techage.send_single("0", number, "delivered", nil)
if delivered and delivered ~= "" and delivered ~= "unsupported" then