Upload cleaned up mesecons to nextgen branch

This commit is contained in:
Jeija 2012-12-15 18:45:51 +01:00
parent c0d3bd2abb
commit 44dc1a128c
10 changed files with 309 additions and 444 deletions

@ -22,14 +22,14 @@
-- {
-- state = mesecon.state.on/off
-- rules = rules/get_rules
-- }
-- },
-- effector =
-- {
-- action_on = function
-- action_off = function
-- action_change = function
-- rules = rules/get_rules
-- }
-- },
-- conductor =
-- {
-- state = mesecon.state.on/off
@ -97,7 +97,7 @@ function mesecon:receptor_off(pos, rules)
x = pos.x + rule.x,
y = pos.y + rule.y,
z = pos.z + rule.z}
if mesecon:rules_link(pos, np, rules) and not mesecon:connected_to_pw_src(np) then
if mesecon:rules_link(pos, np, rules) and not mesecon:connected_to_receptor(np) then
mesecon:turnoff(np, pos)
end
end

@ -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
-- Nodes that can power mesecons
function mesecon:is_receptor_node(nodename)
-- RECEPTORS
-- mesecon:is_receptor(nodename) --> Returns true if nodename is a receptor
-- 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) --> Returns true whatever there is at pos. Calls itself for connected nodes (if pos is a conductor) --> recursive
-- mesecon:turnoff(pos) --> Turns off whatever there is at pos. Calls itself for connected nodes (if pos is a conductor) --> recursive
-- 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
-- mesecon:updatenode(pos) | deprecated --> Updates the state of pos and surroundings e.g. when newly placed by a piston
-- 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]
and minetest.registered_nodes[nodename].mesecons
and minetest.registered_nodes[nodename].mesecons.receptor
and minetest.registered_nodes[nodename].mesecons.receptor.state == mesecon.state.on then
return true
and minetest.registered_nodes[nodename].mesecons.effector then
return minetest.registered_nodes[nodename].mesecons.effector
end
for _, receptor in ipairs(mesecon.receptors) do
if receptor.onstate == nodename then
return true
end
end
function mesecon:get_receptor(nodename)
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
return false
end
function mesecon:is_receptor_node_off(nodename, pos, ownpos)
if minetest.registered_nodes[nodename]
and minetest.registered_nodes[nodename].mesecons
and minetest.registered_nodes[nodename].mesecons.receptor
and minetest.registered_nodes[nodename].mesecons.receptor.state == mesecon.state.off then
function mesecon:get_any_inputrules (node)
if mesecon:is_conductor(node.name) then
return mesecon:conductor_get_rules(node)
elseif mesecon:is_effector(node.name) 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
end
for _, receptor in ipairs(mesecon.receptors) do
if receptor.offstate == nodename then
return true
end
return false
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
return false
end
function mesecon:receptor_get_rules(node)
if minetest.registered_nodes[node.name].mesecons
and minetest.registered_nodes[node.name].mesecons.receptor then
local rules = minetest.registered_nodes[node.name].mesecons.receptor.rules
local receptor = mesecon:get_receptor(node.name)
if receptor then
local rules = receptor.rules
if type(rules) == 'function' then
return rules(node)
elseif rules then
return rules
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 mesecon.receptors[i].rules ~=nil then
return receptor.rules
else
return mesecon:get_rules("default")
end
end
end
return mesecon.rules.default
end
-- Effectors
-- Nodes that can be powered by mesecons
function mesecon:is_effector_on(nodename)
if minetest.registered_nodes[nodename]
and minetest.registered_nodes[nodename].mesecons
and minetest.registered_nodes[nodename].mesecons.effector
and minetest.registered_nodes[nodename].mesecons.effector.action_off then
local effector = mesecon:get_effector(nodename)
if effector and effector.action_off then
return true
end
for _, effector in ipairs(mesecon.effectors) do --TODO
if effector.onstate == nodename then
return true
end
end
return false
end
function mesecon:is_effector_off(nodename)
if minetest.registered_nodes[nodename]
and minetest.registered_nodes[nodename].mesecons
and minetest.registered_nodes[nodename].mesecons.effector
and minetest.registered_nodes[nodename].mesecons.effector.action_on then
local effector = mesecon:get_effector(nodename)
if effector and effector.action_on then
return true
end
for _, effector in ipairs(mesecon.effectors) do --TODO
if effector.offstate == nodename then
return true
end
end
return false
end
function mesecon:is_effector(nodename)
if minetest.registered_nodes[nodename]
and minetest.registered_nodes[nodename].mesecons
and minetest.registered_nodes[nodename].mesecons.effector then
local effector = mesecon:get_effector(nodename)
if effector then
return true
end
return mesecon:is_effector_on(nodename) or mesecon:is_effector_off(nodename) --TODO
return false
end
function mesecon:effector_get_input_rules(node)
if minetest.registered_nodes[node.name].mesecons
and minetest.registered_nodes[node.name].mesecons.effector then
local rules = minetest.registered_nodes[node.name].mesecons.effector.rules
function mesecon:effector_get_rules(node)
local effector = mesecon:get_effector(node.name)
if effector then
local rules = effector.rules
if type(rules) == 'function' then
return rules(node)
elseif rules then
return rules
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
end
--Signals
function mesecon:activate(pos, node)
if minetest.registered_nodes[node.name]
and minetest.registered_nodes[node.name].mesecons
and minetest.registered_nodes[node.name].mesecons.effector
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)
local effector = mesecon:get_effector(node.name)
if effector and effector.action_on then
effector.action_on (pos, node)
end
end
function mesecon:deactivate(pos, node) --TODO
if minetest.registered_nodes[node.name]
and minetest.registered_nodes[node.name].mesecons
and minetest.registered_nodes[node.name].mesecons.effector
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)
function mesecon:deactivate(pos, node)
local effector = mesecon:get_effector(node.name)
if effector and effector.action_off then
effector.action_off (pos, node)
end
end
function mesecon:changesignal(pos, node) --TODO
if minetest.registered_nodes[node.name]
and minetest.registered_nodes[node.name].mesecons
and minetest.registered_nodes[node.name].mesecons.effector
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)
function mesecon:changesignal(pos, node)
local effector = mesecon:get_effector(node.name)
if effector and effector.action_change then
effector.action_change (pos, node)
end
end
@ -172,97 +212,64 @@ end
-- 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)
if minetest.registered_nodes[nodename]
and minetest.registered_nodes[nodename].mesecons
and minetest.registered_nodes[nodename].mesecons.conductor
and minetest.registered_nodes[nodename].mesecons.conductor.state == mesecon.state.on then
local conductor = mesecon:get_conductor(nodename)
if conductor and conductor.state == mesecon.state.on then
return true
end
for _, conductor in ipairs(mesecon.conductors) do --TODO
if conductor.onstate == nodename then
return true
end
end
return false
end
function mesecon:is_conductor_off(nodename)
if minetest.registered_nodes[nodename]
and minetest.registered_nodes[nodename].mesecons
and minetest.registered_nodes[nodename].mesecons.conductor
and minetest.registered_nodes[nodename].mesecons.conductor.state == mesecon.state.off then
local conductor = mesecon:get_conductor(nodename)
if conductor and conductor.state == mesecon.state.off then
return true
end
for _, conductor in ipairs(mesecon.conductors) do --TODO
if conductor.offstate == nodename then
return true
end
end
return false
end
function mesecon:is_conductor(nodename)
--TODO
return mesecon:is_conductor_on(nodename) or mesecon:is_conductor_off(nodename)
local conductor = mesecon:get_conductor(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
function mesecon:conductor_get_rules(node)
if minetest.registered_nodes[node.name]
and minetest.registered_nodes[node.name].mesecons
and minetest.registered_nodes[node.name].mesecons.conductor then
local rules = minetest.registered_nodes[node.name].mesecons.conductor.rules
local conductor = mesecon:get_conductor(node.name)
if conductor then
local rules = conductor.rules
if type(rules) == 'function' then
return rules(node)
elseif rules then
return rules
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
end
--
-- some more general high-level stuff
function mesecon:is_power_on(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
end
return false
@ -270,7 +277,7 @@ end
function mesecon:is_power_off(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
end
return false
@ -326,69 +333,57 @@ function mesecon:turnoff(pos)
end
function mesecon:connected_to_pw_src(pos, checked)
local c = 1
function mesecon:connected_to_receptor(pos, checked)
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
-- find out if node has already been checked (to prevent from endless loop)
for _, cp in ipairs(checked) do
if mesecon:cmpPos(cp, 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)
if node == nil then return false, checked end
if not mesecon:is_conductor(node.name) then return false, checked 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)
-- add current position to checked
table.insert(checked, {x=pos.x, y=pos.y, z=pos.z})
for _, rule in ipairs(rules) do
local np = mesecon:addPosRule(pos, rule)
if mesecon:rules_link(pos, np) then
connected, checked = mesecon:connected_to_pw_src(np, checked)
if connected then
return true
local node = minetest.env:get_node(pos)
if mesecon:is_conductor(node.name) then
-- Check if conductors around are connected
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
connected, checked = mesecon:connected_to_receptor(np, checked)
if connected then
return true
end
end
end
elseif mesecon:is_receptor_on(node.name) then
return true
end
return false, checked
end
function mesecon:rules_link(output, input, dug_outputrules) --output/input are positions (outputrules optional, used if node has been dug)
local outputnode = minetest.env:get_node(output)
local inputnode = minetest.env:get_node(input)
local outputrules = dug_outputrules
local inputrules
local outputrules = dug_outputrules or mesecon:get_any_outputrules (outputnode)
local inputrules = mesecon:get_any_inputrules (inputnode)
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
if not outputrules or not inputrules then
return
end
if mesecon:is_conductor(inputnode.name) then
inputrules = mesecon:conductor_get_rules(inputnode)
elseif mesecon:is_effector(inputnode.name) then
inputrules = mesecon:effector_get_input_rules(inputnode)
else
return false
end
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
if mesecon:cmpPos(mesecon:addPosRule(input, inputrule), output) then --Check if input accepts from output
-- Check if input accepts from output
if mesecon:cmpPos(mesecon:addPosRule(input, inputrule), output) then
return true
end
end
@ -397,82 +392,34 @@ function mesecon:rules_link(output, input, dug_outputrules) --output/input are p
return false
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)
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)
return mesecon:is_powered_by_conductor(pos) or mesecon:is_powered_by_receptor(pos)
local node = minetest.env:get_node(pos)
local rules = mesecon:get_any_inputrules(node)
if not rules then return false end
for _, rule in ipairs(rules) do
local np = mesecon:addPosRule(pos, rule)
local nn = minetest.env:get_node(np)
if (mesecon:is_conductor_on (nn.name) or mesecon:is_receptor_on (nn.name))
and mesecon:rules_link(np, pos) then
return true
end
end
return false
end
function mesecon:updatenode(pos)
if mesecon:connected_to_pw_src(pos) then
mesecon:turnon(pos)
else
mesecon:turnoff(pos)
end
if mesecon:is_powered(pos) then
mesecon:turnon(pos)
else
mesecon:turnoff(pos)
end
end
--Rules rotation Functions:

@ -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

@ -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"
}}
})

@ -1,28 +1,23 @@
minetest.register_on_dignode(
function(pos, oldnode, digger)
if mesecon:is_conductor_on(oldnode.name) then
mesecon:receptor_off(pos)
end
if mesecon:is_receptor_node(oldnode.name) then
mesecon:receptor_off(pos, mesecon:receptor_get_rules(oldnode))
mesecon.on_placenode = function (pos, node)
if mesecon:is_receptor_on(node.name) then
mesecon:receptor_on(pos, mesecon:receptor_get_rules(node))
elseif 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
minetest.register_on_placenode(
function (pos, node)
if mesecon:is_receptor_node(node.name) then
mesecon:receptor_on(pos, mesecon:receptor_get_rules(node))
end
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
mesecon.on_dignode = function (pos, node)
if mesecon:is_conductor_on(node.name) then
mesecon:receptor_off(pos)
elseif mesecon:is_receptor_on(node.name) then
mesecon:receptor_off(pos, mesecon:receptor_get_rules(node))
end
)
end
minetest.register_on_placenode(mesecon.on_placenode)
minetest.register_on_dignode(mesecon.on_dignode)

@ -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
-- The conditions in brackets define whether there is a mesecon at that place or not
-- 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_zmy = {-1/16, -.5+1/16, -.5, 1/16, .4999+1/16, -.5+1/16}
-- Registering the wires
for xp=0, 1 do
for zp=0, 1 do
for xm=0, 1 do
@ -191,6 +157,9 @@ end
end
end
-- Updating the wires:
-- Place the right connection wire
local update_on_place_dig = function (pos, node)
if minetest.registered_nodes[node.name]
and minetest.registered_nodes[node.name].mesecons then
@ -237,38 +206,21 @@ function mesecon:update_autoconnect(pos, secondcall, replace_old)
nodename = minetest.env:get_node(pos).name
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_bothdir(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_bothdir(pos, zmpos) then zm = 1 else zm = 0 end
if mesecon:rules_link_anydir(pos, xppos) then xp = 1 else xp = 0 end
if mesecon:rules_link_anydir(pos, xmpos) then xm = 1 else xm = 0 end
if mesecon:rules_link_anydir(pos, zppos) then zp = 1 else zp = 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_bothdir(pos, xmympos) then xm = 1 end
if mesecon:rules_link_bothdir(pos, zpympos) then zp = 1 end
if mesecon:rules_link_bothdir(pos, zmympos) then zm = 1 end
if mesecon:rules_link_anydir(pos, xpympos) then xp = 1 end
if mesecon:rules_link_anydir(pos, xmympos) then xm = 1 end
if mesecon:rules_link_anydir(pos, zpympos) then zp = 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(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(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 zpy == 1 then zp = 1 end
if xmy == 1 then xm = 1 end
@ -291,13 +243,3 @@ minetest.register_craft({
{'"default:mese"'},
}
})
minetest.register_abm(
{nodenames = {"mesecons:mesecon_off", "mesecons:mesecon_on"},
interval = 2,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
mesecon:update_autoconnect(pos, false, true)
end,
})
end

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

@ -247,5 +247,8 @@ function mesecon:piston_get_direction(node)
end
end
dofile(minetest.get_modpath("mesecons_pistons").."/pistons_down.lua")
dofile(minetest.get_modpath("mesecons_pistons").."/pistons_up.lua")
-- dofile(minetest.get_modpath("mesecons_pistons").."/pistons_down.lua")
-- dofile(minetest.get_modpath("mesecons_pistons").."/pistons_up.lua")
-- Dropped
-- We need a better way to have these piston types
-- There should be a facedir for vertical orientations

Binary file not shown.

After

Width:  |  Height:  |  Size: 465 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 464 B