power switch and no-power state bugs fixed.

This commit is contained in:
Joachim Stolberg 2019-07-05 21:44:18 +02:00
parent ec9c89c377
commit 0db9362d80
6 changed files with 37 additions and 6 deletions

View File

@ -57,7 +57,7 @@ local function node_timer(pos, elapsed)
crd.State:nopower(pos, mem) crd.State:nopower(pos, mem)
end end
elseif state == techage.NOPOWER and power_available(pos) then elseif state == techage.NOPOWER and power_available(pos) then
crd.State:start(pos, mem) crd.State.start_from_timer(crd.State, pos, mem)
end end
-- call the secondary timer routine with the requested frequency -- call the secondary timer routine with the requested frequency
if techage.is_operational(mem) then if techage.is_operational(mem) then

View File

@ -238,6 +238,11 @@ function NodeStates:start(pos, mem, called_from_on_timer)
return false return false
end 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) function NodeStates:standby(pos, mem)
local state = mem.techage_state or STOPPED local state = mem.techage_state or STOPPED
if state == RUNNING then if state == RUNNING then

View File

@ -13,6 +13,7 @@
]]-- ]]--
-- for lazy programmers -- for lazy programmers
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local M = minetest.get_meta local M = minetest.get_meta
local P = minetest.string_to_pos local P = minetest.string_to_pos
local S = techage.S local S = techage.S
@ -164,7 +165,7 @@ local _, node_name_ta3, _ =
if node.name == "techage:oil_drillbit2" then if node.name == "techage:oil_drillbit2" then
local info = techage.explore.get_oil_info(pos) local info = techage.explore.get_oil_info(pos)
if info then 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 end
end, end,

View File

@ -176,7 +176,7 @@ local Boxes = {
-- after_place_node = function(pos, placer, itemstack, pointed_thing) -- after_place_node = function(pos, placer, itemstack, pointed_thing)
-- local meta = minetest.get_meta(pos) -- 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) -- Pipe:after_place_node(pos)
-- techage.sink_power_consumption(pos, 0) -- techage.sink_power_consumption(pos, 0)
-- end, -- end,

View File

@ -232,6 +232,13 @@ function techage.power.power_cut(pos, dir, cable, cut)
end end
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) function techage.power.register_node(names, pwr_def)
for _,name in ipairs(names) do for _,name in ipairs(names) do
local ndef = minetest.registered_nodes[name] local ndef = minetest.registered_nodes[name]
@ -297,7 +304,10 @@ function techage.power.consume_power(pos, needed)
mem.demand1 = mem.demand1 or 0 mem.demand1 = mem.demand1 or 0
local val = math.min(needed, mem.demand1) local val = math.min(needed, mem.demand1)
mem.demand1 = mem.demand1 - val mem.demand1 = mem.demand1 - val
return val --return val
if mem.reserve then -- TODO ????
return needed
end
end end
return 0 return 0
end end

View File

@ -20,7 +20,7 @@ local S = techage.S
local Cable = techage.ElectricCable local Cable = techage.ElectricCable
local power_cut = techage.power.power_cut local power_cut = techage.power.power_cut
local after_rotate_node = techage.power.after_rotate_node
local Param2ToDir = { local Param2ToDir = {
[0] = 6, [0] = 6,
@ -123,6 +123,18 @@ minetest.register_node("techage:powerswitch_on", {
sounds = default.node_sound_wood_defaults(), 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) local function on_place(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then if pointed_thing.type ~= "node" then
return itemstack return itemstack
@ -136,6 +148,7 @@ local function on_rotate(pos, node, user, mode, new_param2)
end end
node.param2 = techage.rotate_wallmounted(node.param2) node.param2 = techage.rotate_wallmounted(node.param2)
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
after_rotate_node(pos, Cable)
return true return true
end end
@ -168,7 +181,9 @@ minetest.register_node("techage:powerswitch_box", {
}) })
techage.power.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({ minetest.register_craft({
output = "techage:powerswitch 2", output = "techage:powerswitch 2",