From 6bfd108bf1a5a0e75ed4a24418470ca57069cf44 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Tue, 5 Mar 2019 22:42:31 +0100 Subject: [PATCH] consumer with node_states added --- basis/node_states.lua | 37 ++++++++++++++++--------------------- basis/power.lua | 4 ++++ electric/electric_cable.lua | 3 ++- electric/generator.lua | 2 -- init.lua | 3 ++- steam_engine/steam_pipe.lua | 1 + 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/basis/node_states.lua b/basis/node_states.lua index 9d1689e..4fd26ac 100644 --- a/basis/node_states.lua +++ b/basis/node_states.lua @@ -110,6 +110,15 @@ local function can_start(pos, mem) return true end +local function swap_node(pos, name) + local node = minetest.get_node(pos) + if node.name == name then + return + end + node.name = name + minetest.swap_node(pos, node) +end + function NodeStates:new(attr) local o = { -- mandatory @@ -160,9 +169,7 @@ function NodeStates:stop(pos, mem) end mem.techage_state = STOPPED if self.node_name_passive then - local node = minetest.get_node(pos) - node.name = self.node_name_passive - minetest.swap_node(pos, node) + swap_node(pos, self.node_name_passive) end if self.infotext_name then local number = mem.techage_number @@ -196,9 +203,7 @@ function NodeStates:start(pos, mem, called_from_on_timer) self.stop_timer = true end if self.node_name_active then - local node = minetest.get_node(pos) - node.name = self.node_name_active - minetest.swap_node(pos, node) + swap_node(pos, self.node_name_active) end if self.infotext_name then local number = mem.techage_number @@ -221,9 +226,7 @@ function NodeStates:standby(pos, mem) -- timer has to be stopped once to be able to be restarted self.stop_timer = true if self.node_name_passive then - local node = minetest.get_node(pos) - node.name = self.node_name_passive - minetest.swap_node(pos, node) + swap_node(pos, self.node_name_passive) end if self.infotext_name then local number = mem.techage_number @@ -245,9 +248,7 @@ function NodeStates:blocked(pos, mem) -- timer has to be stopped once to be able to be restarted self.stop_timer = true if self.node_name_passive then - local node = minetest.get_node(pos) - node.name = self.node_name_passive - minetest.swap_node(pos, node) + swap_node(pos, self.node_name_passive) end if self.infotext_name then local number = mem.techage_number @@ -266,9 +267,7 @@ function NodeStates:fault(pos, mem) if mem.techage_state == RUNNING or mem.techage_state == STOPPED then mem.techage_state = FAULT if self.node_name_passive then - local node = minetest.get_node(pos) - node.name = self.node_name_passive - minetest.swap_node(pos, node) + swap_node(pos, self.node_name_passive) end if self.infotext_name then local number = mem.techage_number @@ -286,9 +285,7 @@ end function NodeStates:defect(pos, mem) mem.techage_state = DEFECT if self.node_name_defect then - local node = minetest.get_node(pos) - node.name = self.node_name_defect - minetest.swap_node(pos, node) + swap_node(pos, self.node_name_defect) end if self.infotext_name then local number = mem.techage_number @@ -453,9 +450,7 @@ function NodeStates:on_node_repair(pos) if mem.techage_state == DEFECT then mem.techage_state = STOPPED if self.node_name_passive then - local node = minetest.get_node(pos) - node.name = self.node_name_passive - minetest.swap_node(pos, node) + swap_node(pos, self.node_name_passive) end if self.aging_level1 then mem.techage_aging = 0 diff --git a/basis/power.lua b/basis/power.lua index 7f77803..92b5f83 100644 --- a/basis/power.lua +++ b/basis/power.lua @@ -267,6 +267,10 @@ function techage.consumer_after_tube_update(node, pos, out_dir, peer_pos, peer_i minetest.after(0.2, check_power_consumption, pos) end +function techage.consumer_check_power_consumption(pos) + minetest.after(0.2, check_power_consumption, pos) +end + function techage.consumer_after_dig_node(pos, oldnode) TN(oldnode).power_network:after_dig_node(pos) tubelib2.del_mem(pos) diff --git a/electric/electric_cable.lua b/electric/electric_cable.lua index f4b7c85..0bc8024 100644 --- a/electric/electric_cable.lua +++ b/electric/electric_cable.lua @@ -28,7 +28,8 @@ local Cable = tubelib2.Tube:new({ show_infotext = false, force_to_use_tubes = true, primary_node_names = {"techage:electric_cableS", "techage:electric_cableA"}, - secondary_node_names = {"techage:lamp", "techage:lamp_on", "techage:power"}, + secondary_node_names = {"techage:lamp", "techage:lamp_on", "techage:power", + "techage:ele_consumer", "techage:ele_consumer_on"}, after_place_tube = function(pos, param2, tube_type, num_tubes) minetest.swap_node(pos, {name = "techage:electric_cable"..tube_type, param2 = param2 % 32}) M(pos):set_int("tl2_param2", param2) diff --git a/electric/generator.lua b/electric/generator.lua index 5725223..5929317 100644 --- a/electric/generator.lua +++ b/electric/generator.lua @@ -20,8 +20,6 @@ local function formspec(self, pos, mem) "image_button[3,1.2;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. "button[5.5,1.2;1.8,1;update;"..I("Update").."]".. "list[current_player;main;0,3;8,4;]".. - "listring[current_name;water]".. - "listring[current_player;main]".. default.get_hotbar_bg(0, 3) end diff --git a/init.lua b/init.lua index 274da34..d946c89 100644 --- a/init.lua +++ b/init.lua @@ -23,7 +23,7 @@ dofile(MP.."/steam_engine/drive_axle.lua") dofile(MP.."/steam_engine/steam_pipe.lua") dofile(MP.."/steam_engine/firebox.lua") dofile(MP.."/steam_engine/boiler.lua") ---dofile(MP.."/steam_engine/cylinder.lua") +dofile(MP.."/steam_engine/cylinder.lua") --dofile(MP.."/steam_engine/flywheel.lua") dofile(MP.."/steam_engine/gearbox.lua") dofile(MP.."/steam_engine/consumer.lua") @@ -31,6 +31,7 @@ dofile(MP.."/steam_engine/consumer.lua") dofile(MP.."/electric/electric_cable.lua") dofile(MP.."/electric/test.lua") dofile(MP.."/electric/generator.lua") +dofile(MP.."/electric/consumer.lua") --dofile(MP.."/fermenter/biogas_pipe.lua") diff --git a/steam_engine/steam_pipe.lua b/steam_engine/steam_pipe.lua index 2a28697..6be9892 100644 --- a/steam_engine/steam_pipe.lua +++ b/steam_engine/steam_pipe.lua @@ -26,6 +26,7 @@ local Pipe = tubelib2.Tube:new({ dirs_to_check = {1,2,3,4,5,6}, max_tube_length = 6, show_infotext = false, + force_to_use_tubes = true, primary_node_names = {"techage:steam_pipeS", "techage:steam_pipeA"}, secondary_node_names = {"techage:cylinder", "techage:cylinder_on", "techage:boiler2"}, after_place_tube = function(pos, param2, tube_type, num_tubes)