Get redstone torches mostly workng (had to disable only calling node update routines when power level changes which is incorrect behavior, three redstone torch oscillator is not working correctly)

This commit is contained in:
teknomunk 2024-04-23 08:32:48 +00:00
parent bbbc90e514
commit b67f2261ed
2 changed files with 47 additions and 48 deletions

View File

@ -62,51 +62,47 @@ local function torch_overheated(pos)
timer:start(TORCH_COOLOFF) timer:start(TORCH_COOLOFF)
end end
local function torch_action_on(pos, node) local TORCH_STATE_ON = {
local overheat ["mesecons_torch:mesecon_torch_off"] = "mesecons_torch:mesecon_torch_on",
if node.name == "mesecons_torch:mesecon_torch_on" then ["mesecons_torch:mesecon_torch_off_wall"] = "mesecons_torch:mesecon_torch_on_wall",
overheat = mesecon.do_overheat(pos) }
if overheat then local TORCH_STATE_OFF = {
minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_overheated", param2=node.param2}) ["mesecons_torch:mesecon_torch_on"] = "mesecons_torch:mesecon_torch_off",
else ["mesecons_torch:mesecon_torch_on_wall"] = "mesecons_torch:mesecon_torch_off_wall",
minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_off", param2=node.param2}) }
end local TORCH_STATE_OVERHEAT = {
vl_redstone.set_power(pos, 0, 2) ["mesecons_torch:mesecon_torch_on"] = "mesecons_torch:mesecon_torch_overheated",
elseif node.name == "mesecons_torch:mesecon_torch_on_wall" then ["mesecons_torch:mesecon_torch_on_wall"] = "mesecons_torch:mesecon_torch_overheated_wall",
overheat = mesecon.do_overheat(pos) ["mesecons_torch:mesecon_torch_off"] = "mesecons_torch:mesecon_torch_overheated",
if overheat then ["mesecons_torch:mesecon_torch_off_wall"] = "mesecons_torch:mesecon_torch_overheated_wall",
minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_overheated_wall", param2=node.param2}) }
else
minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_off_wall", param2=node.param2})
end
vl_redstone.set_power(pos, 0, 2)
end
if overheat then
torch_overheated(pos)
end
end
local function torch_action_off(pos, node) local function torch_action_change(pos, node, rule, strength)
local overheat local nodedef = minetest.registered_nodes[node.name]
if node.name == "mesecons_torch:mesecon_torch_off" or node.name == "mesecons_torch:mesecon_torch_overheated" then --local effector_state = ((nodedef.mesecons or {}).effector or {}).state
--local is_on = ( effector_state == mesecon.state.on )
local overheat = false
local original_name = node.name
if strength == 0 then
-- Turn on
node.name = TORCH_STATE_ON[node.name] or node.name
vl_redstone.set_power(pos, 15, 0.1)
overheat = mesecon.do_overheat(pos) overheat = mesecon.do_overheat(pos)
if overheat then else
minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_overheated", param2=node.param2}) -- Turn off
else node.name = TORCH_STATE_OFF[node.name] or node.name
minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_on", param2=node.param2}) vl_redstone.set_power(pos, 0, 0.1)
vl_redstone.set_power(pos, 15, 2)
end
elseif node.name == "mesecons_torch:mesecon_torch_off_wall" or node.name == "mesecons_torch:mesecon_torch_overheated_wall" then
overheat = mesecon.do_overheat(pos)
if overheat then
minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_overheated_wall", param2=node.param2})
else
minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_on_wall", param2=node.param2})
vl_redstone.set_power(pos, 15, 2)
end
end end
if overheat then if overheat then
print("overheat")
torch_overheated(pos) torch_overheated(pos)
node.name = TORCH_STATE_OVERHEAT[node.name] or node.name
end
if node.name ~= original_name then
minetest.swap_node(pos, node)
end end
end end
@ -140,9 +136,9 @@ local off_override = {
effector = { effector = {
state = mesecon.state.on, state = mesecon.state.on,
rules = torch_get_input_rules, rules = torch_get_input_rules,
action_off = torch_action_off, action_change = torch_action_change,
}, },
} },
} }
minetest.override_item("mesecons_torch:mesecon_torch_off", off_override) minetest.override_item("mesecons_torch:mesecon_torch_off", off_override)
@ -158,7 +154,7 @@ local overheated_override = {
on_timer = function(pos, elapsed) on_timer = function(pos, elapsed)
if not mesecon.is_powered(pos) then if not mesecon.is_powered(pos) then
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
torch_action_off(pos, node) torch_action_change(pos, node, nil, 0)
end end
end end
} }
@ -183,7 +179,7 @@ mcl_torches.register_torch(on_def)
local on_override = { local on_override = {
on_destruct = function(pos, oldnode) on_destruct = function(pos, oldnode)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
torch_action_on(pos, node) torch_action_change(pos, node, nil, 0)
end, end,
mesecons = { mesecons = {
receptor = { receptor = {
@ -193,7 +189,7 @@ local on_override = {
effector = { effector = {
state = mesecon.state.off, state = mesecon.state.off,
rules = torch_get_input_rules, rules = torch_get_input_rules,
action_on = torch_action_on, action_change = torch_action_change,
}, },
}, },
_tt_help = S("Provides redstone power when it's not powered itself"), _tt_help = S("Provides redstone power when it's not powered itself"),

View File

@ -151,11 +151,14 @@ local function update_node(pos)
-- Don't do any processing inf the actual strength at this node has changed -- Don't do any processing inf the actual strength at this node has changed
local node_multipower = get_node_multipower_data(pos) local node_multipower = get_node_multipower_data(pos)
local last_strength = node_multipower.strength or 0 local last_strength = node_multipower.strength or 0
--print("At "..vector_to_string(pos).."("..node.name..") strength="..tostring(strength)..",last_strength="..tostring(last_strength))
--[[
print("At "..vector_to_string(pos).."("..node.name..") strength="..tostring(strength)..",last_strength="..tostring(last_strength))
if last_strength == strength then if last_strength == strength then
--print("No strength change") print("No strength change")
return return
end end
--]]
-- Determine the input rule that the strength is coming from (for mesecons compatibility; there are mods that depend on it) -- Determine the input rule that the strength is coming from (for mesecons compatibility; there are mods that depend on it)
local rule = nil local rule = nil
@ -304,7 +307,7 @@ local function get_positions_from_node_rules(pos, rules_type, list, powered)
end end
vl_scheduler.register_function("vl_redstone:flow_power",function(task, source_pos, source_strength, distance) vl_scheduler.register_function("vl_redstone:flow_power",function(task, source_pos, source_strength, distance)
print("Flowing lv"..tostring(source_strength).." power from "..vector_to_string(source_pos).." for "..tostring(distance).." blocks") --print("Flowing lv"..tostring(source_strength).." power from "..vector_to_string(source_pos).." for "..tostring(distance).." blocks")
local processed = {} local processed = {}
local powered = {} local powered = {}
local source_pos_hash = minetest_hash_node_pos(source_pos) local source_pos_hash = minetest_hash_node_pos(source_pos)