dig wire and receptor, directly and indirectly

This commit is contained in:
Henry Behrendt 2021-09-12 20:54:09 +02:00
parent d2fbbb3fcf
commit 42475a8018
9 changed files with 73 additions and 14 deletions

View File

@ -474,6 +474,12 @@ for _, mode in pairs{"comp", "sub"} do
on_rotate = on_rotate,
}
if state == mesecon.state.on then
nodedef.on_destruct = function(pos, oldnode)
local node = minetest.get_node(pos)
mesecon.on_dignode(pos, node)
end
end
if mode == "comp" and state == mesecon.state.off then
-- This is the prototype
nodedef._doc_items_create_entry = true

View File

@ -5,7 +5,7 @@
-- | | |___ ____| |___ |____ |____| | \| ____|
-- by Jeija, Uberi (Temperest), sfan5, VanessaE, Hawk777 and contributors
--
--
-- extended by socke2398
--
-- This mod adds mesecons[=minecraft redstone] and different receptors/effectors to minetest.
-- See the documentation on the forum for additional information, especially about crafting
@ -134,5 +134,30 @@ function mesecon.receptor_off(pos, rules, opaquespread)
mesecon.queue:add_action(pos, "receptor_off", {rules, opaquespread}, nil, rules)
end
mesecon.queue:add_function("conductor_off", function (pos, rules)
rules = rules or mesecon.rules.default
local node = mesecon.get_node_force(pos)
for _, rule in ipairs(mesecon.flattenrules(rules)) do
mesecon.vm_begin()
mesecon.changesignal(pos, node, rule, mesecon.state.off, 2)
local res, rec_on = mesecon.turnoff(pos, rule)
if (res) then
mesecon.vm_commit()
else
mesecon.vm_abort()
for _, rec in pairs(rec_on) do
local node = mesecon.get_node_force(rec)
local meta = minetest.get_meta(rec)
local voltage = meta:get_string("mesecon_voltage")~="" and meta:get_int("mesecon_voltage") or 15
mesecon.receptor_on(rec, mesecon.receptor_get_rules(node), voltage)
end
end
end
end)
function mesecon.conductor_off(pos, rules)
mesecon.queue:add_action(pos, "conductor_off", {rules}, nil, rules)
end
--Services like turnoff receptor on dignode and so on
dofile(minetest.get_modpath("mesecons").."/services.lua");

View File

@ -147,14 +147,17 @@ function mesecon.on_placenode(pos, node)
end
end
function mesecon.on_dignode(pos, node)
function mesecon.on_dignode(pos, node, direct_dig)
local regnode = minetest.registered_nodes[node.name]
if (regnode and regnode.mesecons and not regnode.on_destruct) or not direct_dig then
if mesecon.is_conductor_on(node) then
minetest.log("action", mesecon.postostring(pos) .. "-->" .. "on_dignode.is_conductor_on")
mesecon.receptor_off(pos, mesecon.conductor_get_rules(node))
mesecon.conductor_off(pos, mesecon.conductor_get_rules(node))
elseif mesecon.is_receptor_on(node.name) then
minetest.log("action", mesecon.postostring(pos) .. "-->" .. "on_dignode.is_receptor_on")
mesecon.receptor_off(pos, mesecon.receptor_get_rules(node), mesecon.is_receptor_opaquespread(node.name))
end
end
if minetest.get_item_group(node.name, "opaque") == 1 then
--local sources = mesecon.is_powered(pos)
local neighbors = mesecon.mcl_get_neighbors(pos)
@ -163,7 +166,7 @@ function mesecon.on_dignode(pos, node)
local nlink = neighbors[n].link
local nnode = minetest.get_node(npos)
if mesecon.is_conductor_on(nnode) then
mesecon.receptor_off(npos, mesecon.conductor_get_rules(nnode))
mesecon.conductor_off(npos, mesecon.conductor_get_rules(nnode))
-- Disable neighbor effectors unless they are in a special ignore group
elseif mesecon.is_effector_on(nnode.name) and mesecon.is_powered(npos) == false and minetest.get_item_group(nnode.name, "mesecon_ignore_opaque_dig") == 0 then
mesecon.changesignal(npos, nnode, nlink, mesecon.state.off, 1)
@ -181,8 +184,13 @@ function mesecon.on_blastnode(pos, node)
return minetest.get_node_drops(node.name, "")
end
function mesecon.reg_on_dignode(pos, node)
mesecon.on_dignode(pos, node, true)
end
minetest.register_on_placenode(mesecon.on_placenode)
minetest.register_on_dignode(mesecon.on_dignode)
minetest.register_on_dignode(mesecon.reg_on_dignode)
-- Overheating service for fast circuits
local OVERHEAT_MAX = mesecon.setting("overheat_max", 8)

View File

@ -293,6 +293,13 @@ function mesecon.register_node(name, spec_common, spec_off, spec_on)
spec_off.__mesecon_state = "off"
spec_on = mesecon.mergetable(spec_common, spec_on);
if spec_on.mesecons and (spec_on.mesecons.receptor or spec_on.mesecons.conductor) then
spec_on.on_destruct = spec_on.on_destruct or
function(pos, oldnode)
local node = minetest.get_node(pos)
mesecon.on_dignode(pos, node)
end
end
spec_off = mesecon.mergetable(spec_common, spec_off);
minetest.register_node(name .. "_on", spec_on)

View File

@ -195,7 +195,10 @@ function mesecon.register_button(basename, description, texture, recipeitem, sou
mesecon.receptor_off(pos, button_get_output_rules(node))
end
end,
on_destruct = function(pos, oldnode)
local node = minetest.get_node(pos)
mesecon.on_dignode(pos, node)
end,
_mcl_blast_resistance = 0.5,
_mcl_hardness = 0.5,
})

View File

@ -368,6 +368,10 @@ for i = 1, 4 do
},
},
on_rotate = on_rotate,
on_destruct = function(pos, oldnode)
local node = minetest.get_node(pos)
mesecon.on_dignode(pos, node)
end,
})
end

View File

@ -185,6 +185,7 @@ local on_override = {
on_destruct = function(pos, oldnode)
local node = minetest.get_node(pos)
torch_action_on(pos, node)
mesecon.on_dignode(pos, node)
end,
mesecons = {
receptor = {

View File

@ -162,6 +162,10 @@ minetest.register_node("mesecons_walllever:wall_lever_on", {
state = mesecon.state.on,
opaquespread = true,
}},
on_destruct = function(pos, oldnode)
local node = minetest.get_node(pos)
mesecon.on_dignode(pos, node)
end,
on_rotate = on_rotate,
_mcl_blast_resistance = 0.5,
_mcl_hardness = 0.5,

View File

@ -190,12 +190,13 @@ local function update_on_place_dig(pos, node)
for _, r in ipairs(mesecon.flattenrules(rules)) do
local np = vector.add(pos, r)
if minetest.registered_nodes[minetest.get_node(np).name] and minetest.registered_nodes[minetest.get_node(np).name].mesecon_wire then
local nnode = minetest.get_node(np).name
if minetest.registered_nodes[nnode] and minetest.registered_nodes[nnode].mesecon_wire then
local abandoned_rules = wire_updateconnect(np)
minetest.log("action", mesecon.postostring(np) .. "-->" .. "wire.update_on_place_dig->" .. mesecon.tabletostring(abandoned_rules))
if next(abandoned_rules) ~= nil then
mesecon.receptor_off(np, abandoned_rules)
mesecon.receptor_off(np, mesecon.conductor_get_rules(minetest.get_node(np)))
mesecon.conductor_off(np, abandoned_rules)
mesecon.conductor_off(np, mesecon.conductor_get_rules(minetest.get_node(np)))
end
end
end