diff --git a/basic_machines/chest.lua b/basic_machines/chest.lua index 8894f8a..ed7b58d 100644 --- a/basic_machines/chest.lua +++ b/basic_machines/chest.lua @@ -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 diff --git a/basic_machines/ta4_chest.lua b/basic_machines/ta4_chest.lua index 53ec22c..fac0ee2 100644 --- a/basic_machines/ta4_chest.lua +++ b/basic_machines/ta4_chest.lua @@ -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 diff --git a/basic_machines/ta5_chest.lua b/basic_machines/ta5_chest.lua index 7cc26a0..d99b051 100644 --- a/basic_machines/ta5_chest.lua +++ b/basic_machines/ta5_chest.lua @@ -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 diff --git a/basis/command.lua b/basis/command.lua index bc7e332..5cb98e4 100644 --- a/basis/command.lua +++ b/basis/command.lua @@ -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 []"), diff --git a/carts/chest_cart.lua b/carts/chest_cart.lua index 343819f..ff6da7d 100644 --- a/carts/chest_cart.lua +++ b/carts/chest_cart.lua @@ -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 diff --git a/coal_power_station/firebox.lua b/coal_power_station/firebox.lua index 268fa93..1b732cd 100644 --- a/coal_power_station/firebox.lua +++ b/coal_power_station/firebox.lua @@ -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 diff --git a/coal_power_station/oilfirebox.lua b/coal_power_station/oilfirebox.lua index efcc942..b2cc309 100644 --- a/coal_power_station/oilfirebox.lua +++ b/coal_power_station/oilfirebox.lua @@ -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 diff --git a/energy_storage/heatexchanger2.lua b/energy_storage/heatexchanger2.lua index 2e513ea..dc4b1d3 100644 --- a/energy_storage/heatexchanger2.lua +++ b/energy_storage/heatexchanger2.lua @@ -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) diff --git a/furnace/firebox.lua b/furnace/firebox.lua index 755052b..e3678db 100644 --- a/furnace/firebox.lua +++ b/furnace/firebox.lua @@ -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 diff --git a/furnace/furnace_top.lua b/furnace/furnace_top.lua index 28bb441..b1c8aff 100644 --- a/furnace/furnace_top.lua +++ b/furnace/furnace_top.lua @@ -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 diff --git a/fusion_reactor/heatexchanger2.lua b/fusion_reactor/heatexchanger2.lua index 2190a2d..999efbb 100644 --- a/fusion_reactor/heatexchanger2.lua +++ b/fusion_reactor/heatexchanger2.lua @@ -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) diff --git a/icta_controller/controller.lua b/icta_controller/controller.lua index e1c2ae6..6c75af8 100644 --- a/icta_controller/controller.lua +++ b/icta_controller/controller.lua @@ -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 diff --git a/liquids/silo.lua b/liquids/silo.lua index 752f657..254b246 100644 --- a/liquids/silo.lua +++ b/liquids/silo.lua @@ -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) diff --git a/liquids/valve.lua b/liquids/valve.lua index 02c977b..bf59c35 100644 --- a/liquids/valve.lua +++ b/liquids/valve.lua @@ -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 diff --git a/logic/player_detector.lua b/logic/player_detector.lua index 7aeb828..f189185 100644 --- a/logic/player_detector.lua +++ b/logic/player_detector.lua @@ -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 diff --git a/lua_controller/controller.lua b/lua_controller/controller.lua index bdeab02..01c7b05 100644 --- a/lua_controller/controller.lua +++ b/lua_controller/controller.lua @@ -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 diff --git a/lua_controller/sensorchest.lua b/lua_controller/sensorchest.lua index 5344879..5ba2f1e 100644 --- a/lua_controller/sensorchest.lua +++ b/lua_controller/sensorchest.lua @@ -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} diff --git a/wind_turbine/rotor.lua b/wind_turbine/rotor.lua index a73e6b3..d84245a 100644 --- a/wind_turbine/rotor.lua +++ b/wind_turbine/rotor.lua @@ -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}