Add load command to the controller battery
This commit is contained in:
parent
eb1ed8890c
commit
ce9fddf6a7
@ -24,8 +24,9 @@ end
|
|||||||
|
|
||||||
local function on_timer(pos, elapsed)
|
local function on_timer(pos, elapsed)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
local number = meta:get_string("node_number")
|
||||||
local percent = calc_percent(meta:get_int("content"))
|
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
|
if percent == 0 then
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
node.name = "techage:ta4_battery_empty"
|
node.name = "techage:ta4_battery_empty"
|
||||||
@ -75,10 +76,16 @@ minetest.register_node("techage:ta4_battery", {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
M(pos):set_int("content", content)
|
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)
|
on_timer(pos, 1)
|
||||||
minetest.get_node_timer(pos):start(30)
|
minetest.get_node_timer(pos):start(30)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
|
techage.remove_node(pos, oldnode, oldmetadata)
|
||||||
|
end,
|
||||||
|
|
||||||
on_timer = on_timer,
|
on_timer = on_timer,
|
||||||
|
|
||||||
preserve_metadata = function(pos, oldnode, oldmetadata, drops)
|
preserve_metadata = function(pos, oldnode, oldmetadata, drops)
|
||||||
@ -154,9 +161,17 @@ else
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
techage.register_node({"techage:ta4_battery"},
|
techage.register_node({"techage:ta4_battery"}, {
|
||||||
{
|
|
||||||
on_node_load = function(pos)
|
on_node_load = function(pos)
|
||||||
minetest.get_node_timer(pos):start(30)
|
minetest.get_node_timer(pos):start(30)
|
||||||
end,
|
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,
|
||||||
})
|
})
|
||||||
|
@ -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 |
|
| "state" | one of: "empty", "loaded", "full" | State of a chest or Sensor Chest |
|
||||||
| "fuel" | number | fuel value of a fuel consuming block |
|
| "fuel" | number | fuel value of a fuel consuming block |
|
||||||
| "depth" | number | Read the current depth value of a quarry block (1..80) |
|
| "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 |
|
| "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 |
|
| "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 |
|
| "stacks" | Array with up to 4 Stores with the inventory content (see example) | only for Sensor Chests |
|
||||||
|
Binary file not shown.
@ -237,10 +237,10 @@ local function read_state(itemstack, user, pointed_thing)
|
|||||||
fuel = dump(fuel)
|
fuel = dump(fuel)
|
||||||
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": fuel = "..fuel.." ")
|
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": fuel = "..fuel.." ")
|
||||||
end
|
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
|
if load and load ~= "" and load ~= "unsupported" then
|
||||||
load = dump(load)
|
load, abs = dump(load), abs and dump(abs) or "--"
|
||||||
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": load = "..load.." % ")
|
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": load = "..load.." % / "..abs.." units ")
|
||||||
end
|
end
|
||||||
local delivered = techage.send_single("0", number, "delivered", nil)
|
local delivered = techage.send_single("0", number, "delivered", nil)
|
||||||
if delivered and delivered ~= "" and delivered ~= "unsupported" then
|
if delivered and delivered ~= "" and delivered ~= "unsupported" then
|
||||||
|
Loading…
Reference in New Issue
Block a user