power switch and no-power state bugs fixed.
This commit is contained in:
parent
ec9c89c377
commit
0db9362d80
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user