Merge branch 'nextgen'

Conflicts:
	mesecons/wires.lua
This commit is contained in:
Jeija 2012-12-31 18:32:46 +01:00
commit ec07fc27d7
52 changed files with 1404 additions and 1224 deletions

View File

@ -22,14 +22,14 @@
-- { -- {
-- state = mesecon.state.on/off -- state = mesecon.state.on/off
-- rules = rules/get_rules -- rules = rules/get_rules
-- } -- },
-- effector = -- effector =
-- { -- {
-- action_on = function -- action_on = function
-- action_off = function -- action_off = function
-- action_change = function -- action_change = function
-- rules = rules/get_rules -- rules = rules/get_rules
-- } -- },
-- conductor = -- conductor =
-- { -- {
-- state = mesecon.state.on/off -- state = mesecon.state.on/off
@ -70,6 +70,7 @@ dofile(minetest.get_modpath("mesecons").."/internal.lua");
-- Deprecated stuff -- Deprecated stuff
-- To be removed in future releases -- To be removed in future releases
-- Currently there is nothing here
dofile(minetest.get_modpath("mesecons").."/legacy.lua"); dofile(minetest.get_modpath("mesecons").."/legacy.lua");
-- API -- API
@ -79,12 +80,10 @@ function mesecon:receptor_on(pos, rules)
rules = rules or mesecon.rules.default rules = rules or mesecon.rules.default
for _, rule in ipairs(rules) do for _, rule in ipairs(rules) do
local np = { local np = mesecon:addPosRule(pos, rule)
x = pos.x + rule.x, local link, rulename = mesecon:rules_link(pos, np, rules)
y = pos.y + rule.y, if link then
z = pos.z + rule.z} mesecon:turnon(np, rulename)
if mesecon:rules_link(pos, np, rules) then
mesecon:turnon(np, pos)
end end
end end
end end
@ -93,18 +92,16 @@ function mesecon:receptor_off(pos, rules)
rules = rules or mesecon.rules.default rules = rules or mesecon.rules.default
for _, rule in ipairs(rules) do for _, rule in ipairs(rules) do
local np = { local np = mesecon:addPosRule(pos, rule)
x = pos.x + rule.x, local link, rulename = mesecon:rules_link(pos, np, rules)
y = pos.y + rule.y, if link and not mesecon:connected_to_receptor(np) then
z = pos.z + rule.z} mesecon:turnoff(np, rulename)
if mesecon:rules_link(pos, np, rules) and not mesecon:connected_to_pw_src(np) then
mesecon:turnoff(np, pos)
end end
end end
end end
print("[OK] mesecons") print("[OK] Mesecons")
--The actual wires --The actual wires
dofile(minetest.get_modpath("mesecons").."/wires.lua"); dofile(minetest.get_modpath("mesecons").."/wires.lua");

View File

@ -1,162 +1,202 @@
-- INTERNAL -- Internal.lua - The core of mesecons
--
-- For more practical developer resources see mesecons.tk
--
-- Function overview
-- mesecon:get_effector(nodename) --> Returns the mesecons.effector -specifictation in the nodedef by the nodename
-- mesecon:get_receptor(nodename) --> Returns the mesecons.receptor -specifictation in the nodedef by the nodename
-- mesecon:get_conductor(nodename) --> Returns the mesecons.conductor-specifictation in the nodedef by the nodename
-- mesecon:get_any_inputrules (node) --> Returns the rules of a node if it is a conductor or an effector
-- mesecon:get_any_outputrules (node) --> Returns the rules of a node if it is a conductor or a receptor
-- Receptors -- RECEPTORS
-- Nodes that can power mesecons -- mesecon:is_receptor(nodename) --> Returns true if nodename is a receptor
function mesecon:is_receptor_node(nodename) -- mesecon:is_receptor_on(nodename) --> Returns true if nodename is an receptor with state = mesecon.state.on
-- mesecon:is_receptor_off(nodename) --> Returns true if nodename is an receptor with state = mesecon.state.off
-- mesecon:receptor_get_rules(node) --> Returns the rules of the receptor (mesecon.rules.default if none specified)
-- EFFECTORS
-- mesecon:is_effector(nodename) --> Returns true if nodename is an effector
-- mesecon:is_effector_on(nodename) --> Returns true if nodename is an effector with nodedef.mesecons.effector.action_off
-- mesecon:is_effector_off(nodename) --> Returns true if nodename is an effector with nodedef.mesecons.effector.action_on
-- mesecon:effector_get_rules(node) --> Returns the input rules of the effector (mesecon.rules.default if none specified)
-- SIGNALS
-- mesecon:activate(pos, node) --> Activates the effector node at the specific pos (calls nodedef.mesecons.effector.action_on)
-- mesecon:deactivate(pos, node) --> Deactivates the effector node at the specific pos (calls nodedef.mesecons.effector.action_off)
-- mesecon:changesignal(pos, node) --> Changes the effector node at the specific pos (calls nodedef.mesecons.effector.action_change)
-- RULES
-- mesecon:add_rules(name, rules) | deprecated? --> Saves rules table by name
-- mesecon:get_rules(name, rules) | deprecated? --> Loads rules table with name
-- CONDUCTORS
-- mesecon:is_conductor(nodename) --> Returns true if nodename is a conductor
-- mesecon:is_conductor_on(nodename) --> Returns true if nodename is a conductor with state = mesecon.state.on
-- mesecon:is_conductor_off(nodename) --> Returns true if nodename is a conductor with state = mesecon.state.off
-- mesecon:get_conductor_on(offstate) --> Returns the onstate nodename of the conductor with the name offstate
-- mesecon:get_conductor_off(onstate) --> Returns the offstate nodename of the conductor with the name onstate
-- mesecon:conductor_get_rules(node) --> Returns the input+output rules of a conductor (mesecon.rules.default if none specified)
-- HIGH-LEVEL Internals
-- mesecon:is_power_on(pos) --> Returns true if pos emits power in any way
-- mesecon:is_power_off(pos) --> Returns true if pos does not emit power in any way
-- mesecon:turnon(pos, rulename) --> Returns true whatever there is at pos. Calls itself for connected nodes (if pos is a conductor) --> recursive, the rulename is the name of the input rule that caused calling turnon
-- mesecon:turnoff(pos, rulename) --> Turns off whatever there is at pos. Calls itself for connected nodes (if pos is a conductor) --> recursive, the rulename is the name of the input rule that caused calling turnoff
-- mesecon:connected_to_receptor(pos) --> Returns true if pos is connected to a receptor directly or via conductors; calls itself if pos is a conductor --> recursive
-- mesecon:rules_link(output, input, dug_outputrules) --> Returns true if outputposition + outputrules = inputposition and inputposition + inputrules = outputposition (if the two positions connect)
-- mesecon:rules_link_anydir(outp., inp., d_outpr.) --> Same as rules mesecon:rules_link but also returns true if output and input are swapped
-- mesecon:is_powered(pos) --> Returns true if pos is powered by a receptor or a conductor
-- RULES ROTATION helpsers
-- mesecon:rotate_rules_right(rules)
-- mesecon:rotate_rules_left(rules)
-- mesecon:rotate_rules_up(rules)
-- mesecon:rotate_rules_down(rules)
-- These functions return rules that have been rotated in the specific direction
-- General
function mesecon:get_effector(nodename)
if minetest.registered_nodes[nodename] if minetest.registered_nodes[nodename]
and minetest.registered_nodes[nodename].mesecons and minetest.registered_nodes[nodename].mesecons
and minetest.registered_nodes[nodename].mesecons.receptor and minetest.registered_nodes[nodename].mesecons.effector then
and minetest.registered_nodes[nodename].mesecons.receptor.state == mesecon.state.on then return minetest.registered_nodes[nodename].mesecons.effector
return true
end end
for _, receptor in ipairs(mesecon.receptors) do end
if receptor.onstate == nodename then
return true function mesecon:get_receptor(nodename)
end if minetest.registered_nodes[nodename]
and minetest.registered_nodes[nodename].mesecons
and minetest.registered_nodes[nodename].mesecons.receptor then
return minetest.registered_nodes[nodename].mesecons.receptor
end
end
function mesecon:get_conductor(nodename)
if minetest.registered_nodes[nodename]
and minetest.registered_nodes[nodename].mesecons
and minetest.registered_nodes[nodename].mesecons.conductor then
return minetest.registered_nodes[nodename].mesecons.conductor
end
end
function mesecon:get_any_outputrules (node)
if mesecon:is_conductor(node.name) then
return mesecon:conductor_get_rules(node)
elseif mesecon:is_receptor(node.name) then
return mesecon:receptor_get_rules(node)
end end
return false return false
end end
function mesecon:is_receptor_node_off(nodename, pos, ownpos) function mesecon:get_any_inputrules (node)
if minetest.registered_nodes[nodename] if mesecon:is_conductor(node.name) then
and minetest.registered_nodes[nodename].mesecons return mesecon:conductor_get_rules(node)
and minetest.registered_nodes[nodename].mesecons.receptor elseif mesecon:is_effector(node.name) then
and minetest.registered_nodes[nodename].mesecons.receptor.state == mesecon.state.off then return mesecon:effector_get_rules(node)
end
return false
end
-- Receptors
-- Nodes that can power mesecons
function mesecon:is_receptor_on(nodename)
local receptor = mesecon:get_receptor(nodename)
if receptor and receptor.state == mesecon.state.on then
return true return true
end end
for _, receptor in ipairs(mesecon.receptors) do return false
if receptor.offstate == nodename then end
return true
end function mesecon:is_receptor_off(nodename)
local receptor = mesecon:get_receptor(nodename)
if receptor and receptor.state == mesecon.state.off then
return true
end
return false
end
function mesecon:is_receptor(nodename)
local receptor = mesecon:get_receptor(nodename)
if receptor then
return true
end end
return false return false
end end
function mesecon:receptor_get_rules(node) function mesecon:receptor_get_rules(node)
if minetest.registered_nodes[node.name].mesecons local receptor = mesecon:get_receptor(node.name)
and minetest.registered_nodes[node.name].mesecons.receptor then if receptor then
local rules = minetest.registered_nodes[node.name].mesecons.receptor.rules local rules = receptor.rules
if type(rules) == 'function' then if type(rules) == 'function' then
return rules(node) return rules(node)
elseif rules then elseif rules then
return rules return rules
end end
end end
for _, receptor in ipairs(mesecon.receptors) do --TODO
if receptor.onstate == node.name or receptor.offstate == node.name then
if receptor.get_rules ~= nil then
return receptor.get_rules(node.param2)
elseif receptor.rules ~=nil then
return receptor.rules
else
return mesecon:get_rules("default")
end
end
end
return mesecon.rules.default return mesecon.rules.default
end end
-- Effectors -- Effectors
-- Nodes that can be powered by mesecons -- Nodes that can be powered by mesecons
function mesecon:is_effector_on(nodename) function mesecon:is_effector_on(nodename)
if minetest.registered_nodes[nodename] local effector = mesecon:get_effector(nodename)
and minetest.registered_nodes[nodename].mesecons if effector and effector.action_off then
and minetest.registered_nodes[nodename].mesecons.effector
and minetest.registered_nodes[nodename].mesecons.effector.action_off then
return true return true
end end
for _, effector in ipairs(mesecon.effectors) do --TODO
if effector.onstate == nodename then
return true
end
end
return false return false
end end
function mesecon:is_effector_off(nodename) function mesecon:is_effector_off(nodename)
if minetest.registered_nodes[nodename] local effector = mesecon:get_effector(nodename)
and minetest.registered_nodes[nodename].mesecons if effector and effector.action_on then
and minetest.registered_nodes[nodename].mesecons.effector
and minetest.registered_nodes[nodename].mesecons.effector.action_on then
return true return true
end end
for _, effector in ipairs(mesecon.effectors) do --TODO
if effector.offstate == nodename then
return true
end
end
return false return false
end end
function mesecon:is_effector(nodename) function mesecon:is_effector(nodename)
if minetest.registered_nodes[nodename] local effector = mesecon:get_effector(nodename)
and minetest.registered_nodes[nodename].mesecons if effector then
and minetest.registered_nodes[nodename].mesecons.effector then
return true return true
end end
return mesecon:is_effector_on(nodename) or mesecon:is_effector_off(nodename) --TODO return false
end end
function mesecon:effector_get_input_rules(node) function mesecon:effector_get_rules(node)
if minetest.registered_nodes[node.name].mesecons local effector = mesecon:get_effector(node.name)
and minetest.registered_nodes[node.name].mesecons.effector then if effector then
local rules = minetest.registered_nodes[node.name].mesecons.effector.rules local rules = effector.rules
if type(rules) == 'function' then if type(rules) == 'function' then
return rules(node) return rules(node)
elseif rules then elseif rules then
return rules return rules
end end
end end
for _, effector in ipairs(mesecon.effectors) do
if effector.onstate == node.name
or effector.offstate == node.name then
if effector.get_input_rules ~= nil then
return effector.get_input_rules(node.param2)
elseif effector.input_rules ~=nil then
return effector.input_rules
else
return mesecon:get_rules("default")
end
end
end
return mesecon.rules.default return mesecon.rules.default
end end
--Signals --Signals
function mesecon:activate(pos, node) function mesecon:activate(pos, node, rulename)
if minetest.registered_nodes[node.name] local effector = mesecon:get_effector(node.name)
and minetest.registered_nodes[node.name].mesecons if effector and effector.action_on then
and minetest.registered_nodes[node.name].mesecons.effector effector.action_on (pos, node, rulename)
and minetest.registered_nodes[node.name].mesecons.effector.action_on then
minetest.registered_nodes[node.name].mesecons.effector.action_on (pos, node)
end
for _, action in ipairs(mesecon.actions_on) do --TODO
action(pos, node)
end end
end end
function mesecon:deactivate(pos, node) --TODO function mesecon:deactivate(pos, node, rulename)
if minetest.registered_nodes[node.name] local effector = mesecon:get_effector(node.name)
and minetest.registered_nodes[node.name].mesecons if effector and effector.action_off then
and minetest.registered_nodes[node.name].mesecons.effector effector.action_off (pos, node, rulename)
and minetest.registered_nodes[node.name].mesecons.effector.action_off then
minetest.registered_nodes[node.name].mesecons.effector.action_off(pos, node)
end
for _, action in ipairs(mesecon.actions_off) do
action(pos, node)
end end
end end
function mesecon:changesignal(pos, node) --TODO function mesecon:changesignal(pos, node, rulename)
if minetest.registered_nodes[node.name] local effector = mesecon:get_effector(node.name)
and minetest.registered_nodes[node.name].mesecons if effector and effector.action_change then
and minetest.registered_nodes[node.name].mesecons.effector effector.action_change (pos, node, rulename)
and minetest.registered_nodes[node.name].mesecons.effector.action_change then
minetest.registered_nodes[node.name].mesecons.effector.action_change(pos, node)
end
for _, action in ipairs(mesecon.actions_change) do
action(pos, node)
end end
end end
@ -172,97 +212,64 @@ end
-- Conductors -- Conductors
function mesecon:get_conductor_on(offstate)
if minetest.registered_nodes[offstate]
and minetest.registered_nodes[offstate].mesecons
and minetest.registered_nodes[offstate].mesecons.conductor then
return minetest.registered_nodes[offstate].mesecons.conductor.onstate
end
for _, conductor in ipairs(mesecon.conductors) do --TODO
if conductor.offstate == offstate then
return conductor.onstate
end
end
return false
end
function mesecon:get_conductor_off(onstate)
if minetest.registered_nodes[onstate]
and minetest.registered_nodes[onstate].mesecons
and minetest.registered_nodes[onstate].mesecons.conductor then
return minetest.registered_nodes[onstate].mesecons.conductor.offstate
end
for _, conductor in ipairs(mesecon.conductors) do --TODO
if conductor.onstate == onstate then
return conductor.offstate
end
end
return false
end
function mesecon:is_conductor_on(nodename) function mesecon:is_conductor_on(nodename)
if minetest.registered_nodes[nodename] local conductor = mesecon:get_conductor(nodename)
and minetest.registered_nodes[nodename].mesecons if conductor and conductor.state == mesecon.state.on then
and minetest.registered_nodes[nodename].mesecons.conductor
and minetest.registered_nodes[nodename].mesecons.conductor.state == mesecon.state.on then
return true return true
end end
for _, conductor in ipairs(mesecon.conductors) do --TODO
if conductor.onstate == nodename then
return true
end
end
return false return false
end end
function mesecon:is_conductor_off(nodename) function mesecon:is_conductor_off(nodename)
if minetest.registered_nodes[nodename] local conductor = mesecon:get_conductor(nodename)
and minetest.registered_nodes[nodename].mesecons if conductor and conductor.state == mesecon.state.off then
and minetest.registered_nodes[nodename].mesecons.conductor
and minetest.registered_nodes[nodename].mesecons.conductor.state == mesecon.state.off then
return true return true
end end
for _, conductor in ipairs(mesecon.conductors) do --TODO
if conductor.offstate == nodename then
return true
end
end
return false return false
end end
function mesecon:is_conductor(nodename) function mesecon:is_conductor(nodename)
--TODO local conductor = mesecon:get_conductor(nodename)
return mesecon:is_conductor_on(nodename) or mesecon:is_conductor_off(nodename) if conductor then
return true
end
return false
end
function mesecon:get_conductor_on(offstate)
local conductor = mesecon:get_conductor(offstate)
if conductor then
return conductor.onstate
end
return false
end
function mesecon:get_conductor_off(onstate)
local conductor = mesecon:get_conductor(onstate)
if conductor then
return conductor.offstate
end
return false
end end
function mesecon:conductor_get_rules(node) function mesecon:conductor_get_rules(node)
if minetest.registered_nodes[node.name] local conductor = mesecon:get_conductor(node.name)
and minetest.registered_nodes[node.name].mesecons if conductor then
and minetest.registered_nodes[node.name].mesecons.conductor then local rules = conductor.rules
local rules = minetest.registered_nodes[node.name].mesecons.conductor.rules
if type(rules) == 'function' then if type(rules) == 'function' then
return rules(node) return rules(node)
elseif rules then elseif rules then
return rules return rules
end end
end end
for _, conductor in ipairs(mesecon.conductors) do --TODO
if conductor.onstate == node.name
or conductor.offstate == node.name then
if conductor.get_rules ~= nil then
return conductor.get_rules(node.param2)
else
return conductor.rules
end
end
end
return mesecon.rules.default return mesecon.rules.default
end end
-- -- some more general high-level stuff
function mesecon:is_power_on(pos) function mesecon:is_power_on(pos)
local node = minetest.env:get_node(pos) local node = minetest.env:get_node(pos)
if mesecon:is_conductor_on(node.name) or mesecon:is_receptor_node(node.name) then if mesecon:is_conductor_on(node.name) or mesecon:is_receptor_on(node.name) then
return true return true
end end
return false return false
@ -270,13 +277,13 @@ end
function mesecon:is_power_off(pos) function mesecon:is_power_off(pos)
local node = minetest.env:get_node(pos) local node = minetest.env:get_node(pos)
if mesecon:is_conductor_off(node.name) or mesecon:is_receptor_node_off(node.name) then if mesecon:is_conductor_off(node.name) or mesecon:is_receptor_off(node.name) then
return true return true
end end
return false return false
end end
function mesecon:turnon(pos) function mesecon:turnon(pos, rulename)
local node = minetest.env:get_node(pos) local node = minetest.env:get_node(pos)
if mesecon:is_conductor_off(node.name) then if mesecon:is_conductor_off(node.name) then
@ -285,22 +292,21 @@ function mesecon:turnon(pos)
for _, rule in ipairs(rules) do for _, rule in ipairs(rules) do
local np = mesecon:addPosRule(pos, rule) local np = mesecon:addPosRule(pos, rule)
local link, rulename = mesecon:rules_link(pos, np)
if mesecon:rules_link(pos, np) then if link then
mesecon:turnon(np) mesecon:turnon(np, rulename)
end end
end end
end elseif mesecon:is_effector(node.name) then
mesecon:changesignal(pos, node, rulename)
if mesecon:is_effector(node.name) then
mesecon:changesignal(pos, node)
if mesecon:is_effector_off(node.name) then if mesecon:is_effector_off(node.name) then
mesecon:activate(pos, node) mesecon:activate(pos, node, rulename)
end end
end end
end end
function mesecon:turnoff(pos) function mesecon:turnoff(pos, rulename)
local node = minetest.env:get_node(pos) local node = minetest.env:get_node(pos)
if mesecon:is_conductor_on(node.name) then if mesecon:is_conductor_on(node.name) then
@ -309,87 +315,88 @@ function mesecon:turnoff(pos)
for _, rule in ipairs(rules) do for _, rule in ipairs(rules) do
local np = mesecon:addPosRule(pos, rule) local np = mesecon:addPosRule(pos, rule)
local link, rulename = mesecon:rules_link(pos, np)
if mesecon:rules_link(pos, np) then if link then
mesecon:turnoff(np) mesecon:turnoff(np, rulename)
end end
end end
end elseif mesecon:is_effector(node.name) then
mesecon:changesignal(pos, node, rulename)
if mesecon:is_effector(node.name) then
mesecon:changesignal(pos, node)
if mesecon:is_effector_on(node.name) if mesecon:is_effector_on(node.name)
and not mesecon:is_powered(pos) then and not mesecon:is_powered(pos) then
mesecon:deactivate(pos, node) mesecon:deactivate(pos, node, rulename)
end end
end end
end end
function mesecon:connected_to_pw_src(pos, checked) function mesecon:connected_to_receptor(pos)
local c = 1 local node = minetest.env:get_node(pos)
checked = checked or {}
while checked[c] ~= nil do --find out if node has already been checked (to prevent from endless loop)
if mesecon:cmpPos(checked[c], pos) then
return false, checked
end
c = c + 1
end
checked[c] = {x=pos.x, y=pos.y, z=pos.z} --add current node to checked
local node = minetest.env:get_node_or_nil(pos) -- Check if conductors around are connected
if node == nil then return false, checked end local rules = mesecon:get_any_inputrules(node)
if not mesecon:is_conductor(node.name) then return false, checked end if not rules then return false end
if mesecon:is_powered_by_receptor(pos) then --return if conductor is powered
return true, checked
end
--Check if conductors around are connected
local connected
local rules = mesecon:conductor_get_rules(node)
for _, rule in ipairs(rules) do for _, rule in ipairs(rules) do
local np = mesecon:addPosRule(pos, rule) local np = mesecon:addPosRule(pos, rule)
if mesecon:rules_link(pos, np) then if mesecon:rules_link(np, pos) then
connected, checked = mesecon:connected_to_pw_src(np, checked) if mesecon:find_receptor_on(np, {}) then
if connected then
return true return true
end end
end end
end end
return false, checked
return false
end end
function mesecon:rules_link(output, input, dug_outputrules) --output/input are positions (outputrules optional, used if node has been dug) function mesecon:find_receptor_on(pos, checked)
local outputnode = minetest.env:get_node(output) -- find out if node has already been checked (to prevent from endless loop)
local inputnode = minetest.env:get_node(input) for _, cp in ipairs(checked) do
local outputrules = dug_outputrules if mesecon:cmpPos(cp, pos) then
local inputrules return false, checked
if outputrules == nil then
if mesecon:is_conductor(outputnode.name) then
outputrules = mesecon:conductor_get_rules(outputnode)
elseif mesecon:is_receptor_node(outputnode.name) or mesecon:is_receptor_node_off(outputnode.name) then
outputrules = mesecon:receptor_get_rules(outputnode)
else
return false
end end
end end
if mesecon:is_conductor(inputnode.name) then -- add current position to checked
inputrules = mesecon:conductor_get_rules(inputnode) table.insert(checked, {x=pos.x, y=pos.y, z=pos.z})
elseif mesecon:is_effector(inputnode.name) then local node = minetest.env:get_node(pos)
inputrules = mesecon:effector_get_input_rules(inputnode)
else if mesecon:is_receptor_on(node.name) then
return false return true
end end
if mesecon:is_conductor(node.name) then
local rules = mesecon:conductor_get_rules(node)
for _, rule in ipairs(rules) do
local np = mesecon:addPosRule(pos, rule)
if mesecon:rules_link(np, pos) then
if mesecon:find_receptor_on(np, checked) then
return true
end
end
end
end
return false
end
function mesecon:rules_link(output, input, dug_outputrules) --output/input are positions (outputrules optional, used if node has been dug), second return value: the name of the affected input rule
local outputnode = minetest.env:get_node(output)
local inputnode = minetest.env:get_node(input)
local outputrules = dug_outputrules or mesecon:get_any_outputrules (outputnode)
local inputrules = mesecon:get_any_inputrules (inputnode)
if not outputrules or not inputrules then
return
end
for _, outputrule in ipairs(outputrules) do for _, outputrule in ipairs(outputrules) do
if mesecon:cmpPos(mesecon:addPosRule(output, outputrule), input) then -- Check if output sends to input -- Check if output sends to input
if mesecon:cmpPos(mesecon:addPosRule(output, outputrule), input) then
for _, inputrule in ipairs(inputrules) do for _, inputrule in ipairs(inputrules) do
if mesecon:cmpPos(mesecon:addPosRule(input, inputrule), output) then --Check if input accepts from output -- Check if input accepts from output
return true if mesecon:cmpPos(mesecon:addPosRule(input, inputrule), output) then
return true, inputrule.name
end end
end end
end end
@ -397,125 +404,69 @@ function mesecon:rules_link(output, input, dug_outputrules) --output/input are p
return false return false
end end
function mesecon:rules_link_bothdir(pos1, pos2) function mesecon:rules_link_anydir(pos1, pos2)
return mesecon:rules_link(pos1, pos2) or mesecon:rules_link(pos2, pos1) return mesecon:rules_link(pos1, pos2) or mesecon:rules_link(pos2, pos1)
end end
function mesecon:is_powered_by_conductor(pos)
local j = 1
local k = 1
local rules
local con_pos = {}
local con_rules = {}
local con_node
local node = minetest.env:get_node(pos)
if mesecon:is_conductor(node.name) then
rules = mesecon:conductor_get_rules(node)
elseif mesecon:is_effector(node.name) then
rules = mesecon:effector_get_input_rules(node)
else
return false
end
for _, rule in ipairs(rules) do
local con_pos = mesecon:addPosRule(pos, rule)
con_node = minetest.env:get_node(con_pos)
if mesecon:is_conductor_on(con_node.name) and mesecon:rules_link(con_pos, pos) then
return true
end
end
return false
end
function mesecon:is_powered_by_receptor(pos)
local j = 1
local k = 1
local rules
local rcpt_pos = {}
local rcpt_rules = {}
local rcpt_node
local node = minetest.env:get_node(pos)
if mesecon:is_conductor(node.name) then
rules = mesecon:conductor_get_rules(node)
elseif mesecon:is_effector(node.name) then
rules = mesecon:effector_get_input_rules(node)
else
return false
end
for _, rule in ipairs(rules) do
local rcpt_pos = mesecon:addPosRule(pos, rule)
rcpt_node = minetest.env:get_node(rcpt_pos)
if mesecon:is_receptor_node(rcpt_node.name) and mesecon:rules_link(rcpt_pos, pos) then
return true
end
end
return false
end
function mesecon:is_powered(pos) function mesecon:is_powered(pos)
return mesecon:is_powered_by_conductor(pos) or mesecon:is_powered_by_receptor(pos) local node = minetest.env:get_node(pos)
end local rules = mesecon:get_any_inputrules(node)
if not rules then return false end
function mesecon:updatenode(pos) for _, rule in ipairs(rules) do
if mesecon:connected_to_pw_src(pos) then local np = mesecon:addPosRule(pos, rule)
mesecon:turnon(pos) local nn = minetest.env:get_node(np)
else
mesecon:turnoff(pos) if (mesecon:is_conductor_on (nn.name) or mesecon:is_receptor_on (nn.name))
end and mesecon:rules_link(np, pos) then
return true
end
end
return false
end end
--Rules rotation Functions: --Rules rotation Functions:
function mesecon:rotate_rules_right(rules) function mesecon:rotate_rules_right(rules)
local nr={}; local nr = {}
for i, rule in ipairs(rules) do for i, rule in ipairs(rules) do
nr[i]={} table.insert(nr, {
nr[i].z=rule.x x = -rule.z,
nr[i].x=-rule.z y = rule.y,
nr[i].y=rule.y z = rule.x})
end end
return nr return nr
end end
function mesecon:rotate_rules_left(rules) function mesecon:rotate_rules_left(rules)
local nr={}; local nr = {}
for i, rule in ipairs(rules) do for i, rule in ipairs(rules) do
nr[i]={} table.insert(nr, {
nr[i].z=-rules[i].x x = rule.z,
nr[i].x=rules[i].z y = rule.y,
nr[i].y=rules[i].y z = -rule.x})
end end
return nr return nr
end end
function mesecon:rotate_rules_down(rules) function mesecon:rotate_rules_down(rules)
local nr={}; local nr = {}
for i, rule in ipairs(rules) do for i, rule in ipairs(rules) do
nr[i]={} table.insert(nr, {
nr[i].y=rule.x x = -rule.y,
nr[i].x=-rule.y y = rule.x,
nr[i].z=rule.z z = rule.z})
end end
return nr return nr
end end
function mesecon:rotate_rules_up(rules) function mesecon:rotate_rules_up(rules)
local nr={}; local nr = {}
for i, rule in ipairs(rules) do for i, rule in ipairs(rules) do
nr[i]={} table.insert(nr, {
nr[i].y=-rule.x x = rule.y,
nr[i].x=rule.y y = -rule.x,
nr[i].z=rule.z z = rule.z})
end end
return nr return nr
end end

View File

@ -1,60 +0,0 @@
--very old:
function mesecon:add_receptor_node(name, rules, get_rules)
if get_rules==nil and rules==nil then
rules=mesecon:get_rules("default")
end
table.insert(mesecon.receptors, {onstate = name, rules = rules, get_rules = get_rules})
end
function mesecon:add_receptor_node_off(name, rules, get_rules)
if get_rules==nil and rules==nil then
rules=mesecon:get_rules("default")
end
table.insert(mesecon.receptors, {offstate = name, rules = rules, get_rules = get_rules})
end
--old:
function mesecon:register_receptor(onstate, offstate, rules, get_rules)
if get_rules == nil and rules == nil then
rules=mesecon:get_rules("default")
end
table.insert(mesecon.receptors,
{onstate = onstate,
offstate = offstate,
rules = input_rules,
get_rules = get_rules})
end
function mesecon:register_effector(onstate, offstate, input_rules, get_input_rules)
if get_input_rules==nil and input_rules==nil then
rules=mesecon:get_rules("default")
end
table.insert(mesecon.effectors,
{onstate = onstate,
offstate = offstate,
input_rules = input_rules,
get_input_rules = get_input_rules})
end
function mesecon:register_on_signal_on(action)
table.insert(mesecon.actions_on, action)
end
function mesecon:register_on_signal_off(action)
table.insert(mesecon.actions_off, action)
end
function mesecon:register_on_signal_change(action)
table.insert(mesecon.actions_change, action)
end
function mesecon:register_conductor (onstate, offstate, rules, get_rules)
if rules == nil then
rules = mesecon:get_rules("default")
end
table.insert(mesecon.conductors, {onstate = onstate, offstate = offstate, rules = rules, get_rules = get_rules})
end
mesecon:add_rules("default", mesecon.rules.default)

38
mesecons/oldwires.lua Normal file
View File

@ -0,0 +1,38 @@
minetest.register_node("mesecons:mesecon_off", {
drawtype = "raillike",
tiles = {"jeija_mesecon_off.png", "jeija_mesecon_curved_off.png", "jeija_mesecon_t_junction_off.png", "jeija_mesecon_crossing_off.png"},
inventory_image = "jeija_mesecon_off.png",
wield_image = "jeija_mesecon_off.png",
paramtype = "light",
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.45, 0.5},
},
groups = {dig_immediate=3, mesecon=1, mesecon_conductor_craftable=1},
description="Mesecons",
mesecons = {conductor={
state = mesecon.state.off,
onstate = "mesecons:mesecon_on"
}}
})
minetest.register_node("mesecons:mesecon_on", {
drawtype = "raillike",
tiles = {"jeija_mesecon_on.png", "jeija_mesecon_curved_on.png", "jeija_mesecon_t_junction_on.png", "jeija_mesecon_crossing_on.png"},
paramtype = "light",
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.45, 0.5},
},
groups = {dig_immediate=3, not_in_creaive_inventory=1, mesecon=1},
drop = '"mesecons:mesecon_off" 1',
light_source = LIGHT_MAX-11,
mesecons = {conductor={
state = mesecon.state.on,
offstate = "mesecons:mesecon_off"
}}
})

View File

@ -1,28 +1,28 @@
minetest.register_on_dignode( mesecon.on_placenode = function (pos, node)
function(pos, oldnode, digger) if mesecon:is_receptor_on(node.name) then
if mesecon:is_conductor_on(oldnode.name) then mesecon:receptor_on(pos, mesecon:receptor_get_rules(node))
mesecon:receptor_off(pos) elseif mesecon:is_powered(pos) then
end if mesecon:is_conductor(node.name) then
mesecon:turnon (pos)
if mesecon:is_receptor_node(oldnode.name) then mesecon:receptor_on (pos, mesecon:conductor_get_rules(node))
mesecon:receptor_off(pos, mesecon:receptor_get_rules(oldnode)) else
mesecon:changesignal(pos, node)
mesecon:activate(pos, node)
end end
elseif mesecon:is_conductor_on(node.name) then
mesecon:swap_node(pos, mesecon:get_conductor_off(node.name))
elseif mesecon:is_effector_on (node.name) then
mesecon:deactivate(pos, node)
end end
) end
minetest.register_on_placenode( mesecon.on_dignode = function (pos, node)
function (pos, node) if mesecon:is_conductor_on(node.name) then
if mesecon:is_receptor_node(node.name) then mesecon:receptor_off(pos, mesecon:conductor_get_rules(node))
mesecon:receptor_on(pos, mesecon:receptor_get_rules(node)) elseif mesecon:is_receptor_on(node.name) then
end mesecon:receptor_off(pos, mesecon:receptor_get_rules(node))
if mesecon:is_powered(pos) then
if mesecon:is_conductor_off(node.name) then
mesecon:turnon(pos, node)
else
mesecon:changesignal(pos, node)
mesecon:activate(pos, node)
end
end
end end
) end
minetest.register_on_placenode(mesecon.on_placenode)
minetest.register_on_dignode(mesecon.on_dignode)

View File

@ -3,3 +3,4 @@ BLINKY_PLANT_INTERVAL = 3
NEW_STYLE_WIRES = true -- true = new nodebox wires, false = old raillike wires NEW_STYLE_WIRES = true -- true = new nodebox wires, false = old raillike wires
PRESSURE_PLATE_INTERVAL = 0.1 PRESSURE_PLATE_INTERVAL = 0.1
OBJECT_DETECTOR_RADIUS = 6 OBJECT_DETECTOR_RADIUS = 6
PISTON_MAXIMUM_PUSH = 15

View File

@ -6,6 +6,15 @@ function mesecon:swap_node(pos, name)
minetest.env:get_meta(pos):from_table(data) minetest.env:get_meta(pos):from_table(data)
end end
function mesecon:move_node(pos, newpos)
local node = minetest.env:get_node(pos)
local meta = minetest.env:get_meta(pos):to_table()
minetest.env:remove_node(pos)
minetest.env:add_node(newpos, node)
minetest.env:get_meta(pos):from_table(meta)
end
function mesecon:addPosRule(p, r) function mesecon:addPosRule(p, r)
return {x = p.x + r.x, y = p.y + r.y, z = p.z + r.z} return {x = p.x + r.x, y = p.y + r.y, z = p.z + r.z}
end end

View File

@ -1,39 +1,3 @@
-- Oldstyle wires:
if NEW_STYLE_WIRES == false then --old wires
minetest.register_node("mesecons:mesecon_off", {
drawtype = "raillike",
tiles = {"jeija_mesecon_off.png", "jeija_mesecon_curved_off.png", "jeija_mesecon_t_junction_off.png", "jeija_mesecon_crossing_off.png"},
inventory_image = "jeija_mesecon_off.png",
wield_image = "jeija_mesecon_off.png",
paramtype = "light",
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.45, 0.5},
},
groups = {dig_immediate=3, mesecon=1, mesecon_conductor_craftable=1},
description="Mesecons",
})
minetest.register_node("mesecons:mesecon_on", {
drawtype = "raillike",
tiles = {"jeija_mesecon_on.png", "jeija_mesecon_curved_on.png", "jeija_mesecon_t_junction_on.png", "jeija_mesecon_crossing_on.png"},
paramtype = "light",
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.45, 0.5},
},
groups = {dig_immediate=3, not_in_creaive_inventory=1, mesecon=1},
drop = '"mesecons:mesecon_off" 1',
light_source = LIGHT_MAX-11,
})
mesecon:register_conductor("mesecons:mesecon_on", "mesecons:mesecon_off")
else -- NEW STYLE WIRES
-- naming scheme: wire:(xp)(zp)(xm)(zm)_on/off -- naming scheme: wire:(xp)(zp)(xm)(zm)_on/off
-- The conditions in brackets define whether there is a mesecon at that place or not -- The conditions in brackets define whether there is a mesecon at that place or not
-- 1 = there is one; 0 = there is none -- 1 = there is one; 0 = there is none
@ -52,6 +16,8 @@ box_zpy = {-1/16, -.5+1/16, .5-1/16, 1/16, .4999+1/16, .5}
box_xmy = {-.5, -.5+1/16, -1/16, -.5+1/16, .4999+1/16, 1/16} box_xmy = {-.5, -.5+1/16, -1/16, -.5+1/16, .4999+1/16, 1/16}
box_zmy = {-1/16, -.5+1/16, -.5, 1/16, .4999+1/16, -.5+1/16} box_zmy = {-1/16, -.5+1/16, -.5, 1/16, .4999+1/16, -.5+1/16}
-- Registering the wires
for xp=0, 1 do for xp=0, 1 do
for zp=0, 1 do for zp=0, 1 do
for xm=0, 1 do for xm=0, 1 do
@ -191,6 +157,9 @@ end
end end
end end
-- Updating the wires:
-- Place the right connection wire
local update_on_place_dig = function (pos, node) local update_on_place_dig = function (pos, node)
if minetest.registered_nodes[node.name] if minetest.registered_nodes[node.name]
and minetest.registered_nodes[node.name].mesecons then and minetest.registered_nodes[node.name].mesecons then
@ -237,37 +206,20 @@ function mesecon:update_autoconnect(pos, secondcall, replace_old)
nodename = minetest.env:get_node(pos).name nodename = minetest.env:get_node(pos).name
if string.find(nodename, "mesecons:wire_") == nil and not replace_old then return nil end if string.find(nodename, "mesecons:wire_") == nil and not replace_old then return nil end
if mesecon:rules_link_bothdir(pos, xppos) then xp = 1 else xp = 0 end if mesecon:rules_link_anydir(pos, xppos) then xp = 1 else xp = 0 end
if mesecon:rules_link_bothdir(pos, xmpos) then xm = 1 else xm = 0 end if mesecon:rules_link_anydir(pos, xmpos) then xm = 1 else xm = 0 end
if mesecon:rules_link_bothdir(pos, zppos) then zp = 1 else zp = 0 end if mesecon:rules_link_anydir(pos, zppos) then zp = 1 else zp = 0 end
if mesecon:rules_link_bothdir(pos, zmpos) then zm = 1 else zm = 0 end if mesecon:rules_link_anydir(pos, zmpos) then zm = 1 else zm = 0 end
if mesecon:rules_link_bothdir(pos, xpympos) then xp = 1 end if mesecon:rules_link_anydir(pos, xpympos) then xp = 1 end
if mesecon:rules_link_bothdir(pos, xmympos) then xm = 1 end if mesecon:rules_link_anydir(pos, xmympos) then xm = 1 end
if mesecon:rules_link_bothdir(pos, zpympos) then zp = 1 end if mesecon:rules_link_anydir(pos, zpympos) then zp = 1 end
if mesecon:rules_link_bothdir(pos, zmympos) then zm = 1 end if mesecon:rules_link_anydir(pos, zmympos) then zm = 1 end
if mesecon:rules_link(pos, xpypos) then xpy = 1 else xpy = 0 end if mesecon:rules_link_anydir(pos, xpypos) then xpy = 1 else xpy = 0 end
if mesecon:rules_link(pos, zpypos) then zpy = 1 else zpy = 0 end if mesecon:rules_link_anydir(pos, zpypos) then zpy = 1 else zpy = 0 end
if mesecon:rules_link(pos, xmypos) then xmy = 1 else xmy = 0 end if mesecon:rules_link_anydir(pos, xmypos) then xmy = 1 else xmy = 0 end
if mesecon:rules_link(pos, zmypos) then zmy = 1 else zmy = 0 end if mesecon:rules_link_anydir(pos, zmypos) then zmy = 1 else zmy = 0 end
-- Backward compatibility
if replace_old then
xp = (xp == 1 or (string.find(minetest.env:get_node(xppos ).name, "mesecons:mesecon_") ~= nil or
string.find(minetest.env:get_node(xpympos).name, "mesecons:mesecon_") ~= nil)) and 1 or 0
zp = (zp == 1 or (string.find(minetest.env:get_node(zppos ).name, "mesecons:mesecon_") ~= nil or
string.find(minetest.env:get_node(zpympos).name, "mesecons:mesecon_") ~= nil)) and 1 or 0
xm = (xm == 1 or (string.find(minetest.env:get_node(xmpos ).name, "mesecons:mesecon_") ~= nil or
string.find(minetest.env:get_node(xmympos).name, "mesecons:mesecon_") ~= nil)) and 1 or 0
zm = (zm == 1 or (string.find(minetest.env:get_node(zmpos ).name, "mesecons:mesecon_") ~= nil or
string.find(minetest.env:get_node(zmympos).name, "mesecons:mesecon_") ~= nil)) and 1 or 0
xpy = (xpy == 1 or string.find(minetest.env:get_node(xpypos).name, "mesecons:mesecon_") ~=nil) and 1 or 0
zpy = (zpy == 1 or string.find(minetest.env:get_node(zpypos).name, "mesecons:mesecon_") ~=nil) and 1 or 0
xmy = (xmy == 1 or string.find(minetest.env:get_node(xmypos).name, "mesecons:mesecon_") ~=nil) and 1 or 0
zmy = (zmy == 1 or string.find(minetest.env:get_node(zmypos).name, "mesecons:mesecon_") ~=nil) and 1 or 0
end
if xpy == 1 then xp = 1 end if xpy == 1 then xp = 1 end
if zpy == 1 then zp = 1 end if zpy == 1 then zp = 1 end
@ -318,13 +270,8 @@ else
end end
minetest.register_craft({
minetest.register_abm( type = "cooking",
{nodenames = {"mesecons:mesecon_off", "mesecons:mesecon_on"}, output = '"mesecons:wire_00000000_off" 16',
interval = 2, recipe = "default:mese_crystal",
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
mesecon:update_autoconnect(pos, false, true)
end,
}) })
end

View File

@ -11,7 +11,7 @@ minetest.register_alias("mesecons:wireless_receiver", "mesecons_wireless:wireles
minetest.register_alias("mesecons:wireless_transmitter", "mesecons_wireless:wireless_transmitter_off") minetest.register_alias("mesecons:wireless_transmitter", "mesecons_wireless:wireless_transmitter_off")
minetest.register_alias("mesecons:switch", "mesecons_switch:mesecon_switch_off") minetest.register_alias("mesecons:switch", "mesecons_switch:mesecon_switch_off")
minetest.register_alias("mesecons:button", "mesecons_button:button_off") minetest.register_alias("mesecons:button", "mesecons_button:button_off")
minetest.register_alias("mesecons:piston", "mesecons_pistons:piston_normal") minetest.register_alias("mesecons:piston", "mesecons_pistons:piston_normal_off")
minetest.register_alias("mesecons:blinky_plant", "mesecons_blinkyplant:blinky_plant_off") minetest.register_alias("mesecons:blinky_plant", "mesecons_blinkyplant:blinky_plant_off")
minetest.register_alias("mesecons:mesecon_torch", "mesecons_torch:mesecon_torch_on") minetest.register_alias("mesecons:mesecon_torch", "mesecons_torch:mesecon_torch_on")
minetest.register_alias("mesecons:torch", "mesecons_torch:mesecon_torch_on") minetest.register_alias("mesecons:torch", "mesecons_torch:mesecon_torch_on")
@ -30,3 +30,9 @@ minetest.register_alias("mesecons:solarpanel", "mesecons_solarpanel:solar_panel_
--Backwards compatibility --Backwards compatibility
minetest.register_alias("mesecons:mesecon_off", "mesecons:wire_00000000_off") minetest.register_alias("mesecons:mesecon_off", "mesecons:wire_00000000_off")
minetest.register_alias("mesecons_pistons:piston_sticky", "mesecons_pistons:piston_sticky_on")
minetest.register_alias("mesecons_pistons:piston_normal", "mesecons_pistons:piston_normal_on")
minetest.register_alias("mesecons_pistons:piston_up_normal", "mesecons_pistons:piston_up_normal_on")
minetest.register_alias("mesecons_pistons:piston_down_normal", "mesecons_pistons:piston_down_normal_on")
minetest.register_alias("mesecons_pistons:piston_up_sticky", "mesecons_pistons:piston_up_sticky_on")
minetest.register_alias("mesecons_pistons:piston_down_sticky", "mesecons_pistons:piston_down_sticky_on")

View File

@ -1,28 +1,16 @@
-- Function that get the input/output rules of the delayer -- Function that get the input/output rules of the delayer
local delayer_get_output_rules = function(node) local delayer_get_output_rules = function(node)
local rules = {} local rules = {{x = 0, y = 0, z = 1}}
if node.param2 == 0 then for i = 0, node.param2 do
table.insert(rules, {x = 1, y = 0, z = 0}) rules = mesecon:rotate_rules_left(rules)
elseif node.param2 == 2 then
table.insert(rules, {x =-1, y = 0, z = 0})
elseif node.param2 == 1 then
table.insert(rules, {x = 0, y = 0, z =-1})
elseif node.param2 == 3 then
table.insert(rules, {x = 0, y = 0, z = 1})
end end
return rules return rules
end end
local delayer_get_input_rules = function(node) local delayer_get_input_rules = function(node)
local rules = {} local rules = {{x = 0, y = 0, z = -1}}
if node.param2 == 0 then for i = 0, node.param2 do
table.insert(rules, {x =-1, y = 0, z = 0}) rules = mesecon:rotate_rules_left(rules)
elseif node.param2 == 2 then
table.insert(rules, {x = 1, y = 0, z = 0})
elseif node.param2 == 1 then
table.insert(rules, {x = 0, y = 0, z = 1})
elseif node.param2 == 3 then
table.insert(rules, {x = 0, y = 0, z =-1})
end end
return rules return rules
end end
@ -30,54 +18,30 @@ end
-- Functions that are called after the delay time -- Functions that are called after the delay time
local delayer_turnon = function(params) local delayer_turnon = function(params)
local rules = delayer_get_output_rules(params) local rules = delayer_get_output_rules(params.node)
mesecon:receptor_on(params.pos, rules) mesecon:receptor_on(params.pos, rules)
end end
local delayer_turnoff = function(params) local delayer_turnoff = function(params)
local rules = delayer_get_output_rules(params) local rules = delayer_get_output_rules(params.node)
mesecon:receptor_off(params.pos, rules) mesecon:receptor_off(params.pos, rules)
end end
local delayer_update = function(pos, node) local delayer_activate = function(pos, node)
if string.find(node.name, "mesecons_delayer:delayer_off")~=nil then local def = minetest.registered_nodes[node.name]
local time = 0 local time = def.delayer_time
if node.name=="mesecons_delayer:delayer_off_1" then mesecon:swap_node(pos, def.delayer_onstate)
mesecon:swap_node(pos, "mesecons_delayer:delayer_on_1") minetest.after(time, delayer_turnon , {pos = pos, node = node})
time=0.1
elseif node.name=="mesecons_delayer:delayer_off_2" then
mesecon:swap_node(pos, "mesecons_delayer:delayer_on_2")
time=0.3
elseif node.name=="mesecons_delayer:delayer_off_3" then
mesecon:swap_node(pos, "mesecons_delayer:delayer_on_3")
time=0.5
elseif node.name=="mesecons_delayer:delayer_off_4" then
mesecon:swap_node(pos, "mesecons_delayer:delayer_on_4")
time=1
end
minetest.after(time, delayer_turnon, {pos=pos, param2=node.param2})
end
if string.find(node.name, "mesecons_delayer:delayer_on")~=nil then
local time = 0
if node.name=="mesecons_delayer:delayer_on_1" then
mesecon:swap_node(pos, "mesecons_delayer:delayer_off_1")
time=0.1
elseif node.name=="mesecons_delayer:delayer_on_2" then
mesecon:swap_node(pos, "mesecons_delayer:delayer_off_2")
time=0.3
elseif node.name=="mesecons_delayer:delayer_on_3" then
mesecon:swap_node(pos, "mesecons_delayer:delayer_off_3")
time=0.5
elseif node.name=="mesecons_delayer:delayer_on_4" then
mesecon:swap_node(pos, "mesecons_delayer:delayer_off_4")
time=1
end
minetest.after(time, delayer_turnoff, {pos=pos, param2=node.param2})
end
end end
--Actually register the 2 (states) x 4 (delay times) delayers local delayer_deactivate = function(pos, node)
local def = minetest.registered_nodes[node.name]
local time = def.delayer_time
mesecon:swap_node(pos, def.delayer_offstate)
minetest.after(time, delayer_turnoff, {pos = pos, node = node})
end
-- Register the 2 (states) x 4 (delay times) delayers
for i = 1, 4 do for i = 1, 4 do
local groups = {} local groups = {}
@ -87,6 +51,12 @@ else
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1} groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1}
end end
local delaytime
if i == 1 then delaytime = 0.1
elseif i == 2 then delaytime = 0.3
elseif i == 3 then delaytime = 0.5
elseif i == 4 then delaytime = 1.0 end
boxes = {{ -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, -- the main slab boxes = {{ -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, -- the main slab
{ -2/16, -7/16, -4/16, 2/16, -26/64, -3/16 }, -- the jeweled "on" indicator { -2/16, -7/16, -4/16, 2/16, -26/64, -3/16 }, -- the jeweled "on" indicator
@ -138,6 +108,8 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
mesecon:swap_node(pos,"mesecons_delayer:delayer_off_1") mesecon:swap_node(pos,"mesecons_delayer:delayer_off_1")
end end
end, end,
delayer_time = delaytime,
delayer_onstate = "mesecons_delayer:delayer_on_"..tostring(i),
mesecons = { mesecons = {
receptor = receptor =
{ {
@ -147,7 +119,7 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
effector = effector =
{ {
rules = delayer_get_input_rules, rules = delayer_get_input_rules,
action_change = delayer_update action_on = delayer_activate
} }
} }
}) })
@ -190,6 +162,8 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), {
mesecon:swap_node(pos,"mesecons_delayer:delayer_on_1") mesecon:swap_node(pos,"mesecons_delayer:delayer_on_1")
end end
end, end,
delayer_time = delaytime,
delayer_offstate = "mesecons_delayer:delayer_off_"..tostring(i),
mesecons = { mesecons = {
receptor = receptor =
{ {
@ -199,8 +173,16 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), {
effector = effector =
{ {
rules = delayer_get_input_rules, rules = delayer_get_input_rules,
action_change = delayer_update action_off = delayer_deactivate
} }
} }
}) })
end end
minetest.register_craft({
output = "mesecons_delayer:delayer_off_1",
recipe = {
{"mesecons_torch:mesecon_torch_on", "group:mesecon_conductor_craftable", "mesecons_torch:mesecon_torch_on"},
{"default:cobble","default:cobble", "default:cobble"},
}
})

View File

@ -0,0 +1,83 @@
local corner_nodebox = {
type = "fixed",
fixed = {{ -16/32-0.001, -17/32, -3/32, 0, -13/32, 3/32 },
{ -3/32, -17/32, -16/32+0.001, 3/32, -13/32, 3/32}}
}
local corner_selectionbox = {
type = "fixed",
fixed = { -16/32-0.001, -18/32, -16/32, 5/32, -12/32, 5/32 },
}
local corner_get_rules = function (node)
local rules =
{{x = 1, y = 0, z = 0},
{x = 0, y = 0, z = -1}}
for i = 0, node.param2 do
rules = mesecon:rotate_rules_left(rules)
end
return rules
end
minetest.register_node("mesecons_extrawires:corner_on", {
drawtype = "nodebox",
tiles = {
"jeija_insulated_wire_curved_tb_on.png",
"jeija_insulated_wire_curved_tb_on.png^[transformR270",
"jeija_insulated_wire_sides_on.png",
"jeija_insulated_wire_ends_on.png",
"jeija_insulated_wire_sides_on.png",
"jeija_insulated_wire_ends_on.png"
},
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
sunlight_propagates = true,
selection_box = corner_selectionbox,
node_box = corner_nodebox,
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
drop = "mesecons_extrawires:insulated_off",
mesecons = {conductor =
{
state = mesecon.state.on,
rules = corner_get_rules,
offstate = "mesecons_extrawires:corner_off"
}}
})
minetest.register_node("mesecons_extrawires:corner_off", {
drawtype = "nodebox",
description = "Mesecon Corner",
tiles = {
"jeija_insulated_wire_curved_tb_off.png",
"jeija_insulated_wire_curved_tb_off.png^[transformR270",
"jeija_insulated_wire_sides_off.png",
"jeija_insulated_wire_ends_off.png",
"jeija_insulated_wire_sides_off.png",
"jeija_insulated_wire_ends_off.png"
},
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
sunlight_propagates = true,
selection_box = corner_selectionbox,
node_box = corner_nodebox,
groups = {dig_immediate = 3},
mesecons = {conductor =
{
state = mesecon.state.off,
rules = corner_get_rules,
onstate = "mesecons_extrawires:corner_on"
}}
})
minetest.register_craft({
output = '"mesecons_extrawires:corner_off" 3',
recipe = {
{"", "", ""},
{"mesecons_insulated:insulated_off", "mesecons_insulated:insulated_off", ""},
{"", "mesecons_insulated:insulated_off", ""},
}
})

View File

@ -6,7 +6,7 @@ end
minetest.register_node("mesecons_extrawires:crossing_on", { minetest.register_node("mesecons_extrawires:crossing_on", {
drawtype = "nodebox", drawtype = "nodebox",
tiles = {"jeija_insulated_wire_sides.png"}, tiles = {"jeija_insulated_wire_sides_on.png"},
paramtype = "light", paramtype = "light",
walkable = false, walkable = false,
stack_max = 99, stack_max = 99,

View File

@ -1,4 +1,5 @@
-- dofile(minetest.get_modpath("mesecons_extrawires").."/crossing.lua"); -- dofile(minetest.get_modpath("mesecons_extrawires").."/crossing.lua");
-- The crossing code is not active right now because it is hard to maintain -- The crossing code is not active right now because it is hard to maintain
dofile(minetest.get_modpath("mesecons_extrawires").."/tjunction.lua"); dofile(minetest.get_modpath("mesecons_extrawires").."/tjunction.lua");
dofile(minetest.get_modpath("mesecons_extrawires").."/corner.lua");
dofile(minetest.get_modpath("mesecons_extrawires").."/vertical.lua"); dofile(minetest.get_modpath("mesecons_extrawires").."/vertical.lua");

View File

@ -11,28 +11,25 @@ local tjunction_selectionbox = {
local tjunction_get_rules = function (node) local tjunction_get_rules = function (node)
local rules = local rules =
{{x = 1, y = 0, z = 0}, {{x = 0, y = 0, z = 1},
{x =-1, y = 0, z = 0}, {x = 1, y = 0, z = 0},
{x = 0, y = 0, z = -1}} {x = 0, y = 0, z = -1}}
if node.param2 == 1 then for i = 0, node.param2 do
rules = mesecon:rotate_rules_left(rules) rules = mesecon:rotate_rules_left(rules)
elseif node.param2 == 2 then
rules = mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules))
elseif node.param2 == 3 then
rules = mesecon:rotate_rules_right(rules)
end end
return rules return rules
end end
minetest.register_node("mesecons_extrawires:tjunction_on", { minetest.register_node("mesecons_extrawires:tjunction_on", {
drawtype = "nodebox", drawtype = "nodebox",
tiles = { tiles = {
"jeija_insulated_wire_sides.png", "jeija_insulated_wire_tjunction_tb_on.png",
"jeija_insulated_wire_sides.png", "jeija_insulated_wire_tjunction_tb_on.png^[transformR180",
"jeija_insulated_wire_ends_on.png", "jeija_insulated_wire_ends_on.png",
"jeija_insulated_wire_ends_on.png", "jeija_insulated_wire_ends_on.png",
"jeija_insulated_wire_sides.png", "jeija_insulated_wire_sides_on.png",
"jeija_insulated_wire_ends_on.png" "jeija_insulated_wire_ends_on.png"
}, },
paramtype = "light", paramtype = "light",
@ -42,7 +39,7 @@ minetest.register_node("mesecons_extrawires:tjunction_on", {
selection_box = tjunction_selectionbox, selection_box = tjunction_selectionbox,
node_box = tjunction_nodebox, node_box = tjunction_nodebox,
groups = {dig_immediate = 3, mesecon_conductor_craftable=1, not_in_creative_inventory = 1}, groups = {dig_immediate = 3, mesecon_conductor_craftable=1, not_in_creative_inventory = 1},
drop = "mesecons_insulated:insulated_off", drop = "mesecons_extrawires:tjunction_off",
mesecons = {conductor = mesecons = {conductor =
{ {
state = mesecon.state.on, state = mesecon.state.on,
@ -55,11 +52,11 @@ minetest.register_node("mesecons_extrawires:tjunction_off", {
drawtype = "nodebox", drawtype = "nodebox",
description = "T-junction", description = "T-junction",
tiles = { tiles = {
"jeija_insulated_wire_sides.png", "jeija_insulated_wire_tjunction_tb_off.png",
"jeija_insulated_wire_sides.png", "jeija_insulated_wire_tjunction_tb_off.png^[transformR180",
"jeija_insulated_wire_ends_off.png", "jeija_insulated_wire_ends_off.png",
"jeija_insulated_wire_ends_off.png", "jeija_insulated_wire_ends_off.png",
"jeija_insulated_wire_sides.png", "jeija_insulated_wire_sides_off.png",
"jeija_insulated_wire_ends_off.png" "jeija_insulated_wire_ends_off.png"
}, },
paramtype = "light", paramtype = "light",

View File

@ -77,7 +77,7 @@ minetest.register_node("mesecons_extrawires:vertical_on", {
walkable = false, walkable = false,
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
groups = {dig_immediate = 3}, groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = vbox, selection_box = vbox,
node_box = vbox, node_box = vbox,
is_vertical_conductor = true, is_vertical_conductor = true,
@ -117,11 +117,11 @@ minetest.register_node("mesecons_extrawires:vertical_off", {
minetest.register_node("mesecons_extrawires:vertical_top_on", { minetest.register_node("mesecons_extrawires:vertical_top_on", {
description = "Vertical mesecon", description = "Vertical mesecon",
drawtype = "nodebox", drawtype = "nodebox",
tiles = {"wires_vertical_on.png"}, tiles = {"wires_full_on.png"},
walkable = false, walkable = false,
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
groups = {dig_immediate = 3}, groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = tbox, selection_box = tbox,
node_box = tbox, node_box = tbox,
is_vertical_conductor = true, is_vertical_conductor = true,
@ -139,11 +139,11 @@ minetest.register_node("mesecons_extrawires:vertical_top_on", {
minetest.register_node("mesecons_extrawires:vertical_top_off", { minetest.register_node("mesecons_extrawires:vertical_top_off", {
description = "Vertical mesecon", description = "Vertical mesecon",
drawtype = "nodebox", drawtype = "nodebox",
tiles = {"wires_vertical_off.png"}, tiles = {"wires_full_off.png"},
walkable = false, walkable = false,
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
groups = {dig_immediate = 3}, groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = tbox, selection_box = tbox,
node_box = tbox, node_box = tbox,
is_vertical_conductor = true, is_vertical_conductor = true,
@ -162,12 +162,12 @@ minetest.register_node("mesecons_extrawires:vertical_top_off", {
minetest.register_node("mesecons_extrawires:vertical_bottom_on", { minetest.register_node("mesecons_extrawires:vertical_bottom_on", {
description = "Vertical mesecon", description = "Vertical mesecon",
drawtype = "nodebox", drawtype = "nodebox",
tiles = {"wires_vertical_on.png"}, tiles = {"wires_full_on.png"},
walkable = false, walkable = false,
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
vertical_conductor_state = "on", vertical_conductor_state = "on",
groups = {dig_immediate = 3}, groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = bbox, selection_box = bbox,
node_box = bbox, node_box = bbox,
mesecons = {conductor = { mesecons = {conductor = {
@ -183,11 +183,11 @@ minetest.register_node("mesecons_extrawires:vertical_bottom_on", {
minetest.register_node("mesecons_extrawires:vertical_bottom_off", { minetest.register_node("mesecons_extrawires:vertical_bottom_off", {
description = "Vertical mesecon", description = "Vertical mesecon",
drawtype = "nodebox", drawtype = "nodebox",
tiles = {"wires_vertical_off.png"}, tiles = {"wires_full_off.png"},
walkable = false, walkable = false,
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
groups = {dig_immediate = 3}, groups = {dig_immediate = 3, not_in_creative_inventory = 1},
selection_box = bbox, selection_box = bbox,
node_box = bbox, node_box = bbox,
is_vertical_conductor = true, is_vertical_conductor = true,

View File

@ -9,14 +9,14 @@ end
minetest.register_node("mesecons_insulated:insulated_on", { minetest.register_node("mesecons_insulated:insulated_on", {
drawtype = "nodebox", drawtype = "nodebox",
description = "insulated mesecons", description = "Insulated Mesecon",
tiles = { tiles = {
"jeija_insulated_wire_sides.png", "jeija_insulated_wire_sides_on.png",
"jeija_insulated_wire_sides.png", "jeija_insulated_wire_sides_on.png",
"jeija_insulated_wire_ends_on.png", "jeija_insulated_wire_ends_on.png",
"jeija_insulated_wire_ends_on.png", "jeija_insulated_wire_ends_on.png",
"jeija_insulated_wire_sides.png", "jeija_insulated_wire_sides_on.png",
"jeija_insulated_wire_sides.png" "jeija_insulated_wire_sides_on.png"
}, },
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
@ -43,12 +43,12 @@ minetest.register_node("mesecons_insulated:insulated_off", {
drawtype = "nodebox", drawtype = "nodebox",
description = "insulated mesecons", description = "insulated mesecons",
tiles = { tiles = {
"jeija_insulated_wire_sides.png", "jeija_insulated_wire_sides_off.png",
"jeija_insulated_wire_sides.png", "jeija_insulated_wire_sides_off.png",
"jeija_insulated_wire_ends_off.png", "jeija_insulated_wire_ends_off.png",
"jeija_insulated_wire_ends_off.png", "jeija_insulated_wire_ends_off.png",
"jeija_insulated_wire_sides.png", "jeija_insulated_wire_sides_off.png",
"jeija_insulated_wire_sides.png" "jeija_insulated_wire_sides_off.png"
}, },
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",

View File

@ -2,6 +2,13 @@
-- A lamp is "is an electrical device used to create artificial light" (wikipedia) -- A lamp is "is an electrical device used to create artificial light" (wikipedia)
-- guess what? -- guess what?
mesecon_lamp_box = {
type = "wallmounted",
wall_top = {-0.3125,0.375,-0.3125,0.3125,0.5,0.3125},
wall_bottom = {-0.3125,-0.5,-0.3125,0.3125,-0.375,0.3125},
wall_side = {-0.375,-0.3125,-0.3125,-0.5,0.3125,0.3125},
}
minetest.register_node("mesecons_lamp:lamp_on", { minetest.register_node("mesecons_lamp:lamp_on", {
drawtype = "nodebox", drawtype = "nodebox",
tiles = {"jeija_meselamp_on.png"}, tiles = {"jeija_meselamp_on.png"},
@ -11,18 +18,8 @@ minetest.register_node("mesecons_lamp:lamp_on", {
sunlight_propagates = true, sunlight_propagates = true,
walkable = true, walkable = true,
light_source = LIGHT_MAX, light_source = LIGHT_MAX,
node_box = { node_box = mesecon_lamp_box,
type = "wallmounted", selection_box = mesecon_lamp_box,
wall_top = {-0.3125,0.375,-0.3125,0.3125,0.5,0.3125},
wall_bottom = {-0.3125,-0.5,-0.3125,0.3125,-0.375,0.3125},
wall_side = {-0.375,-0.3125,-0.3125,-0.5,0.3125,0.3125},
},
selection_box = {
type = "wallmounted",
wall_top = {-0.3125,0.375,-0.3125,0.3125,0.5,0.3125},
wall_bottom = {-0.3125,-0.5,-0.3125,0.3125,-0.375,0.3125},
wall_side = {-0.375,-0.3125,-0.3125,-0.5,0.3125,0.3125},
},
groups = {dig_immediate=3,not_in_creative_inventory=1, mesecon_effector_on = 1}, groups = {dig_immediate=3,not_in_creative_inventory=1, mesecon_effector_on = 1},
drop='"mesecons_lamp:lamp_off" 1', drop='"mesecons_lamp:lamp_off" 1',
mesecons = {effector = { mesecons = {effector = {
@ -41,18 +38,8 @@ minetest.register_node("mesecons_lamp:lamp_off", {
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
sunlight_propagates = true, sunlight_propagates = true,
walkable = true, walkable = true,
node_box = { node_box = mesecon_lamp_box,
type = "wallmounted", selection_box = mesecon_lamp_box,
wall_top = {-0.3125,0.375,-0.3125,0.3125,0.5,0.3125},
wall_bottom = {-0.3125,-0.5,-0.3125,0.3125,-0.375,0.3125},
wall_side = {-0.375,-0.3125,-0.3125,-0.5,0.3125,0.3125},
},
selection_box = {
type = "wallmounted",
wall_top = {-0.3125,0.375,-0.3125,0.3125,0.5,0.3125},
wall_bottom = {-0.3125,-0.5,-0.3125,0.3125,-0.375,0.3125},
wall_side = {-0.375,-0.3125,-0.3125,-0.5,0.3125,0.3125},
},
groups = {dig_immediate=3, mesecon_receptor_off = 1, mesecon_effector_off = 1}, groups = {dig_immediate=3, mesecon_receptor_off = 1, mesecon_effector_off = 1},
description="Meselamp", description="Meselamp",
mesecons = {effector = { mesecons = {effector = {

View File

@ -30,16 +30,16 @@ if (c == 1) then table.insert(rules, {x = 1, y = 0, z = 0}) end
if (d == 1) then table.insert(rules, {x = 0, y = 0, z = -1}) end if (d == 1) then table.insert(rules, {x = 0, y = 0, z = -1}) end
local input_rules={} local input_rules={}
if (a == 0) then table.insert(input_rules, {x = -1, y = 0, z = 0}) end if (a == 0) then table.insert(input_rules, {x = -1, y = 0, z = 0, name = "A"}) end
if (b == 0) then table.insert(input_rules, {x = 0, y = 0, z = 1}) end if (b == 0) then table.insert(input_rules, {x = 0, y = 0, z = 1, name = "B"}) end
if (c == 0) then table.insert(input_rules, {x = 1, y = 0, z = 0}) end if (c == 0) then table.insert(input_rules, {x = 1, y = 0, z = 0, name = "C"}) end
if (d == 0) then table.insert(input_rules, {x = 0, y = 0, z = -1}) end if (d == 0) then table.insert(input_rules, {x = 0, y = 0, z = -1, name = "D"}) end
mesecon:add_rules(nodename, rules) mesecon:add_rules(nodename, rules)
local mesecons = {effector = local mesecons = {effector =
{ {
rules = input_rules, rules = input_rules,
action_change = function (pos, node) action_change = function (pos, node, rulename)
update_yc(pos) update_yc(pos)
end end
}} }}

View File

@ -70,7 +70,7 @@ minetest.register_node("mesecons_movestones:movestone", {
repeat -- Check if it collides with a stopper repeat -- Check if it collides with a stopper
collpos = mesecon:addPosRule(collpos, direction) collpos = mesecon:addPosRule(collpos, direction)
checknode=minetest.env:get_node(collpos) checknode=minetest.env:get_node(collpos)
if mesecon:is_mvps_stopper(checknode.name) then if mesecon:is_mvps_stopper(checknode.name, direction) then
return return
end end
until checknode.name=="air" until checknode.name=="air"
@ -97,7 +97,7 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
on_step = function(self, dtime) on_step = function(self, dtime)
local pos = self.object:getpos() local pos = self.object:getpos()
local direction=mesecon:get_movestone_direction(pos) local direction = mesecon:get_movestone_direction(pos)
if not direction then if not direction then
minetest.env:add_node(pos, {name="mesecons_movestones:movestone"}) minetest.env:add_node(pos, {name="mesecons_movestones:movestone"})
@ -105,9 +105,9 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
return return
end end
self.object:setvelocity({x=direction.x*3, y=direction.y*3, z=direction.z*3}) self.object:setvelocity({x=direction.x*2, y=direction.y*2, z=direction.z*2})
mesecon:mvps_push(pos, direction) mesecon:mvps_push(pos, direction, 100)
end, end,
}) })
@ -140,7 +140,7 @@ minetest.register_node("mesecons_movestones:sticky_movestone", {
repeat -- Check if it collides with a stopper repeat -- Check if it collides with a stopper
collpos = mesecon:addPosRule(collpos, direction) collpos = mesecon:addPosRule(collpos, direction)
checknode=minetest.env:get_node(collpos) checknode=minetest.env:get_node(collpos)
if mesecon:is_mvps_stopper(checknode.name) then if mesecon:is_mvps_stopper(checknode.name, direction) then
return return
end end
until checknode.name=="air" until checknode.name=="air"
@ -149,7 +149,7 @@ minetest.register_node("mesecons_movestones:sticky_movestone", {
repeat -- Check if it collides with a stopper (pull direction) repeat -- Check if it collides with a stopper (pull direction)
collpos={x=collpos.x-direction.x, y=collpos.y-direction.y, z=collpos.z-direction.z} collpos={x=collpos.x-direction.x, y=collpos.y-direction.y, z=collpos.z-direction.z}
checknode=minetest.env:get_node(collpos) checknode=minetest.env:get_node(collpos)
if mesecon:is_mvps_stopper(checknode.name) then if mesecon:is_mvps_stopper(checknode.name, direction) then
return return
end end
until checknode.name=="air" until checknode.name=="air"
@ -192,9 +192,9 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
return return
end end
self.object:setvelocity({x=direction.x*3, y=direction.y*3, z=direction.z*3}) self.object:setvelocity({x=direction.x*2, y=direction.y*2, z=direction.z*2})
mesecon:mvps_push(pos, direction) mesecon:mvps_push(pos, direction, 100)
--STICKY --STICKY
mesecon:mvps_pull_all(pos, direction) mesecon:mvps_pull_all(pos, direction)

View File

@ -2,42 +2,99 @@
mesecon.mvps_stoppers={} mesecon.mvps_stoppers={}
function mesecon:is_mvps_stopper(nodename) function mesecon:is_mvps_stopper(node, pushdir, stack, stackid)
local i=1 local get_stopper = mesecon.mvps_stoppers[node.name]
repeat if type (get_stopper) == "function" then
i=i+1 get_stopper = get_stopper(node, pushdir, stack, stackid)
if mesecon.mvps_stoppers[i]==nodename then return true end end
until mesecon.mvps_stoppers[i]==nil return get_stopper
return false
end end
function mesecon:register_mvps_stopper(nodename) function mesecon:register_mvps_stopper(nodename, get_stopper)
local i=1 if get_stopper == nil then
repeat get_stopper = true
i=i+1 end
if mesecon.mvps_stoppers[i]==nil then break end mesecon.mvps_stoppers[nodename] = get_stopper
until false
mesecon.mvps_stoppers[i]=nodename
end end
function mesecon:mvps_push(pos, direction) -- pos: pos of mvps; direction: direction of push function mesecon:mvps_process_stack(stack)
pos.x=pos.x+direction.x -- update mesecons for placed nodes ( has to be done after all nodes have been added )
pos.y=pos.y+direction.y for _, n in ipairs(stack) do
pos.z=pos.z+direction.z mesecon.on_placenode(n.pos, minetest.env:get_node(n.pos))
mesecon:update_autoconnect(n.pos)
end
end
local lpos = {x=pos.x, y=pos.y, z=pos.z} function mesecon:mvps_push(pos, dir, maximum) -- pos: pos of mvps; dir: direction of push; maximum: maximum nodes to be pushed
local lnode = minetest.env:get_node(lpos) np = {x = pos.x, y = pos.y, z = pos.z}
local newnode
minetest.env:remove_node(lpos) -- determine the number of nodes to be pushed
while not(lnode.name == "ignore" or lnode.name == "air" or not(minetest.registered_nodes[lnode.name].liquidtype == "none")) do local nodes = {}
lpos.x=lpos.x+direction.x while true do
lpos.y=lpos.y+direction.y nn = minetest.env:get_node_or_nil(np)
lpos.z=lpos.z+direction.z if not nn or #nodes > maximum then
newnode = lnode -- don't push at all, something is in the way (unloaded map or too many nodes)
lnode = minetest.env:get_node(lpos) return
minetest.env:add_node(lpos, newnode)
nodeupdate(lpos)
end end
if nn.name == "air"
or minetest.registered_nodes[nn.name].liquidtype ~= "none" then --is liquid
break
end
table.insert (nodes, {node = nn, pos = np})
np = mesecon:addPosRule(np, dir)
end
-- determine if one of the nodes blocks the push
for id, n in ipairs(nodes) do
if mesecon:is_mvps_stopper(n.node, dir, nodes, id) then
return
end
end
-- remove all nodes
for _, n in ipairs(nodes) do
minetest.env:remove_node(n.pos)
nodeupdate(n.pos)
end
-- update mesecons for removed nodes ( has to be done after all nodes have been removed )
for _, n in ipairs(nodes) do
mesecon.on_dignode(n.pos, n.node)
mesecon:update_autoconnect(n.pos)
end
-- add nodes
for _, n in ipairs(nodes) do
np = mesecon:addPosRule(n.pos, dir)
minetest.env:add_node(np, n.node)
nodeupdate(np)
end
for i in ipairs(nodes) do
nodes[i].pos = mesecon:addPosRule(nodes[i].pos, dir)
end
return true, nodes
end
function mesecon:mvps_pull_single(pos, dir) -- pos: pos of mvps; direction: direction of pull (matches push direction for sticky pistons)
np = mesecon:addPosRule(pos, dir)
nn = minetest.env:get_node(np)
if minetest.registered_nodes[nn.name].liquidtype == "none"
and not mesecon:is_mvps_stopper(nn, {x = -dir.x, y = -dir.y, z = -dir.z}, {{pos = np, node = nn}}, 1) then
minetest.env:remove_node(np)
minetest.env:add_node(pos, nn)
nodeupdate(np)
nodeupdate(pos)
mesecon.on_dignode(np, nn)
mesecon:update_autoconnect(np)
end
return {{pos = np, node = {param2 = 0, name = "air"}}, {pos = pos, node = nn}}
end end
function mesecon:mvps_pull_all(pos, direction) -- pos: pos of mvps; direction: direction of pull function mesecon:mvps_pull_all(pos, direction) -- pos: pos of mvps; direction: direction of pull

View File

@ -1,3 +1,2 @@
mesecons mesecons
mesecons_materials
mesecons_mvps mesecons_mvps

File diff suppressed because it is too large Load Diff

View File

@ -1,159 +1,113 @@
-- PRESSURE PLATE WOOD local pp_box_off = {
type = "fixed",
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
}
minetest.register_node("mesecons_pressureplates:pressure_plate_wood_off", { local pp_box_on = {
drawtype = "nodebox", type = "fixed",
tiles = {"jeija_pressure_plate_wood_off.png"}, fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
inventory_image = "jeija_pressure_plate_wood_off.png", }
wield_image = "jeija_pressure_plate_wood_off.png",
paramtype = "light",
is_ground_content = true,
walkable = true,
selection_box = {
type = "fixed",
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
},
node_box = {
type = "fixed",
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3, mesecon = 2},
description="Wood Pressure Plate",
on_timer = function(pos, elapsed) pp_on_timer = function (pos, elapsed)
local objs = minetest.env:get_objects_inside_radius(pos, 1) local node = minetest.env:get_node(pos)
local ppspec = minetest.registered_nodes[node.name].pressureplate
-- This is a workaround for a strange bug that occurs when the server is started
-- For some reason the first time on_timer is called, the pos is wrong
if not ppspec then return end
local objs = minetest.env:get_objects_inside_radius(pos, 1)
if objs[1] == nil and node.name == ppspec.onstate then
minetest.env:add_node(pos, {name = ppspec.offstate})
mesecon:receptor_off(pos)
-- force deactivation of mesecon two blocks below (hacky)
mesecon:turnoff(mesecon:addPosRule(pos, {x = 0, y = -2, z = 0}))
else
for k, obj in pairs(objs) do for k, obj in pairs(objs) do
local objpos=obj:getpos() local objpos = obj:getpos()
if objpos.y>pos.y-1 and objpos.y<pos.y then if objpos.y > pos.y-1 and objpos.y < pos.y then
minetest.env:add_node(pos, {name="mesecons_pressureplates:pressure_plate_wood_on"}) minetest.env:add_node(pos, {name=ppspec.onstate})
mesecon:receptor_on(pos) mesecon:receptor_on(pos)
-- force activation of mesecon two blocks below (hacky)
mesecon:turnon(mesecon:addPosRule(pos, {x = 0, y = -2, z = 0}))
end end
end end
return true end
end, return true
end
on_construct = function(pos) -- Register a Pressure Plate
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL) -- offstate: name of the pressure plate when inactive
end, -- onstate: name of the pressure plate when active
}) -- description: description displayed in the player's inventory
-- tiles_off: textures of the pressure plate when inactive
-- tiles_on: textures of the pressure plate when active
-- image: inventory and wield image of the pressure plate
-- recipe: crafting recipe of the pressure plate
minetest.register_node("mesecons_pressureplates:pressure_plate_wood_on", { function mesecon:register_pressure_plate(offstate, onstate, description, texture_off, texture_on, recipe)
drawtype = "nodebox", local ppspec = {
tiles = {"jeija_pressure_plate_wood_on.png"}, offstate = offstate,
paramtype = "light", onstate = onstate
is_ground_content = true,
walkable = true,
selection_box = {
type = "fixed",
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
},
node_box = {
type = "fixed",
fixed = { -7/16, -8/16, -7/16, 7/16, -31/64, 7/16 },
},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1, mesecon = 2},
drop='"mesecons_pressureplates:pressure_plate_wood_off" 1',
on_timer = function(pos, elapsed)
local objs = minetest.env:get_objects_inside_radius(pos, 1)
if objs[1]==nil then
minetest.env:add_node(pos, {name="mesecons_pressureplates:pressure_plate_wood_off"})
mesecon:receptor_off(pos)
end
return true
end,
on_construct = function(pos)
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
end,
})
minetest.register_craft({
output = '"mesecons_pressureplates:pressure_plate_wood_off" 1',
recipe = {
{'"default:wood"', '"default:wood"'},
} }
})
-- PRESSURE PLATE STONE minetest.register_node(offstate, {
drawtype = "nodebox",
tiles = {texture_off},
inventory_image = texture_off,
wield_image = image,
paramtype = "light",
selection_box = pp_box_off,
node_box = pp_box_off,
groups = {snappy = 2, oddly_breakable_by_hand = 3},
description = description,
pressureplate = ppspec,
on_timer = pp_on_timer,
mesecons = {receptor = {
state = mesecon.state.off
}},
on_construct = function(pos)
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
end,
})
minetest.register_node("mesecons_pressureplates:pressure_plate_stone_off", { minetest.register_node(onstate, {
drawtype = "nodebox", drawtype = "nodebox",
tiles = {"jeija_pressure_plate_stone_off.png"}, tiles = {texture_on},
inventory_image = "jeija_pressure_plate_stone_off.png", paramtype = "light",
wield_image = "jeija_pressure_plate_stone_off.png", selection_box = pp_box_on,
paramtype = "light", node_box = pp_box_on,
is_ground_content = true, groups = {snappy = 2, oddly_breakable_by_hand = 3, not_in_creative_inventory = 1},
walkable = true, drop = offstate,
selection_box = { pressureplate = ppspec,
type = "fixed", on_timer = pp_on_timer,
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 }, mesecons = {receptor = {
}, state = mesecon.state.on
node_box = { }},
type = "fixed", on_construct = function(pos)
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 }, minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
}, end,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3}, })
description="Stone Pressure Plate",
on_timer = function(pos, elapsed) minetest.register_craft({
local objs = minetest.env:get_objects_inside_radius(pos, 1) output = offstate,
for k, obj in pairs(objs) do recipe = recipe,
local objpos=obj:getpos() })
if objpos.y>pos.y-1 and objpos.y<pos.y then end
minetest.env:add_node(pos, {name="mesecons_pressureplates:pressure_plate_stone_on"})
mesecon:receptor_on(pos)
end
end
return true
end,
on_construct = function(pos) mesecon:register_pressure_plate(
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL) "mesecons_pressureplates:pressure_plate_wood_off",
end, "mesecons_pressureplates:pressure_plate_wood_on",
"Wooden Pressure Plate",
"jeija_pressure_plate_wood_off.png",
"jeija_pressure_plate_wood_on.png",
{{"default:wood", "default:wood"}})
mesecons = {receptor = { mesecon:register_pressure_plate(
state = mesecon.state.off "mesecons_pressureplates:pressure_plate_stone_off",
}} "mesecons_pressureplates:pressure_plate_stone_on",
}) "Stone Pressure Plate",
"jeija_pressure_plate_stone_off.png",
minetest.register_node("mesecons_pressureplates:pressure_plate_stone_on", { "jeija_pressure_plate_stone_on.png",
drawtype = "nodebox", {{"default:cobble", "default:cobble"}})
tiles = {"jeija_pressure_plate_stone_on.png"},
paramtype = "light",
is_ground_content = true,
walkable = true,
selection_box = {
type = "fixed",
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
},
node_box = {
type = "fixed",
fixed = { -7/16, -8/16, -7/16, 7/16, -31/64, 7/16 },
},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1},
drop='"mesecons_pressureplates:pressure_plate_stone_off" 1',
on_timer = function(pos, elapsed)
local objs = minetest.env:get_objects_inside_radius(pos, 1)
if objs[1]==nil then
minetest.env:add_node(pos, {name="mesecons_pressureplates:pressure_plate_stone_off"})
mesecon:receptor_off(pos)
end
return true
end,
on_construct = function(pos)
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
end,
mesecons = {receptor = {
state = mesecon.state.off
}}
})
minetest.register_craft({
output = '"mesecons_pressureplates:pressure_plate_stone_off" 1',
recipe = {
{'"default:cobble"', '"default:cobble"'},
}
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 172 B

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 172 B

After

Width:  |  Height:  |  Size: 166 B

View File

Before

Width:  |  Height:  |  Size: 200 B

After

Width:  |  Height:  |  Size: 200 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 793 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 782 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 793 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 782 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 778 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 763 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 791 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 790 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 759 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 762 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 759 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 790 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 802 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 787 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 786 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 790 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 465 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 464 B

View File

@ -1,53 +1,54 @@
--MESECON TORCHES --MESECON TORCHES
local torch_get_rules = function(node) local rotate_torch_rules = function (rules, param2)
local rules = { if param2 == 5 then
{x=1, y=0, z=0}, return mesecon:rotate_rules_right(rules)
{x=0, y=0, z=1}, elseif param2 == 2 then
{x=0, y=0, z=-1}, return mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules)) --180 degrees
{x=0, y=1, z=0}, elseif param2 == 4 then
{x=0, y=-1, z=0}} return mesecon:rotate_rules_left(rules)
if node.param2 == 5 then elseif param2 == 1 then
rules=mesecon:rotate_rules_right(rules) return mesecon:rotate_rules_down(rules)
elseif node.param2 == 2 then elseif param2 == 0 then
rules=mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules)) --180 degrees return mesecon:rotate_rules_up(rules)
elseif node.param2 == 4 then else
rules=mesecon:rotate_rules_left(rules) return rules
elseif node.param2 == 1 then
rules=mesecon:rotate_rules_down(rules)
elseif node.param2 == 0 then
rules=mesecon:rotate_rules_up(rules)
end end
return rules end
local torch_get_output_rules = function(node)
local rules = {
{x = 1, y = 0, z = 0},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z =-1},
{x = 0, y = 1, z = 0},
{x = 0, y =-1, z = 0}}
return rotate_torch_rules(rules, node.param2)
end end
local torch_get_input_rules = function(node) local torch_get_input_rules = function(node)
local rules = {x=0, y=0, z=0} local rules = {{x = -2, y = 0, z = 0},
{x = -1, y = 1, z = 0}}
if node.param2 == 4 then return rotate_torch_rules(rules, node.param2)
rules.z = -2
elseif node.param2 == 2 then
rules.x = -2
elseif node.param2 == 5 then
rules.z = 2
elseif node.param2 == 3 then
rules.x = 2
elseif node.param2 == 1 then
rules.y = 2
elseif node.param2 == 0 then
rules.y = -2
end
return rules
end end
minetest.register_craft({ minetest.register_craft({
output = '"mesecons_torch:mesecon_torch_on" 4', output = '"mesecons_torch:mesecon_torch_on" 4',
recipe = { recipe = {
{"group:mesecon_conductor_craftable"}, {"group:mesecon_conductor_craftable"},
{"default:stick"}, {"default:stick"},}
}
}) })
local torch_selectionbox =
{
type = "wallmounted",
wall_top = {-0.1, 0.5-0.6, -0.1, 0.1, 0.5, 0.1},
wall_bottom = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
wall_side = {-0.5, -0.1, -0.1, -0.5+0.6, 0.1, 0.1},
}
minetest.register_node("mesecons_torch:mesecon_torch_off", { minetest.register_node("mesecons_torch:mesecon_torch_off", {
drawtype = "torchlike", drawtype = "torchlike",
tiles = {"jeija_torches_off.png", "jeija_torches_off_ceiling.png", "jeija_torches_off_side.png"}, tiles = {"jeija_torches_off.png", "jeija_torches_off_ceiling.png", "jeija_torches_off_side.png"},
@ -55,19 +56,12 @@ minetest.register_node("mesecons_torch:mesecon_torch_off", {
paramtype = "light", paramtype = "light",
walkable = false, walkable = false,
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
selection_box = { selection_box = torch_selectionbox,
type = "wallmounted", groups = {dig_immediate = 3, not_in_creative_inventory = 1},
wall_top = {-0.1, 0.5-0.6, -0.1, 0.1, 0.5, 0.1}, drop = "mesecons_torch:mesecon_torch_on",
wall_bottom = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
wall_side = {-0.5, -0.1, -0.1, -0.5+0.6, 0.1, 0.1},
},
legacy_wallmounted = true,
groups = {dig_immediate=3,not_in_creative_inventory=1},
drop = '"mesecons_torch:mesecon_torch_on" 1',
description="Mesecon Torch",
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.off, state = mesecon.state.off,
rules = torch_get_rules rules = torch_get_output_rules
}} }}
}) })
@ -80,43 +74,39 @@ minetest.register_node("mesecons_torch:mesecon_torch_on", {
sunlight_propagates = true, sunlight_propagates = true,
walkable = false, walkable = false,
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
selection_box = { selection_box = torch_selectionbox,
type = "wallmounted",
wall_top = {-0.1, 0.5-0.6, -0.1, 0.1, 0.5, 0.1},
wall_bottom = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
wall_side = {-0.5, -0.1, -0.1, -0.5+0.6, 0.1, 0.1},
},
legacy_wallmounted = true,
groups = {dig_immediate=3}, groups = {dig_immediate=3},
light_source = LIGHT_MAX-5, light_source = LIGHT_MAX-5,
description="Mesecon Torch", description="Mesecon Torch",
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.on, state = mesecon.state.on,
rules = torch_get_rules rules = torch_get_output_rules
}} }},
}) })
minetest.register_abm({ minetest.register_abm({
nodenames = {"mesecons_torch:mesecon_torch_off","mesecons_torch:mesecon_torch_on"}, nodenames = {"mesecons_torch:mesecon_torch_off","mesecons_torch:mesecon_torch_on"},
interval = 1, interval = 1,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node)
local node = minetest.env:get_node(pos) local is_powered = false
local pa = torch_get_input_rules(node) for _, rule in ipairs(torch_get_input_rules(node)) do
local src = mesecon:addPosRule(pos, rule)
if mesecon:is_power_on(src) then
is_powered = true
end
end
local postc = {x=pos.x-pa.x, y=pos.y-pa.y, z=pos.z-pa.z} if is_powered then
if mesecon:is_power_on(postc) then if node.name == "mesecons_torch:mesecon_torch_on" then
if node.name ~= "mesecons_torch:mesecon_torch_off" then mesecon:swap_node(pos, "mesecons_torch:mesecon_torch_off")
minetest.env:add_node(pos, {name="mesecons_torch:mesecon_torch_off",param2=node.param2}) mesecon:receptor_off(pos, torch_get_output_rules(node))
mesecon:receptor_off(pos, torch_get_rules(node)) end
end elseif node.name == "mesecons_torch:mesecon_torch_off" then
else mesecon:swap_node(pos, "mesecons_torch:mesecon_torch_on")
if node.name ~= "mesecons_torch:mesecon_torch_on" then mesecon:receptor_on(pos, torch_get_output_rules(node))
minetest.env:add_node(pos, {name="mesecons_torch:mesecon_torch_on",param2=node.param2}) end
mesecon:receptor_on(pos, torch_get_rules(node)) end
end
end
end
}) })
-- Param2 Table (Block Attached To) -- Param2 Table (Block Attached To)