From 2905a45774137a0fa1c991533e268addeefabcf1 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Thu, 27 Feb 2020 22:33:42 +0100 Subject: [PATCH] removed unneeded code --- basic_machines/chest.lua | 51 ++++--------------------------- basic_machines/distributor.lua | 10 ++---- basic_machines/electronic_fab.lua | 10 +----- basic_machines/gravelrinser.lua | 12 ++------ basic_machines/gravelsieve.lua | 10 +----- basic_machines/grinder.lua | 10 +----- basic_machines/liquidsampler.lua | 3 -- basic_machines/pusher.lua | 10 +----- basic_machines/quarry.lua | 8 +---- basis/fuel_lib.lua | 7 +++++ basis/liquid_lib.lua | 7 +++++ basis/node_states.lua | 16 +++------- chemistry/ta4_doser.lua | 10 +----- coal_power_station/firebox.lua | 24 ++------------- coal_power_station/generator.lua | 12 ++++---- coal_power_station/oilfirebox.lua | 20 ++---------- coal_power_station/turbine.lua | 1 - energy_storage/generator.lua | 12 ++++---- energy_storage/heatexchanger1.lua | 25 +++++++++++++-- furnace/firebox.lua | 20 ++---------- furnace/furnace_top.lua | 10 +----- tools/repairkit.lua | 10 ------ 22 files changed, 75 insertions(+), 223 deletions(-) diff --git a/basic_machines/chest.lua b/basic_machines/chest.lua index e6ef1b5..4c0e867 100644 --- a/basic_machines/chest.lua +++ b/basic_machines/chest.lua @@ -16,44 +16,10 @@ local M = minetest.get_meta local S = techage.S -local PlayerActions = {} -local InventoryState = {} - - -local function store_action(pos, player, action, stack) - local meta = minetest.get_meta(pos) - local name = player and player:get_player_name() or "" - local number = meta:get_string("node_number") - local item = stack:get_name().." "..stack:get_count() - PlayerActions[number] = {name, action, item} -end - -local function send_off_command(pos) - local meta = minetest.get_meta(pos) - local numbers = meta:get_string("numbers") or "" - if numbers ~= "" then - local own_num = meta:get_string("node_number") - techage.send_multi(own_num, numbers, "off") - end -end - - -local function send_command(pos) - local meta = minetest.get_meta(pos) - local numbers = meta:get_string("numbers") or "" - if numbers ~= "" then - local own_num = meta:get_string("node_number") - techage.send_multi(own_num, numbers, "on") - minetest.after(1, send_off_command, pos) - end -end - local function allow_metadata_inventory_put(pos, listname, index, stack, player) if minetest.is_protected(pos, player:get_player_name()) then return 0 end - store_action(pos, player, "put", stack) - send_command(pos) return stack:get_count() end @@ -61,8 +27,6 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player if minetest.is_protected(pos, player:get_player_name()) then return 0 end - store_action(pos, player, "take", stack) - send_command(pos) return stack:get_count() end @@ -109,11 +73,8 @@ minetest.register_node("techage:chest_ta2", { after_place_node = function(pos, placer) local meta = minetest.get_meta(pos) - local number = techage.add_node(pos, "techage:chest_ta2") - meta:set_string("node_number", number) meta:set_string("owner", placer:get_player_name()) meta:set_string("formspec", formspec2()) - meta:set_string("infotext", S("TA2 Protected Chest").." "..number) end, techage_set_numbers = function(pos, numbers, player_name) @@ -259,17 +220,12 @@ techage.register_node({"techage:chest_ta2", "techage:chest_ta3", "techage:chest_ local meta = minetest.get_meta(pos) local inv = meta:get_inventory() return techage.get_inv_state(inv, "main") - elseif topic == "player_action" then - local meta = minetest.get_meta(pos) - local number = meta:get_string("node_number") - return PlayerActions[number] else return "unsupported" end end, }) - minetest.register_craft({ type = "shapeless", output = "techage:chest_ta2", @@ -279,6 +235,11 @@ minetest.register_craft({ minetest.register_craft({ type = "shapeless", output = "techage:chest_ta3", - recipe = {"techage:chest_ta2", "techage:tubeS", "techage:vacuum_tube"} + recipe = {"techage:chest_ta2", "default:chest"} }) +minetest.register_craft({ + type = "shapeless", + output = "techage:chest_ta4", + recipe = {"techage:chest_ta3", "default:chest"} +}) diff --git a/basic_machines/distributor.lua b/basic_machines/distributor.lua index 59a71bc..70b58f6 100644 --- a/basic_machines/distributor.lua +++ b/basic_machines/distributor.lua @@ -26,8 +26,7 @@ local COUNTDOWN_TICKS = 10 local STANDBY_TICKS = 10 local CYCLE_TIME = 4 -local INFO = [[- Turn port on/off: command = "port", payload = "red/green/blue/yellow=on/off" -- Clear counter: command = "clear_counter"]] +local INFO = [[Turn port on/off: command = 'port', payload = red/green/blue/yellow=on/off]] --local Side2Color = {B="red", L="green", F="blue", R="yellow"} @@ -441,12 +440,7 @@ local tubing = { local slot, val = techage.ident_value(payload) return change_filter_settings(pos, slot, val) else - local resp = CRD(pos).State:on_receive_message(pos, topic, payload) - if resp then - return resp - else - return "unsupported" - end + return CRD(pos).State:on_receive_message(pos, topic, payload) end end, diff --git a/basic_machines/electronic_fab.lua b/basic_machines/electronic_fab.lua index be16aa4..e080057 100644 --- a/basic_machines/electronic_fab.lua +++ b/basic_machines/electronic_fab.lua @@ -193,15 +193,7 @@ local tubing = { end end, on_recv_message = function(pos, src, topic, payload) - local resp = CRD(pos).State:on_receive_message(pos, topic, payload) - if resp then - return resp - else - return "unsupported" - end - end, - on_node_load = function(pos) - CRD(pos).State:on_node_load(pos) + return CRD(pos).State:on_receive_message(pos, topic, payload) end, } diff --git a/basic_machines/gravelrinser.lua b/basic_machines/gravelrinser.lua index f052fa7..9cef7e2 100644 --- a/basic_machines/gravelrinser.lua +++ b/basic_machines/gravelrinser.lua @@ -238,15 +238,7 @@ local tubing = { end end, on_recv_message = function(pos, src, topic, payload) - local resp = CRD(pos).State:on_receive_message(pos, topic, payload) - if resp then - return resp - else - return "unsupported" - end - end, - on_node_load = function(pos) - CRD(pos).State:on_node_load(pos) + return CRD(pos).State:on_receive_message(pos, topic, payload) end, } @@ -290,7 +282,7 @@ local node_name_ta2, node_name_ta3, node_name_ta4 = num_items = {0,1,1,1}, power_consumption = {0,3,3,3}, }, - {false, true, true, false}) -- TA2/A3 + {false, true, true, false}) -- TA2/TA3 minetest.register_craft({ output = node_name_ta2, diff --git a/basic_machines/gravelsieve.lua b/basic_machines/gravelsieve.lua index 46cc1b3..4e78619 100644 --- a/basic_machines/gravelsieve.lua +++ b/basic_machines/gravelsieve.lua @@ -171,15 +171,7 @@ local tubing = { end end, on_recv_message = function(pos, src, topic, payload) - local resp = CRD(pos).State:on_receive_message(pos, topic, payload) - if resp then - return resp - else - return "unsupported" - end - end, - on_node_load = function(pos) - CRD(pos).State:on_node_load(pos) + return CRD(pos).State:on_receive_message(pos, topic, payload) end, } diff --git a/basic_machines/grinder.lua b/basic_machines/grinder.lua index 4ad5121..9a76776 100644 --- a/basic_machines/grinder.lua +++ b/basic_machines/grinder.lua @@ -184,15 +184,7 @@ local tubing = { end end, on_recv_message = function(pos, src, topic, payload) - local resp = CRD(pos).State:on_receive_message(pos, topic, payload) - if resp then - return resp - else - return "unsupported" - end - end, - on_node_load = function(pos) - CRD(pos).State:on_node_load(pos) + return CRD(pos).State:on_receive_message(pos, topic, payload) end, } diff --git a/basic_machines/liquidsampler.lua b/basic_machines/liquidsampler.lua index 6913440..a16a269 100644 --- a/basic_machines/liquidsampler.lua +++ b/basic_machines/liquidsampler.lua @@ -173,9 +173,6 @@ local tubing = { on_recv_message = function(pos, src, topic, payload) return CRD(pos).State:on_receive_message(pos, topic, payload) end, - on_node_load = function(pos) - CRD(pos).State:on_node_load(pos) - end, } local node_name_ta2, node_name_ta3, _ = diff --git a/basic_machines/pusher.lua b/basic_machines/pusher.lua index 73057df..abbae68 100644 --- a/basic_machines/pusher.lua +++ b/basic_machines/pusher.lua @@ -115,15 +115,7 @@ local tubing = { is_pusher = true, -- is a pulling/pushing node on_recv_message = function(pos, src, topic, payload) - local resp = CRD(pos).State:on_receive_message(pos, topic, payload) - if resp then - return resp - else - return "unsupported" - end - end, - on_node_load = function(pos) - CRD(pos).State:on_node_load(pos) + return CRD(pos).State:on_receive_message(pos, topic, payload) end, } diff --git a/basic_machines/quarry.lua b/basic_machines/quarry.lua index 5097561..d7bc2c4 100644 --- a/basic_machines/quarry.lua +++ b/basic_machines/quarry.lua @@ -343,15 +343,9 @@ local tubing = { end end, on_recv_message = function(pos, src, topic, payload) - local resp = CRD(pos).State:on_receive_message(pos, topic, payload) - if resp then - return resp - else - return "unsupported" - end + return CRD(pos).State:on_receive_message(pos, topic, payload) end, on_node_load = function(pos, node) - CRD(pos).State:on_node_load(pos) local nvm = techage.get_nvm(pos) if nvm.techage_state == techage.RUNNING then play_sound(pos) diff --git a/basis/fuel_lib.lua b/basis/fuel_lib.lua index bd26a90..023e327 100644 --- a/basis/fuel_lib.lua +++ b/basis/fuel_lib.lua @@ -144,4 +144,11 @@ function techage.fuel.has_fuel(nvm) nvm.liquid = nvm.liquid or {} nvm.liquid.amount = nvm.liquid.amount or 0 return nvm.liquid.amount > 0 +end + +function techage.fuel.get_fuel_amount(nvm) + if nvm.liquid and nvm.liquid.amount then + return nvm.liquid.amount + end + return 0 end \ No newline at end of file diff --git a/basis/liquid_lib.lua b/basis/liquid_lib.lua index 9c3fcb2..f01695c 100644 --- a/basis/liquid_lib.lua +++ b/basis/liquid_lib.lua @@ -222,6 +222,13 @@ function techage.liquid.on_punch(pos, node, puncher, pointed_thing) end end +function techage.liquid.get_liquid_amount(nvm) + if nvm.liquid and nvm.liquid.amount then + return nvm.liquid.amount + end + return 0 +end + techage.liquid.get_liquid_def = get_liquid_def techage.liquid.get_container_def = get_container_def techage.liquid.is_container_empty = is_container_empty diff --git a/basis/node_states.lua b/basis/node_states.lua index a159e92..8f49aac 100644 --- a/basis/node_states.lua +++ b/basis/node_states.lua @@ -446,23 +446,15 @@ function NodeStates:on_receive_message(pos, topic, payload) self:stop(pos, techage.get_nvm(pos)) return true elseif topic == "state" then - local node = techage.get_node_lvm(pos) + local node = minetest.get_node(pos) if node.name == "ignore" then -- unloaded node? return "unloaded" end return techage.get_state_string(techage.get_nvm(pos)) - elseif topic == "counter" then - return nvm.techage_item_meter or 1 - elseif topic == "clear_counter" then - nvm.techage_item_meter = 0 - return true elseif topic == "fuel" then - local inv = M(pos):get_inventory() - if inv:get_size("fuel") == 1 then - local stack = inv:get_stack("fuel", 1) - return stack:get_count() - end - return + return techage.fuel.get_fuel_amount(nvm) + elseif topic == "load" then + return techage.liquid.get_liquid_amount(nvm) else return "unsupported" end diff --git a/chemistry/ta4_doser.lua b/chemistry/ta4_doser.lua index dca4a4e..37066e9 100644 --- a/chemistry/ta4_doser.lua +++ b/chemistry/ta4_doser.lua @@ -304,15 +304,7 @@ minetest.register_node("techage:ta4_doser_on", { techage.register_node({"techage:ta4_doser", "techage:ta4_doser_on"}, { on_recv_message = function(pos, src, topic, payload) - local resp = State:on_receive_message(pos, topic, payload) - if resp then - return resp - else - return "unsupported" - end - end, - on_node_load = function(pos) - State:on_node_load(pos) + return State:on_receive_message(pos, topic, payload) end, }) diff --git a/coal_power_station/firebox.lua b/coal_power_station/firebox.lua index 4a10fbe..37dbb5d 100644 --- a/coal_power_station/firebox.lua +++ b/coal_power_station/firebox.lua @@ -207,15 +207,9 @@ techage.register_node({"techage:coalfirebox"}, { on_recv_message = function(pos, src, topic, payload) local nvm = techage.get_nvm(pos) if topic == "state" then - if nvm.running then - return "running" - else - return "stopped" - end + return nvm.running and "running" or "stopped" elseif topic == "fuel" then - local inv = M(pos):get_inventory() - local stack = inv:get_stack("fuel", 1) - return stack:get_count() + return techage.fuel.get_fuel_amount(nvm) else return "unsupported" end @@ -230,17 +224,3 @@ minetest.register_craft({ {'default:stone', 'default:stone', 'default:stone'}, }, }) - -minetest.register_lbm({ - label = "[techage] Power Station firebox", - name = "techage:coalfirebox", - nodenames = {"techage:coalfirebox"}, - run_at_every_load = true, - action = function(pos, node) - local nvm = techage.get_nvm(pos) - nvm.running = true - minetest.get_node_timer(pos):start(CYCLE_TIME) - end -}) - - diff --git a/coal_power_station/generator.lua b/coal_power_station/generator.lua index 8611829..226a9ef 100644 --- a/coal_power_station/generator.lua +++ b/coal_power_station/generator.lua @@ -25,6 +25,8 @@ local Cable = techage.ElectricCable local power = techage.power local networks = techage.networks +local INFO = [[Command 'load' returns the current provided power in ku]] + local function formspec(self, pos, nvm) return "size[4,4]".. "box[0,-0.1;3.8,0.5;#c6e8ff]".. @@ -222,16 +224,14 @@ techage.register_node({"techage:generator", "techage:generator_on"}, { end, on_recv_message = function(pos, src, topic, payload) local nvm = techage.get_nvm(pos) - if topic == "load" then - return techage.power.percent(PWR_CAPA, nvm.provided) + if topic == "info" then + return INFO + elseif topic == "load" then + return math.floor((nvm.provided or 0) + 0.5) else return State:on_receive_message(pos, topic, payload) end end, - on_node_load = function(pos) - M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) - State:on_node_load(pos) - end, }) minetest.register_craft({ diff --git a/coal_power_station/oilfirebox.lua b/coal_power_station/oilfirebox.lua index 9c9cfbb..1e7636e 100644 --- a/coal_power_station/oilfirebox.lua +++ b/coal_power_station/oilfirebox.lua @@ -170,13 +170,9 @@ techage.register_node({"techage:oilfirebox"}, { on_recv_message = function(pos, src, topic, payload) local nvm = techage.get_nvm(pos) if topic == "state" then - if nvm.running then - return "running" - else - return "stopped" - end + return nvm.running and "running" or "stopped" elseif topic == "fuel" then - return nvm.liquid and nvm.liquid.amount and nvm.liquid.amount + return techage.fuel.get_fuel_amount(nvm) else return "unsupported" end @@ -192,16 +188,4 @@ minetest.register_craft({ }, }) -minetest.register_lbm({ - label = "[techage] Power Station firebox", - name = "techage:steam_engine", - nodenames = {"techage:oilfirebox"}, - run_at_every_load = true, - action = function(pos, node) - local nvm = techage.get_nvm(pos) - nvm.running = true - minetest.get_node_timer(pos):start(CYCLE_TIME) - end -}) - diff --git a/coal_power_station/turbine.lua b/coal_power_station/turbine.lua index cfdd8dd..bcfc8c8 100644 --- a/coal_power_station/turbine.lua +++ b/coal_power_station/turbine.lua @@ -166,7 +166,6 @@ techage.register_node({"techage:turbine", "techage:turbine_on"}, { end end, on_node_load = function(pos, node) - --print("on_node_load", node.name) if node.name == "techage:turbine_on" then play_sound(pos) end diff --git a/energy_storage/generator.lua b/energy_storage/generator.lua index 394d9ef..4577b38 100644 --- a/energy_storage/generator.lua +++ b/energy_storage/generator.lua @@ -25,6 +25,8 @@ local Cable = techage.ElectricCable local power = techage.power local networks = techage.networks +local INFO = [[Command 'load' returns the current provided power in ku]] + local function formspec(self, pos, nvm) return "size[4,4]".. "box[0,-0.1;3.8,0.5;#c6e8ff]".. @@ -223,16 +225,14 @@ techage.register_node({"techage:ta4_generator", "techage:ta4_generator_on"}, { end, on_recv_message = function(pos, src, topic, payload) local nvm = techage.get_nvm(pos) - if topic == "load" then - return techage.power.percent(PWR_CAPA, nvm.provided) + if topic == "info" then + return INFO + elseif topic == "load" then + return math.floor((nvm.provided or 0) + 0.5) else return State:on_receive_message(pos, topic, payload) end end, - on_node_load = function(pos) - M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) - State:on_node_load(pos) - end, }) minetest.register_craft({ diff --git a/energy_storage/heatexchanger1.lua b/energy_storage/heatexchanger1.lua index b50b723..0cce45a 100644 --- a/energy_storage/heatexchanger1.lua +++ b/energy_storage/heatexchanger1.lua @@ -32,6 +32,8 @@ local Pipe = techage.LiquidPipe local power = techage.power local in_range = techage.in_range +local INFO = [[- Command 'load' returns the storage load in percent]] + local function swap_node(pos, name) local node = techage.get_node_lvm(pos) if node.name == name then @@ -115,6 +117,9 @@ local function after_place_node(pos, placer, itemstack) local nvm = techage.get_nvm(pos) nvm.capa = 0 M(pos):set_string("owner", placer:get_player_name()) + local number = techage.add_node(pos, "techage:heatexchanger1") + M(pos):set_string("node_number", number) + M(pos):set_string("infotext", S("TA4 Heat Exchanger 1").." "..number) Cable:after_place_node(pos) Pipe:after_place_node(pos) end @@ -250,10 +255,24 @@ techage.register_node({"techage:heatexchanger1"}, { end, on_recv_message = function(pos, src, topic, payload) local nvm = techage.get_nvm(pos) - if topic == "load" then + if topic == "state" then + if nvm.charging then + return "running" + elseif nvm.running then + return "standby" + else + return "stopped" + end + elseif topic == "load" then return techage.power.percent(nvm.capa_max, nvm.capa) - elseif topic == "size" then - return (nvm.capa_max or 0) / GRVL_CAPA + elseif topic == "on" then + start_node(pos, techage.get_nvm(pos)) + return true + elseif topic == "off" then + stop_node(pos, techage.get_nvm(pos)) + return true + elseif topic == "info" then + return INFO else return "unsupported" end diff --git a/furnace/firebox.lua b/furnace/firebox.lua index 649d4d1..da832da 100644 --- a/furnace/firebox.lua +++ b/furnace/firebox.lua @@ -215,13 +215,9 @@ techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"}, on_recv_message = function(pos, src, topic, payload) local nvm = techage.get_nvm(pos) if topic == "state" then - if nvm.running then - return "running" - else - return "stopped" - end + return nvm.running and "running" or "stopped" elseif topic == "fuel" then - return nvm.liquid and nvm.liquid.amount and nvm.liquid.amount + return techage.fuel.get_fuel_amount(nvm) else return "unsupported" end @@ -244,15 +240,3 @@ techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"}, }) Pipe:add_secondary_node_names({"techage:furnace_firebox", "techage:furnace_firebox_on"}) - - -minetest.register_lbm({ - label = "[techage] Furnace firebox", - name = "techage:furnace", - nodenames = {"techage:furnace_firebox_on"}, - run_at_every_load = true, - action = function(pos, node) - minetest.get_node_timer(pos):start(CYCLE_TIME) - end -}) - diff --git a/furnace/furnace_top.lua b/furnace/furnace_top.lua index 73b7f85..d0f8d07 100644 --- a/furnace/furnace_top.lua +++ b/furnace/furnace_top.lua @@ -234,15 +234,7 @@ local tubing = { end end, on_recv_message = function(pos, src, topic, payload) - local resp = CRD(pos).State:on_receive_message(pos, topic, payload) - if resp then - return resp - else - return "unsupported" - end - end, - on_node_load = function(pos) - CRD(pos).State:on_node_load(pos) + return CRD(pos).State:on_receive_message(pos, topic, payload) end, } diff --git a/tools/repairkit.lua b/tools/repairkit.lua index 312040c..43409f0 100644 --- a/tools/repairkit.lua +++ b/tools/repairkit.lua @@ -234,21 +234,11 @@ 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 counter = techage.send_single("0", number, "counter", nil) - if counter and counter ~= "" and counter ~= "unsupported" then - counter = dump(counter) - minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": counter = "..counter.." ") - end local load = 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.." % ") end - local size = techage.send_single("0", number, "size", nil) - if size and size ~= "" and size ~= "unsupported" then - size = dump(size) - minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": size = "..size.." units ") - end local owner = M(pos):get_string("owner") or "" if owner ~= "" then minetest.chat_send_player(user:get_player_name(), S("Node owner")..": "..owner.." ")