diff --git a/basis/power.lua b/basis/power.lua index e1f8d69..12a3cb4 100644 --- a/basis/power.lua +++ b/basis/power.lua @@ -104,9 +104,12 @@ local turn_on = nil local function call_turn_on(pos, in_dir, sum) if not pos_already_reached(pos) then + local mem = tubelib2.get_mem(pos) local this = TP(pos) - if this and this.turn_on then - this.turn_on(pos, in_dir, sum) + if this and (not this.valid_power_dir or this.valid_power_dir(pos, mem, in_dir)) then + if this.turn_on then + this.turn_on(pos, in_dir, sum) + end end if this and this.animated_power_network then turn_tube_on(pos, in_dir, this.power_network, sum > 0) diff --git a/steam_engine/consumer.lua b/steam_engine/consumer.lua index 1c966b0..1198ebe 100644 --- a/steam_engine/consumer.lua +++ b/steam_engine/consumer.lua @@ -17,8 +17,10 @@ local S = function(pos) if pos then return minetest.pos_to_string(pos) end end local P = minetest.string_to_pos local M = minetest.get_meta -local POWER_CONSUME = 4 +local POWER_CONSUMPTION = 4 +local Axle = techage.Axle +local consumer = techage.consumer local function swap_node(pos, name) local node = minetest.get_node(pos) @@ -35,13 +37,13 @@ local function valid_power_dir(pos, mem, in_dir) return mem.power_dir == in_dir end -local function turn_on(pos, in_dir, on) - if on then - swap_node(pos, "techage:consumer_on") - else - swap_node(pos, "techage:consumer") - end --- end +local function turn_on_clbk(pos, in_dir, sum) + local mem = tubelib2.get_mem(pos) + if sum > 0 then + swap_node(pos, "techage:consumer_on") + else + swap_node(pos, "techage:consumer") + end end minetest.register_node("techage:consumer", { @@ -56,23 +58,21 @@ minetest.register_node("techage:consumer", { 'techage_filling_ta2.png^techage_frame_ta2.png', }, techage = { - turn_on = turn_on, - power_consumption = techage.consumer_power_consumption, - power_network = techage.Axle, - power_consume = POWER_CONSUME, - animated_power_network = true, + turn_on = turn_on_clbk, + read_power_consumption = consumer.read_power_consumption, + power_network = Axle, power_side = "L", valid_power_dir = valid_power_dir, - + animated_power_network = true, }, after_place_node = function(pos, placer) - local mem = techage.consumer_after_place_node(pos, placer) - mem.power_consume = POWER_CONSUME + local mem = consumer.after_place_node(pos, placer) + mem.power_consumption = POWER_CONSUMPTION end, - after_tube_update = techage.consumer_after_tube_update, - after_dig_node = techage.consumer_after_dig_node, + after_tube_update = consumer.after_tube_update, + after_dig_node = consumer.after_dig_node, paramtype2 = "facedir", groups = {choppy=2, cracky=2, crumbly=2}, @@ -119,17 +119,16 @@ minetest.register_node("techage:consumer_on", { }, }, techage = { - turn_on = turn_on, - power_consumption = techage.consumer_power_consumption, - power_network = techage.Axle, - power_consume = POWER_CONSUME, - animated_power_network = true, + turn_on = turn_on_clbk, + read_power_consumption = consumer.read_power_consumption, + power_network = Axle, + power_side = "L", valid_power_dir = valid_power_dir, + animated_power_network = true, }, - after_place_node = techage.consumer_after_place_node, - after_tube_update = techage.consumer_after_tube_update, - after_dig_node = techage.consumer_after_dig_node, + after_tube_update = consumer.after_tube_update, + after_dig_node = consumer.after_dig_node, paramtype2 = "facedir", groups = {not_in_creative_inventory=1},