Fix beduino command bugs

master
Joachim Stolberg 2022-06-09 12:59:17 +02:00
parent ff7e30a1c0
commit 6a71892799
18 changed files with 57 additions and 30 deletions

View File

@ -184,8 +184,7 @@ techage.register_node({"techage:chest_ta2", "techage:chest_ta3"}, {
if topic == 131 then
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local state = techage.get_inv_state(inv, "main")
return 0, ({full = 2, loaded = 1, empty = 0})[state] or 0
return 0, {techage.get_inv_state_num(inv, "main")}
else
return 2, ""
end
@ -426,8 +425,7 @@ techage.register_node({"techage:chest_ta4"}, {
if topic == 131 then
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local state = techage.get_inv_state(inv, "main")
return 0, ({full = 2, loaded = 1, empty = 0})[state] or 0
return 0, {techage.get_inv_state_num(inv, "main")}
else
return 2, ""
end

View File

@ -92,6 +92,18 @@ local function inv_state(nvm)
return "loaded"
end
local function inv_state_num(nvm)
local num = 0
for _,item in ipairs(nvm.inventory or {}) do
if item.count and item.count > 0 then
num = num + 1
end
end
if num == 0 then return 0 end
if num == 8 then return 2 end
return 1
end
local function max_stacksize(item_name)
-- It is sufficient to use minetest.registered_items as all registration
-- functions (node, craftitems, tools) add the definitions there.
@ -614,10 +626,10 @@ techage.register_node({"techage:ta4_chest"}, {
return 0, {get_count(nvm, tonumber(payload[2] or 1) or 1)}
elseif topic == 140 and payload[1] == 2 then -- Inventory Item Name
local nvm = techage.get_nvm(pos)
return 0, {get_itemstring(nvm, tonumber(payload[2] or 1) or 1)}
return 0, get_itemstring(nvm, tonumber(payload[2] or 1) or 1)
elseif topic == 131 then -- Chest State
local nvm = techage.get_nvm(pos)
return 0, {inv_state(nvm)}
return 0, {inv_state_num(nvm)}
else
return 2, ""
end

View File

@ -179,7 +179,7 @@ techage.register_node({"techage:ta5_hl_chest"}, {
if topic == 131 then -- Chest State
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return 0, {techage.get_inv_state(inv, "main")}
return 0, {techage.get_inv_state_num(inv, "main")}
else
return 2, ""
end

View File

@ -593,6 +593,23 @@ function techage.get_inv_state(inv, listname)
return state
end
-- Beduino variant
function techage.get_inv_state_num(inv, listname)
local state
if inv:is_empty(listname) then
state = 0
else
local list = inv:get_list(listname)
state = 2
for _, item in ipairs(list) do
if item:is_empty() then
return 1
end
end
end
return state
end
minetest.register_chatcommand("ta_send", {
description = minetest.formspec_escape(
"Send a techage command to the block with the number given: /ta_send <number> <command> [<data>]"),

View File

@ -163,7 +163,7 @@ techage.register_node({"techage:chest_cart"}, {
if topic == 131 then -- Chest State
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return 0, {techage.get_inv_state(inv, "main")}
return 0, {techage.get_inv_state_num(inv, "main")}
else
return 2, ""
end

View File

@ -212,7 +212,7 @@ techage.register_node({"techage:coalfirebox"}, {
if topic == 128 then
return 0, techage.get_node_lvm(pos).name
elseif topic == 129 then
return 0, {nvm.running and "running" or "stopped"}
return 0, {nvm.running and techage.RUNNING or techage.STOPPED}
elseif topic == 132 then
return 0, {techage.fuel.get_fuel_amount(nvm)}
else

View File

@ -137,7 +137,7 @@ techage.register_node({"techage:oilfirebox"}, {
if topic == 128 then
return 0, techage.get_node_lvm(pos).name
elseif topic == 129 then
return 0, {nvm.running and "running" or "stopped"}
return 0, {nvm.running and techage.RUNNING or techage.STOPPED}
elseif topic == 132 then
return 0, {fuel.get_fuel_amount(nvm)}
else

View File

@ -374,9 +374,9 @@ techage.register_node({"techage:heatexchanger2"}, {
return 0, techage.get_node_lvm(pos).name
elseif topic == 129 then -- State
if techage.is_running(nvm) then
return 0, {1}
return 0, {techage.RUNNING}
else
return 0, {0}
return 0, {techage.STOPPED}
end
elseif topic == 135 then -- Delivered Power
local data = power.get_network_data(pos, Cable, DOWN)

View File

@ -178,7 +178,7 @@ techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"},
if topic == 128 then
return 0, techage.get_node_lvm(pos).name
elseif topic == 129 then -- State
return 0, {nvm.running and "running" or "stopped"}
return 0, {nvm.running and techage.RUNNING or techage.STOPPED}
elseif topic == 132 then -- Fuel Level
return 0, {fuel.get_fuel_amount(nvm)}
else

View File

@ -263,7 +263,7 @@ local tubing = {
on_beduino_request_data = function(pos, src, topic, payload)
if topic == 141 then -- Furnace Output
local nvm = techage.get_nvm(pos)
return 0, {string.split(nvm.output or "unknown", " ")[1]}
return 0, string.split(nvm.output or "unknown", " ")[1]
else
return CRD(pos).State:on_beduino_request_data(pos, topic, payload)
end

View File

@ -352,9 +352,9 @@ techage.register_node({"techage:ta5_heatexchanger2"}, {
return 0, techage.get_node_lvm(pos).name
elseif topic == 129 then -- State
if techage.is_running(nvm) then
return 0, {1}
return 0, {techage.RUNNING}
else
return 0, {0}
return 0, {techage.STOPPED}
end
elseif topic == 135 then -- Delivered Power
local data = power.get_network_data(pos, Cable, DOWN)

View File

@ -465,7 +465,7 @@ techage.register_node({"techage:ta4_icta_controller"}, {
if topic == 129 then
local state = meta:get_int("state") or 0
return 0, {techage.StateStrings[state] or "stopped"}
return 0, {state or techage.STOPPED}
else
return 2, ""
end

View File

@ -313,10 +313,10 @@ techage.register_node({"techage:ta3_silo", "techage:ta4_silo"}, {
end
end,
on_beduino_request_data = function(pos, src, topic, payload)
if topic == 129 then -- State
if topic == 131 then -- Chest State
local meta = M(pos)
local inv = meta:get_inventory()
return 0, {techage.get_inv_state(inv, "main")}
return 0, {techage.get_inv_state_num(inv, "main")}
elseif topic == 134 then
local inv = M(pos):get_inventory()
local nvm = techage.get_nvm(pos)

View File

@ -153,7 +153,7 @@ techage.register_node({"techage:ta3_valve_closed", "techage:ta3_valve_open"}, {
end,
on_beduino_request_data = function(pos, src, topic, payload)
local node = techage.get_node_lvm(pos)
if topic == 129 then -- State
if topic == 142 then -- State
if node.name == "techage:ta3_valve_open" then
return 0, {1}
end

View File

@ -326,7 +326,7 @@ techage.register_node({
on_beduino_request_data = function(pos, src, topic, payload)
if topic == 144 then -- Player Name
local nvm = techage.get_nvm(pos)
return 0, {nvm.player_name or ""}
return 0, nvm.player_name or ""
elseif topic == 142 then -- Binary State
local node = techage.get_node_lvm(pos)
if node.name == "techage:ta3_playerdetector_on" or

View File

@ -670,9 +670,9 @@ techage.register_node({"techage:ta4_lua_controller"}, {
on_beduino_request_data = function(pos, src, topic, payload)
local meta = minetest.get_meta(pos)
if topic == 129 then
if topic == 142 then
local running = meta:get_int("running") or STATE_STOPPED
return 0, running
return 0, {running}
else
return 2, ""
end

View File

@ -247,7 +247,7 @@ techage.register_node({"techage:ta4_sensor_chest"}, {
if topic == 131 then -- Chest State
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return 0, {techage.get_inv_state(inv, "main")}
return 0, {techage.get_inv_state_num(inv, "main")}
elseif topic == 138 and payload[1] == 1 then -- Sensor Chests State (action)
local meta = minetest.get_meta(pos)
local number = meta:get_string("node_number")
@ -256,10 +256,10 @@ techage.register_node({"techage:ta4_sensor_chest"}, {
elseif topic == 138 and payload[1] == 2 then -- Sensor Chests State (player name)
local meta = minetest.get_meta(pos)
local number = meta:get_string("node_number")
return 0, {(PlayerActions[number] or {})[1]}
return 0, (PlayerActions[number] or {})[1]
elseif topic == 138 and payload[1] == 3 then -- Sensor Chests State (stack item name)
local name, _ = get_stack(pos, payload[2] or 1)
return 0, {name}
return 0, name
elseif topic == 138 and payload[1] == 4 then -- Sensor Chests State (stack item count)
local _, count = get_stack(pos, payload[2] or 1)
return 0, {count}

View File

@ -323,14 +323,14 @@ techage.register_node({"techage:ta4_wind_turbine"}, {
if topic == 129 then
local node = minetest.get_node(pos)
if node.name == "ignore" then -- unloaded node?
return 0, {7} -- unloaded
return 0, {techage.UNLOADED}
end
if nvm.error then
return 0, {5} -- fault
return 0, {techage.FAULT}
elseif techage.is_running(nvm) then
return 0, {1} -- running
return 0, {techage.RUNNING}
else
return 0, {6} -- stopped
return 0, {techage.STOPPED}
end
elseif topic == 135 then -- Delivered Power
return 0, {nvm.delivered or 0}