diff --git a/basis/consumer.lua b/basis/consumer.lua index f329d9a..b47a628 100644 --- a/basis/consumer.lua +++ b/basis/consumer.lua @@ -57,7 +57,7 @@ local function node_timer(pos, elapsed) crd.State:nopower(pos, mem) end elseif state == techage.NOPOWER and power_available(pos) then - crd.State:start(pos, mem) + crd.State.start_from_timer(crd.State, pos, mem) end -- call the secondary timer routine with the requested frequency if techage.is_operational(mem) then diff --git a/basis/node_states.lua b/basis/node_states.lua index 5aa2549..cb37239 100644 --- a/basis/node_states.lua +++ b/basis/node_states.lua @@ -238,6 +238,11 @@ function NodeStates:start(pos, mem, called_from_on_timer) return false end +-- to be used from node timer functions +function NodeStates:start_from_timer(pos, mem, called_from_on_timer) + minetest.after(0.1, self.start, self, pos, mem) +end + function NodeStates:standby(pos, mem) local state = mem.techage_state or STOPPED if state == RUNNING then diff --git a/oil/pumpjack.lua b/oil/pumpjack.lua index 5860d99..ae69499 100644 --- a/oil/pumpjack.lua +++ b/oil/pumpjack.lua @@ -13,6 +13,7 @@ ]]-- -- for lazy programmers +local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end local M = minetest.get_meta local P = minetest.string_to_pos local S = techage.S @@ -164,7 +165,7 @@ local _, node_name_ta3, _ = if node.name == "techage:oil_drillbit2" then local info = techage.explore.get_oil_info(pos) if info then - M(pos):set_string("storage_pos", S(info.storage_pos)) + M(pos):set_string("storage_pos", P2S(info.storage_pos)) end end end, diff --git a/power/biogas_pipe.lua b/power/biogas_pipe.lua index 09e91de..e214529 100644 --- a/power/biogas_pipe.lua +++ b/power/biogas_pipe.lua @@ -176,7 +176,7 @@ local Boxes = { -- after_place_node = function(pos, placer, itemstack, pointed_thing) -- local meta = minetest.get_meta(pos) --- meta:set_string("infotext", "Position "..S(pos)) +-- meta:set_string("infotext", "Position "..P2S(pos)) -- Pipe:after_place_node(pos) -- techage.sink_power_consumption(pos, 0) -- end, diff --git a/power/power.lua b/power/power.lua index 72337f6..1aa8bc4 100644 --- a/power/power.lua +++ b/power/power.lua @@ -232,6 +232,13 @@ function techage.power.power_cut(pos, dir, cable, cut) end end +-- only for nodes with own 'conn_sides' and rotate function +function techage.power.after_rotate_node(pos, cable) + cable:after_dig_node(pos) + set_conn_dirs(pos, PWR(pos).conn_sides) + cable:after_place_node(pos) +end + function techage.power.register_node(names, pwr_def) for _,name in ipairs(names) do local ndef = minetest.registered_nodes[name] @@ -297,7 +304,10 @@ function techage.power.consume_power(pos, needed) mem.demand1 = mem.demand1 or 0 local val = math.min(needed, mem.demand1) mem.demand1 = mem.demand1 - val - return val + --return val + if mem.reserve then -- TODO ???? + return needed + end end return 0 end diff --git a/power/powerswitch.lua b/power/powerswitch.lua index cbf0f35..a1d586a 100644 --- a/power/powerswitch.lua +++ b/power/powerswitch.lua @@ -20,7 +20,7 @@ local S = techage.S local Cable = techage.ElectricCable local power_cut = techage.power.power_cut - +local after_rotate_node = techage.power.after_rotate_node local Param2ToDir = { [0] = 6, @@ -123,6 +123,18 @@ minetest.register_node("techage:powerswitch_on", { sounds = default.node_sound_wood_defaults(), }) +local function get_conn_dirs(pos, node) + local tbl = {[0]= + {2,4}, {1,3}, {2,4}, {1,3}, + {2,4}, {5,6}, {2,4}, {5,6}, + {2,4}, {5,6}, {2,4}, {5,6}, + {5,6}, {1,3}, {5,6}, {1,3}, + {5,6}, {1,3}, {5,6}, {1,3}, + {2,4}, {1,3}, {2,4}, {1,3}, + } + return tbl[node.param2] +end + local function on_place(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then return itemstack @@ -136,6 +148,7 @@ local function on_rotate(pos, node, user, mode, new_param2) end node.param2 = techage.rotate_wallmounted(node.param2) minetest.swap_node(pos, node) + after_rotate_node(pos, Cable) return true end @@ -168,7 +181,9 @@ minetest.register_node("techage:powerswitch_box", { }) techage.power.register_node({"techage:powerswitch_box"}, { - power_network = Cable}) + power_network = Cable, + conn_sides = get_conn_dirs, +}) minetest.register_craft({ output = "techage:powerswitch 2",