Fix beduino command bugs
This commit is contained in:
parent
ff7e30a1c0
commit
6a71892799
@ -184,8 +184,7 @@ techage.register_node({"techage:chest_ta2", "techage:chest_ta3"}, {
|
|||||||
if topic == 131 then
|
if topic == 131 then
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local state = techage.get_inv_state(inv, "main")
|
return 0, {techage.get_inv_state_num(inv, "main")}
|
||||||
return 0, ({full = 2, loaded = 1, empty = 0})[state] or 0
|
|
||||||
else
|
else
|
||||||
return 2, ""
|
return 2, ""
|
||||||
end
|
end
|
||||||
@ -426,8 +425,7 @@ techage.register_node({"techage:chest_ta4"}, {
|
|||||||
if topic == 131 then
|
if topic == 131 then
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local state = techage.get_inv_state(inv, "main")
|
return 0, {techage.get_inv_state_num(inv, "main")}
|
||||||
return 0, ({full = 2, loaded = 1, empty = 0})[state] or 0
|
|
||||||
else
|
else
|
||||||
return 2, ""
|
return 2, ""
|
||||||
end
|
end
|
||||||
|
@ -92,6 +92,18 @@ local function inv_state(nvm)
|
|||||||
return "loaded"
|
return "loaded"
|
||||||
end
|
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)
|
local function max_stacksize(item_name)
|
||||||
-- It is sufficient to use minetest.registered_items as all registration
|
-- It is sufficient to use minetest.registered_items as all registration
|
||||||
-- functions (node, craftitems, tools) add the definitions there.
|
-- 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)}
|
return 0, {get_count(nvm, tonumber(payload[2] or 1) or 1)}
|
||||||
elseif topic == 140 and payload[1] == 2 then -- Inventory Item Name
|
elseif topic == 140 and payload[1] == 2 then -- Inventory Item Name
|
||||||
local nvm = techage.get_nvm(pos)
|
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
|
elseif topic == 131 then -- Chest State
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
return 0, {inv_state(nvm)}
|
return 0, {inv_state_num(nvm)}
|
||||||
else
|
else
|
||||||
return 2, ""
|
return 2, ""
|
||||||
end
|
end
|
||||||
|
@ -179,7 +179,7 @@ techage.register_node({"techage:ta5_hl_chest"}, {
|
|||||||
if topic == 131 then -- Chest State
|
if topic == 131 then -- Chest State
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
return 0, {techage.get_inv_state(inv, "main")}
|
return 0, {techage.get_inv_state_num(inv, "main")}
|
||||||
else
|
else
|
||||||
return 2, ""
|
return 2, ""
|
||||||
end
|
end
|
||||||
|
@ -593,6 +593,23 @@ function techage.get_inv_state(inv, listname)
|
|||||||
return state
|
return state
|
||||||
end
|
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", {
|
minetest.register_chatcommand("ta_send", {
|
||||||
description = minetest.formspec_escape(
|
description = minetest.formspec_escape(
|
||||||
"Send a techage command to the block with the number given: /ta_send <number> <command> [<data>]"),
|
"Send a techage command to the block with the number given: /ta_send <number> <command> [<data>]"),
|
||||||
|
@ -163,7 +163,7 @@ techage.register_node({"techage:chest_cart"}, {
|
|||||||
if topic == 131 then -- Chest State
|
if topic == 131 then -- Chest State
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
return 0, {techage.get_inv_state(inv, "main")}
|
return 0, {techage.get_inv_state_num(inv, "main")}
|
||||||
else
|
else
|
||||||
return 2, ""
|
return 2, ""
|
||||||
end
|
end
|
||||||
|
@ -212,7 +212,7 @@ techage.register_node({"techage:coalfirebox"}, {
|
|||||||
if topic == 128 then
|
if topic == 128 then
|
||||||
return 0, techage.get_node_lvm(pos).name
|
return 0, techage.get_node_lvm(pos).name
|
||||||
elseif topic == 129 then
|
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
|
elseif topic == 132 then
|
||||||
return 0, {techage.fuel.get_fuel_amount(nvm)}
|
return 0, {techage.fuel.get_fuel_amount(nvm)}
|
||||||
else
|
else
|
||||||
|
@ -137,7 +137,7 @@ techage.register_node({"techage:oilfirebox"}, {
|
|||||||
if topic == 128 then
|
if topic == 128 then
|
||||||
return 0, techage.get_node_lvm(pos).name
|
return 0, techage.get_node_lvm(pos).name
|
||||||
elseif topic == 129 then
|
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
|
elseif topic == 132 then
|
||||||
return 0, {fuel.get_fuel_amount(nvm)}
|
return 0, {fuel.get_fuel_amount(nvm)}
|
||||||
else
|
else
|
||||||
|
@ -374,9 +374,9 @@ techage.register_node({"techage:heatexchanger2"}, {
|
|||||||
return 0, techage.get_node_lvm(pos).name
|
return 0, techage.get_node_lvm(pos).name
|
||||||
elseif topic == 129 then -- State
|
elseif topic == 129 then -- State
|
||||||
if techage.is_running(nvm) then
|
if techage.is_running(nvm) then
|
||||||
return 0, {1}
|
return 0, {techage.RUNNING}
|
||||||
else
|
else
|
||||||
return 0, {0}
|
return 0, {techage.STOPPED}
|
||||||
end
|
end
|
||||||
elseif topic == 135 then -- Delivered Power
|
elseif topic == 135 then -- Delivered Power
|
||||||
local data = power.get_network_data(pos, Cable, DOWN)
|
local data = power.get_network_data(pos, Cable, DOWN)
|
||||||
|
@ -178,7 +178,7 @@ techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"},
|
|||||||
if topic == 128 then
|
if topic == 128 then
|
||||||
return 0, techage.get_node_lvm(pos).name
|
return 0, techage.get_node_lvm(pos).name
|
||||||
elseif topic == 129 then -- State
|
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
|
elseif topic == 132 then -- Fuel Level
|
||||||
return 0, {fuel.get_fuel_amount(nvm)}
|
return 0, {fuel.get_fuel_amount(nvm)}
|
||||||
else
|
else
|
||||||
|
@ -263,7 +263,7 @@ local tubing = {
|
|||||||
on_beduino_request_data = function(pos, src, topic, payload)
|
on_beduino_request_data = function(pos, src, topic, payload)
|
||||||
if topic == 141 then -- Furnace Output
|
if topic == 141 then -- Furnace Output
|
||||||
local nvm = techage.get_nvm(pos)
|
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
|
else
|
||||||
return CRD(pos).State:on_beduino_request_data(pos, topic, payload)
|
return CRD(pos).State:on_beduino_request_data(pos, topic, payload)
|
||||||
end
|
end
|
||||||
|
@ -352,9 +352,9 @@ techage.register_node({"techage:ta5_heatexchanger2"}, {
|
|||||||
return 0, techage.get_node_lvm(pos).name
|
return 0, techage.get_node_lvm(pos).name
|
||||||
elseif topic == 129 then -- State
|
elseif topic == 129 then -- State
|
||||||
if techage.is_running(nvm) then
|
if techage.is_running(nvm) then
|
||||||
return 0, {1}
|
return 0, {techage.RUNNING}
|
||||||
else
|
else
|
||||||
return 0, {0}
|
return 0, {techage.STOPPED}
|
||||||
end
|
end
|
||||||
elseif topic == 135 then -- Delivered Power
|
elseif topic == 135 then -- Delivered Power
|
||||||
local data = power.get_network_data(pos, Cable, DOWN)
|
local data = power.get_network_data(pos, Cable, DOWN)
|
||||||
|
@ -465,7 +465,7 @@ techage.register_node({"techage:ta4_icta_controller"}, {
|
|||||||
|
|
||||||
if topic == 129 then
|
if topic == 129 then
|
||||||
local state = meta:get_int("state") or 0
|
local state = meta:get_int("state") or 0
|
||||||
return 0, {techage.StateStrings[state] or "stopped"}
|
return 0, {state or techage.STOPPED}
|
||||||
else
|
else
|
||||||
return 2, ""
|
return 2, ""
|
||||||
end
|
end
|
||||||
|
@ -313,10 +313,10 @@ techage.register_node({"techage:ta3_silo", "techage:ta4_silo"}, {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
on_beduino_request_data = function(pos, src, topic, payload)
|
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 meta = M(pos)
|
||||||
local inv = meta:get_inventory()
|
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
|
elseif topic == 134 then
|
||||||
local inv = M(pos):get_inventory()
|
local inv = M(pos):get_inventory()
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
|
@ -153,7 +153,7 @@ techage.register_node({"techage:ta3_valve_closed", "techage:ta3_valve_open"}, {
|
|||||||
end,
|
end,
|
||||||
on_beduino_request_data = function(pos, src, topic, payload)
|
on_beduino_request_data = function(pos, src, topic, payload)
|
||||||
local node = techage.get_node_lvm(pos)
|
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
|
if node.name == "techage:ta3_valve_open" then
|
||||||
return 0, {1}
|
return 0, {1}
|
||||||
end
|
end
|
||||||
|
@ -326,7 +326,7 @@ techage.register_node({
|
|||||||
on_beduino_request_data = function(pos, src, topic, payload)
|
on_beduino_request_data = function(pos, src, topic, payload)
|
||||||
if topic == 144 then -- Player Name
|
if topic == 144 then -- Player Name
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
return 0, {nvm.player_name or ""}
|
return 0, nvm.player_name or ""
|
||||||
elseif topic == 142 then -- Binary State
|
elseif topic == 142 then -- Binary State
|
||||||
local node = techage.get_node_lvm(pos)
|
local node = techage.get_node_lvm(pos)
|
||||||
if node.name == "techage:ta3_playerdetector_on" or
|
if node.name == "techage:ta3_playerdetector_on" or
|
||||||
|
@ -670,9 +670,9 @@ techage.register_node({"techage:ta4_lua_controller"}, {
|
|||||||
on_beduino_request_data = function(pos, src, topic, payload)
|
on_beduino_request_data = function(pos, src, topic, payload)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
if topic == 129 then
|
if topic == 142 then
|
||||||
local running = meta:get_int("running") or STATE_STOPPED
|
local running = meta:get_int("running") or STATE_STOPPED
|
||||||
return 0, running
|
return 0, {running}
|
||||||
else
|
else
|
||||||
return 2, ""
|
return 2, ""
|
||||||
end
|
end
|
||||||
|
@ -247,7 +247,7 @@ techage.register_node({"techage:ta4_sensor_chest"}, {
|
|||||||
if topic == 131 then -- Chest State
|
if topic == 131 then -- Chest State
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
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)
|
elseif topic == 138 and payload[1] == 1 then -- Sensor Chests State (action)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local number = meta:get_string("node_number")
|
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)
|
elseif topic == 138 and payload[1] == 2 then -- Sensor Chests State (player name)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local number = meta:get_string("node_number")
|
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)
|
elseif topic == 138 and payload[1] == 3 then -- Sensor Chests State (stack item name)
|
||||||
local name, _ = get_stack(pos, payload[2] or 1)
|
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)
|
elseif topic == 138 and payload[1] == 4 then -- Sensor Chests State (stack item count)
|
||||||
local _, count = get_stack(pos, payload[2] or 1)
|
local _, count = get_stack(pos, payload[2] or 1)
|
||||||
return 0, {count}
|
return 0, {count}
|
||||||
|
@ -323,14 +323,14 @@ techage.register_node({"techage:ta4_wind_turbine"}, {
|
|||||||
if topic == 129 then
|
if topic == 129 then
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
if node.name == "ignore" then -- unloaded node?
|
if node.name == "ignore" then -- unloaded node?
|
||||||
return 0, {7} -- unloaded
|
return 0, {techage.UNLOADED}
|
||||||
end
|
end
|
||||||
if nvm.error then
|
if nvm.error then
|
||||||
return 0, {5} -- fault
|
return 0, {techage.FAULT}
|
||||||
elseif techage.is_running(nvm) then
|
elseif techage.is_running(nvm) then
|
||||||
return 0, {1} -- running
|
return 0, {techage.RUNNING}
|
||||||
else
|
else
|
||||||
return 0, {6} -- stopped
|
return 0, {techage.STOPPED}
|
||||||
end
|
end
|
||||||
elseif topic == 135 then -- Delivered Power
|
elseif topic == 135 then -- Delivered Power
|
||||||
return 0, {nvm.delivered or 0}
|
return 0, {nvm.delivered or 0}
|
||||||
|
Loading…
Reference in New Issue
Block a user