Compare commits
90 Commits
v0.6-stabl
...
20130211
Author | SHA1 | Date | |
---|---|---|---|
0e34696214 | |||
7cc803b0d7 | |||
536c77330b | |||
fb45ee1d77 | |||
5b5e919683 | |||
4714c908ac | |||
ccb3430540 | |||
43cb258877 | |||
e3c9eded2a | |||
74eefc270a | |||
a5a4f2b65c | |||
c23295409b | |||
baba7de063 | |||
5c2959826e | |||
841bc70b97 | |||
17579a6aa1 | |||
ec07fc27d7 | |||
52ddd4bdc9 | |||
5921f6d46c | |||
7e231b99a6 | |||
ab1966f763 | |||
2bbc9dd4b7 | |||
72d58d2018 | |||
c062411fa1 | |||
2a061362fb | |||
92122379de | |||
c63afd49ec | |||
2a8bd68c41 | |||
84ad046533 | |||
cdd9a93da9 | |||
d3b77b5be3 | |||
ac0fb91139 | |||
d1ace465c7 | |||
7fe4947056 | |||
5a88a9715f | |||
d91e0b66cb | |||
a9a2108d13 | |||
c508bfaea6 | |||
af8fd75fa4 | |||
e2ec7b5b04 | |||
5e8e003b8c | |||
6fab716f3e | |||
34fa8a1167 | |||
23bebfc054 | |||
973a9c650f | |||
9019a4aff7 | |||
f114cb8ddc | |||
5aa0815ffb | |||
6b1bfe6391 | |||
f6ef7b005d | |||
5cdf23fb00 | |||
e9e1006656 | |||
313b9adcd5 | |||
313a137675 | |||
c50b68cf83 | |||
13befe3bba | |||
2c4a46a557 | |||
0aab812487 | |||
c76c274cc0 | |||
a1852204fb | |||
ae4bd1e21c | |||
9dee0c020c | |||
aab0d4d943 | |||
b5f5beeb3d | |||
5fb5df446c | |||
18731cbc8a | |||
44dc1a128c | |||
c0d3bd2abb | |||
594d061d6d | |||
659060ddcd | |||
de46729b97 | |||
5540fcbcb3 | |||
a55874b5d2 | |||
192b9eca4f | |||
59a39204a9 | |||
e9f2beb2c6 | |||
5904abbd79 | |||
d5825f9602 | |||
05def1540a | |||
961b955f2d | |||
31f3c99288 | |||
a0a3328f7c | |||
b37bdbf55c | |||
cf6080f723 | |||
00e071b695 | |||
8578fd89c8 | |||
472650f099 | |||
f28cf0af03 | |||
e0aa5b1d3d | |||
12206ac190 |
@ -3,128 +3,112 @@
|
||||
-- | \/ | |___ ____ |___ | | | | \ | |____
|
||||
-- | | | | | | | | | \ | |
|
||||
-- | | |___ ____| |___ |____ |____| | \| ____|
|
||||
-- by Jeija and Minerd247
|
||||
-- by Jeija, Uberi (Temperest), sfan5, VanessaE
|
||||
--
|
||||
--
|
||||
--
|
||||
-- This mod adds mesecons[=minecraft redstone] and different receptors/effectors to minetest.
|
||||
--
|
||||
-- See the documentation on the forum for additional information, especially about crafting
|
||||
--
|
||||
-- For developer documentation see the Developers' section on mesecons.tk
|
||||
--
|
||||
-- For developer documentation see the Developers' section on mesecons.TK
|
||||
--
|
||||
--
|
||||
--
|
||||
--Quick draft for the mesecons array in the node's definition
|
||||
--mesecons =
|
||||
--{
|
||||
-- receptor =
|
||||
-- {
|
||||
-- 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
|
||||
-- offstate = opposite state (for state = on only)
|
||||
-- onstate = opposite state (for state = off only)
|
||||
-- rules = rules/get_rules
|
||||
-- }
|
||||
--}
|
||||
|
||||
|
||||
-- PUBLIC VARIABLES
|
||||
mesecon={} -- contains all functions and all global variables
|
||||
mesecon.actions_on={} -- Saves registered function callbacks for mesecon on
|
||||
mesecon.actions_off={} -- Saves registered function callbacks for mesecon off
|
||||
mesecon.actions_change={} -- Saves registered function callbacks for mesecon change
|
||||
mesecon.receptors={}
|
||||
mesecon.effectors={}
|
||||
mesecon.rules={}
|
||||
mesecon.conductors={}
|
||||
mesecon.actions_on={} -- Saves registered function callbacks for mesecon on | DEPRECATED
|
||||
mesecon.actions_off={} -- Saves registered function callbacks for mesecon off | DEPRECATED
|
||||
mesecon.actions_change={} -- Saves registered function callbacks for mesecon change | DEPRECATED
|
||||
mesecon.receptors={} -- saves all information about receptors | DEPRECATED
|
||||
mesecon.effectors={} -- saves all information about effectors | DEPRECATED
|
||||
mesecon.conductors={} -- saves all information about conductors | DEPRECATED
|
||||
|
||||
-- INCLUDE SETTINGS
|
||||
-- Settings
|
||||
dofile(minetest.get_modpath("mesecons").."/settings.lua")
|
||||
|
||||
--Internal API
|
||||
-- Presets (eg default rules)
|
||||
dofile(minetest.get_modpath("mesecons").."/presets.lua");
|
||||
|
||||
|
||||
-- Utilities like comparing positions,
|
||||
-- adding positions and rules,
|
||||
-- mostly things that make the source look cleaner
|
||||
dofile(minetest.get_modpath("mesecons").."/util.lua");
|
||||
|
||||
-- Internal stuff
|
||||
-- This is the most important file
|
||||
-- it handles signal transmission and basically everything else
|
||||
-- It is also responsible for managing the nodedef things,
|
||||
-- like calling action_on/off/change
|
||||
dofile(minetest.get_modpath("mesecons").."/internal.lua");
|
||||
|
||||
-- API API API API API API API API API API API API API API API API API API
|
||||
-- Deprecated stuff
|
||||
-- To be removed in future releases
|
||||
-- Currently there is nothing here
|
||||
dofile(minetest.get_modpath("mesecons").."/legacy.lua");
|
||||
|
||||
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 = 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
|
||||
-- API
|
||||
-- these are the only functions you need to remember
|
||||
|
||||
function mesecon:receptor_on(pos, rules)
|
||||
if rules == nil then
|
||||
rules = mesecon:get_rules("default")
|
||||
end
|
||||
rules = rules or mesecon.rules.default
|
||||
|
||||
for i, rule in ipairs(rules) do
|
||||
local np = {
|
||||
x = pos.x + rule.x,
|
||||
y = pos.y + rule.y,
|
||||
z = pos.z + rule.z}
|
||||
if mesecon:rules_link(pos, np, rules) then
|
||||
mesecon:turnon(np, pos)
|
||||
for _, rule in ipairs(rules) do
|
||||
local np = mesecon:addPosRule(pos, rule)
|
||||
local link, rulename = mesecon:rules_link(pos, np, rules)
|
||||
if link then
|
||||
mesecon:turnon(np, rulename)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function mesecon:receptor_off(pos, rules)
|
||||
if rules == nil then
|
||||
rules = mesecon:get_rules("default")
|
||||
end
|
||||
rules = rules or mesecon.rules.default
|
||||
|
||||
for i, rule in ipairs(rules) do
|
||||
local np = {
|
||||
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
|
||||
mesecon:turnoff(np, pos)
|
||||
for _, rule in ipairs(rules) do
|
||||
local np = mesecon:addPosRule(pos, rule)
|
||||
local link, rulename = mesecon:rules_link(pos, np, rules)
|
||||
if link then
|
||||
if not mesecon:connected_to_receptor(np) then
|
||||
mesecon:turnoff(np, rulename)
|
||||
else
|
||||
mesecon:changesignal(np, minetest.env:get_node(np), rulename)
|
||||
end
|
||||
end
|
||||
end
|
||||
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",
|
||||
{{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=1, y=1, z=0},
|
||||
{x=1, y=-1, z=0},
|
||||
{x=-1, y=1, z=0},
|
||||
{x=-1, y=-1, z=0},
|
||||
{x=0, y=1, z=1},
|
||||
{x=0, y=-1, z=1},
|
||||
{x=0, y=1, z=-1},
|
||||
{x=0, y=-1, z=-1}})
|
||||
|
||||
print("[MESEcons] Main mod Loaded!")
|
||||
print("[OK] Mesecons")
|
||||
|
||||
--The actual wires
|
||||
dofile(minetest.get_modpath("mesecons").."/wires.lua");
|
||||
|
||||
--Services like turnoff receptor on dignode and so on
|
||||
dofile(minetest.get_modpath("mesecons").."/services.lua");
|
||||
--Deprecated stuff
|
||||
dofile(minetest.get_modpath("mesecons").."/legacy.lua");
|
||||
|
@ -1,173 +1,275 @@
|
||||
-- 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
|
||||
function mesecon:is_receptor_node(nodename)
|
||||
for _, receptor in ipairs(mesecon.receptors) do
|
||||
if receptor.onstate == nodename then
|
||||
return true
|
||||
-- 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, 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]
|
||||
and minetest.registered_nodes[nodename].mesecons
|
||||
and minetest.registered_nodes[nodename].mesecons.effector then
|
||||
return minetest.registered_nodes[nodename].mesecons.effector
|
||||
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)
|
||||
for _, receptor in ipairs(mesecon.receptors) do
|
||||
if receptor.offstate == nodename 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
|
||||
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)
|
||||
for i, receptor in ipairs(mesecon.receptors) do
|
||||
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")
|
||||
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
|
||||
end
|
||||
return nil
|
||||
|
||||
return mesecon.rules.default
|
||||
end
|
||||
|
||||
-- Effectors
|
||||
-- Nodes that can be powered by mesecons
|
||||
function mesecon:is_effector_on(nodename)
|
||||
for i, effector in ipairs(mesecon.effectors) do
|
||||
if effector.onstate == nodename then
|
||||
local effector = mesecon:get_effector(nodename)
|
||||
if effector and effector.action_off then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:is_effector_off(nodename)
|
||||
for i, effector in ipairs(mesecon.effectors) do
|
||||
if effector.offstate == nodename then
|
||||
local effector = mesecon:get_effector(nodename)
|
||||
if effector and effector.action_on then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:is_effector(nodename)
|
||||
return mesecon:is_effector_on(nodename) or mesecon:is_effector_off(nodename)
|
||||
local effector = mesecon:get_effector(nodename)
|
||||
if effector then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:effector_get_input_rules(node)
|
||||
for i, 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 mesecon.effectors[i].input_rules ~=nil then
|
||||
return effector.input_rules
|
||||
else
|
||||
return mesecon:get_rules("default")
|
||||
end
|
||||
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
|
||||
return mesecon.rules.default
|
||||
end
|
||||
|
||||
--Signals
|
||||
|
||||
function mesecon:activate(pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
for i, action in ipairs(mesecon.actions_on) do
|
||||
action(pos, node)
|
||||
function mesecon:activate(pos, node, rulename)
|
||||
local effector = mesecon:get_effector(node.name)
|
||||
if effector and effector.action_on then
|
||||
effector.action_on (pos, node, rulename)
|
||||
end
|
||||
end
|
||||
|
||||
function mesecon:deactivate(pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
for i, action in ipairs(mesecon.actions_off) do
|
||||
action(pos, node)
|
||||
function mesecon:deactivate(pos, node, rulename)
|
||||
local effector = mesecon:get_effector(node.name)
|
||||
if effector and effector.action_off then
|
||||
effector.action_off (pos, node, rulename)
|
||||
end
|
||||
end
|
||||
|
||||
function mesecon:changesignal(pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
for i, action in ipairs(mesecon.actions_change) do
|
||||
action(pos, node)
|
||||
function mesecon:changesignal(pos, node, rulename)
|
||||
local effector = mesecon:get_effector(node.name)
|
||||
if effector and effector.action_change then
|
||||
effector.action_change (pos, node, rulename)
|
||||
end
|
||||
end
|
||||
|
||||
--Rules
|
||||
|
||||
function mesecon:add_rules(name, rules)
|
||||
table.insert(mesecon.rules, {name = name, rules = rules})
|
||||
mesecon.rules[name] = rules
|
||||
end
|
||||
|
||||
function mesecon:get_rules(name)
|
||||
for i, rule in ipairs(mesecon.rules) do
|
||||
if rule.name==name then
|
||||
return rule.rules
|
||||
end
|
||||
end
|
||||
return mesecon.rules[name]
|
||||
end
|
||||
|
||||
--Conductor system stuff
|
||||
-- Conductors
|
||||
|
||||
function mesecon:is_conductor_on(nodename)
|
||||
local conductor = mesecon:get_conductor(nodename)
|
||||
if conductor and conductor.state == mesecon.state.on then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:is_conductor_off(nodename)
|
||||
local conductor = mesecon:get_conductor(nodename)
|
||||
if conductor and conductor.state == mesecon.state.off then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:is_conductor(nodename)
|
||||
local conductor = mesecon:get_conductor(nodename)
|
||||
if conductor then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:get_conductor_on(offstate)
|
||||
for i, conductor in ipairs(mesecon.conductors) do
|
||||
if conductor.offstate == offstate then
|
||||
local conductor = mesecon:get_conductor(offstate)
|
||||
if conductor then
|
||||
return conductor.onstate
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:get_conductor_off(onstate)
|
||||
for i, conductor in ipairs(mesecon.conductors) do
|
||||
if conductor.onstate == onstate then
|
||||
local conductor = mesecon:get_conductor(onstate)
|
||||
if conductor then
|
||||
return conductor.offstate
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:is_conductor_on(name)
|
||||
for i, conductor in ipairs(mesecon.conductors) do
|
||||
if conductor.onstate == name then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:is_conductor_off(name)
|
||||
for i, conductor in ipairs(mesecon.conductors) do
|
||||
if conductor.offstate == name then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:is_conductor(name)
|
||||
return mesecon:is_conductor_on(name) or mesecon:is_conductor_off(name)
|
||||
end
|
||||
|
||||
function mesecon:conductor_get_rules(node)
|
||||
for i, conductor in ipairs(mesecon.conductors) do
|
||||
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
|
||||
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
|
||||
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
|
||||
@ -175,146 +277,126 @@ 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
|
||||
end
|
||||
|
||||
function mesecon:turnon(pos)
|
||||
function mesecon:turnon(pos, rulename)
|
||||
local node = minetest.env:get_node(pos)
|
||||
|
||||
if mesecon:is_conductor_off(node.name) then
|
||||
local rules = mesecon:conductor_get_rules(node)
|
||||
minetest.env:add_node(pos, {name = mesecon:get_conductor_on(node.name), param2 = node.param2})
|
||||
|
||||
for i, rule in ipairs(rules) do
|
||||
local np = {}
|
||||
np.x = pos.x + rule.x
|
||||
np.y = pos.y + rule.y
|
||||
np.z = pos.z + rule.z
|
||||
for _, rule in ipairs(rules) do
|
||||
local np = mesecon:addPosRule(pos, rule)
|
||||
local link, rulename = mesecon:rules_link(pos, np)
|
||||
|
||||
if mesecon:rules_link(pos, np) then
|
||||
mesecon:turnon(np)
|
||||
if link then
|
||||
mesecon:turnon(np, rulename)
|
||||
end
|
||||
end
|
||||
elseif mesecon:is_effector(node.name) then
|
||||
mesecon:changesignal(pos, node, rulename)
|
||||
if mesecon:is_effector_off(node.name) then
|
||||
mesecon:activate(pos, node, rulename)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if mesecon:is_effector(node.name) then
|
||||
mesecon:changesignal(pos)
|
||||
if mesecon:is_effector_off(node.name) then mesecon:activate(pos) end
|
||||
end
|
||||
end
|
||||
|
||||
function mesecon:turnoff(pos) --receptor rules used because output could have been dug
|
||||
function mesecon:turnoff(pos, rulename)
|
||||
local node = minetest.env:get_node(pos)
|
||||
local rules
|
||||
|
||||
if mesecon:is_conductor_on(node.name) then
|
||||
rules = mesecon:conductor_get_rules(node)
|
||||
|
||||
local rules = mesecon:conductor_get_rules(node)
|
||||
minetest.env:add_node(pos, {name = mesecon:get_conductor_off(node.name), param2 = node.param2})
|
||||
|
||||
for i, rule in ipairs(rules) do
|
||||
local np = {
|
||||
x = pos.x + rule.x,
|
||||
y = pos.y + rule.y,
|
||||
z = pos.z + rule.z,}
|
||||
for _, rule in ipairs(rules) do
|
||||
local np = mesecon:addPosRule(pos, rule)
|
||||
local link, rulename = mesecon:rules_link(pos, np)
|
||||
|
||||
if mesecon:rules_link(pos, np) then
|
||||
mesecon:turnoff(np)
|
||||
if link then
|
||||
mesecon:turnoff(np, rulename)
|
||||
end
|
||||
end
|
||||
elseif mesecon:is_effector(node.name) then
|
||||
mesecon:changesignal(pos, node, rulename)
|
||||
if mesecon:is_effector_on(node.name)
|
||||
and not mesecon:is_powered(pos) then
|
||||
mesecon:deactivate(pos, node, rulename)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if mesecon:is_effector(node.name) then
|
||||
mesecon:changesignal(pos)
|
||||
if mesecon:is_effector_on(node.name) and not mesecon:is_powered(pos) then mesecon:deactivate(pos) end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function mesecon:connected_to_pw_src(pos, checked)
|
||||
local c = 1
|
||||
checked = checked or {}
|
||||
while checked[c] ~= nil do --find out if node has already been checked (to prevent from endless loop)
|
||||
if compare_pos(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)
|
||||
|
||||
if node == nil then return false, checked end
|
||||
if mesecon:is_powered_by_receptor(pos) then --return if conductor is powered
|
||||
return true, checked
|
||||
end
|
||||
function mesecon:connected_to_receptor(pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
|
||||
-- Check if conductors around are connected
|
||||
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, checked
|
||||
end
|
||||
local rules = mesecon:get_any_inputrules(node)
|
||||
if not rules then return false end
|
||||
|
||||
for i, rule in ipairs(rules) do
|
||||
local np = {}
|
||||
np.x = pos.x + rule.x
|
||||
np.y = pos.y + rule.y
|
||||
np.z = pos.z + rule.z
|
||||
if mesecon:rules_link(pos, np) then
|
||||
connected, checked = mesecon:connected_to_pw_src(np, checked)
|
||||
if connected then
|
||||
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, {}) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false, checked
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:rules_link(output, input, dug_outputrules) --output/input are positions (outputrules optional, used if node has been dug)
|
||||
local k = 1
|
||||
local l = 1
|
||||
function mesecon:find_receptor_on(pos, checked)
|
||||
-- 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
|
||||
end
|
||||
|
||||
-- add current position to checked
|
||||
table.insert(checked, {x=pos.x, y=pos.y, z=pos.z})
|
||||
local node = minetest.env:get_node(pos)
|
||||
|
||||
if mesecon:is_receptor_on(node.name) then
|
||||
return true
|
||||
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
|
||||
local inputrules
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
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 k, outputrule in ipairs(outputrules) do
|
||||
if outputrule.x + output.x == input.x
|
||||
and outputrule.y + output.y == input.y
|
||||
and outputrule.z + output.z == input.z then -- Check if output sends to input
|
||||
l = 1
|
||||
for k, inputrule in ipairs(inputrules) do
|
||||
if inputrule.x + input.x == output.x
|
||||
and inputrule.y + input.y == output.y
|
||||
and inputrule.z + input.z == output.z then --Check if input accepts from output
|
||||
return true
|
||||
for _, outputrule in ipairs(outputrules) do
|
||||
-- Check if output sends to input
|
||||
if mesecon:cmpPos(mesecon:addPosRule(output, outputrule), input) then
|
||||
for _, inputrule in ipairs(inputrules) do
|
||||
-- Check if input accepts from output
|
||||
if mesecon:cmpPos(mesecon:addPosRule(input, inputrule), output) then
|
||||
return true, inputrule.name
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -322,135 +404,69 @@ 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 i, rule in ipairs(rules) do
|
||||
local con_pos = {
|
||||
x = pos.x + rule.x,
|
||||
y = pos.y + rule.y,
|
||||
z = pos.z + rule.z}
|
||||
|
||||
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 i, rule in ipairs(rules) do
|
||||
local rcpt_pos = {
|
||||
x = pos.x + rule.x,
|
||||
y = pos.y + rule.y,
|
||||
z = pos.z + rule.z}
|
||||
|
||||
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)
|
||||
end
|
||||
local node = minetest.env:get_node(pos)
|
||||
local rules = mesecon:get_any_inputrules(node)
|
||||
if not rules then return false end
|
||||
|
||||
function mesecon:updatenode(pos)
|
||||
if mesecon:connected_to_pw_src(pos) then
|
||||
mesecon:turnon(pos)
|
||||
else
|
||||
mesecon:turnoff(pos)
|
||||
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
|
||||
|
||||
function compare_pos(pos1, pos2)
|
||||
return pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z
|
||||
return false
|
||||
end
|
||||
|
||||
--Rules rotation Functions:
|
||||
function mesecon:rotate_rules_right(rules)
|
||||
local nr={};
|
||||
local nr = {}
|
||||
for i, rule in ipairs(rules) do
|
||||
nr[i]={}
|
||||
nr[i].z=rule.x
|
||||
nr[i].x=-rule.z
|
||||
nr[i].y=rule.y
|
||||
table.insert(nr, {
|
||||
x = -rule.z,
|
||||
y = rule.y,
|
||||
z = rule.x})
|
||||
end
|
||||
return nr
|
||||
end
|
||||
|
||||
function mesecon:rotate_rules_left(rules)
|
||||
local nr={};
|
||||
local nr = {}
|
||||
for i, rule in ipairs(rules) do
|
||||
nr[i]={}
|
||||
nr[i].z=-rules[i].x
|
||||
nr[i].x=rules[i].z
|
||||
nr[i].y=rules[i].y
|
||||
table.insert(nr, {
|
||||
x = rule.z,
|
||||
y = rule.y,
|
||||
z = -rule.x})
|
||||
end
|
||||
return nr
|
||||
end
|
||||
|
||||
function mesecon:rotate_rules_down(rules)
|
||||
local nr={};
|
||||
local nr = {}
|
||||
for i, rule in ipairs(rules) do
|
||||
nr[i]={}
|
||||
nr[i].y=rule.x
|
||||
nr[i].x=-rule.y
|
||||
nr[i].z=rule.z
|
||||
table.insert(nr, {
|
||||
x = -rule.y,
|
||||
y = rule.x,
|
||||
z = rule.z})
|
||||
end
|
||||
return nr
|
||||
end
|
||||
|
||||
function mesecon:rotate_rules_up(rules)
|
||||
local nr={};
|
||||
local nr = {}
|
||||
for i, rule in ipairs(rules) do
|
||||
nr[i]={}
|
||||
nr[i].y=-rule.x
|
||||
nr[i].x=rule.y
|
||||
nr[i].z=rule.z
|
||||
table.insert(nr, {
|
||||
x = rule.y,
|
||||
y = -rule.x,
|
||||
z = rule.z})
|
||||
end
|
||||
return nr
|
||||
end
|
||||
|
@ -1,13 +0,0 @@
|
||||
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
|
||||
|
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"
|
||||
}}
|
||||
})
|
45
mesecons/presets.lua
Normal file
@ -0,0 +1,45 @@
|
||||
mesecon.rules = {}
|
||||
mesecon.state = {}
|
||||
|
||||
mesecon.rules.default =
|
||||
{{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=1, y=1, z=0},
|
||||
{x=1, y=-1, z=0},
|
||||
{x=-1, y=1, z=0},
|
||||
{x=-1, y=-1, z=0},
|
||||
{x=0, y=1, z=1},
|
||||
{x=0, y=-1, z=1},
|
||||
{x=0, y=1, z=-1},
|
||||
{x=0, y=-1, z=-1}}
|
||||
|
||||
mesecon.rules.buttonlike =
|
||||
{{x = 1, y = 0, z = 0},
|
||||
{x = 1, y = 1, z = 0},
|
||||
{x = 1, y =-1, z = 0},
|
||||
{x = 1, y =-1, z = 1},
|
||||
{x = 1, y =-1, z =-1},
|
||||
{x = 2, y = 0, z = 0}}
|
||||
|
||||
mesecon.rules.flat =
|
||||
{{x = 1, y = 0, z = 0},
|
||||
{x =-1, y = 0, z = 0},
|
||||
{x = 0, y = 0, z = 1},
|
||||
{x = 0, y = 0, z =-1}}
|
||||
|
||||
mesecon.rules.buttonlike_get = function(node)
|
||||
local rules = mesecon.rules.buttonlike
|
||||
if node.param2 == 2 then
|
||||
rules=mesecon:rotate_rules_left(rules)
|
||||
elseif node.param2 == 3 then
|
||||
rules=mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules))
|
||||
elseif node.param2 == 0 then
|
||||
rules=mesecon:rotate_rules_right(rules)
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
mesecon.state.on = "on"
|
||||
mesecon.state.off = "off"
|
@ -1,28 +1,28 @@
|
||||
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))
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
minetest.register_on_placenode(
|
||||
function (pos, node)
|
||||
if mesecon:is_receptor_node(node.name) then
|
||||
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(node.name) then
|
||||
mesecon:turnon (pos)
|
||||
mesecon:receptor_on (pos, mesecon:conductor_get_rules(node))
|
||||
else
|
||||
mesecon:changesignal(pos, node)
|
||||
mesecon:activate(pos, node)
|
||||
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
|
||||
|
||||
if mesecon:is_powered(pos) then
|
||||
if mesecon:is_conductor_off(node.name) then
|
||||
mesecon:turnon(pos)
|
||||
else
|
||||
mesecon:changesignal(pos)
|
||||
mesecon:activate(pos)
|
||||
mesecon.on_dignode = function (pos, node)
|
||||
if mesecon:is_conductor_on(node.name) then
|
||||
mesecon:receptor_off(pos, mesecon:conductor_get_rules(node))
|
||||
elseif mesecon:is_receptor_on(node.name) then
|
||||
mesecon:receptor_off(pos, mesecon:receptor_get_rules(node))
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
minetest.register_on_placenode(mesecon.on_placenode)
|
||||
minetest.register_on_dignode(mesecon.on_dignode)
|
||||
|
@ -2,3 +2,5 @@
|
||||
BLINKY_PLANT_INTERVAL = 3
|
||||
NEW_STYLE_WIRES = true -- true = new nodebox wires, false = old raillike wires
|
||||
PRESSURE_PLATE_INTERVAL = 0.1
|
||||
OBJECT_DETECTOR_RADIUS = 6
|
||||
PISTON_MAXIMUM_PUSH = 15
|
||||
|
24
mesecons/util.lua
Normal file
@ -0,0 +1,24 @@
|
||||
function mesecon:swap_node(pos, name)
|
||||
local node = minetest.env:get_node(pos)
|
||||
local data = minetest.env:get_meta(pos):to_table()
|
||||
node.name = name
|
||||
minetest.env:add_node(pos, node)
|
||||
minetest.env:get_meta(pos):from_table(data)
|
||||
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)
|
||||
return {x = p.x + r.x, y = p.y + r.y, z = p.z + r.z}
|
||||
end
|
||||
|
||||
function mesecon:cmpPos(p1, p2)
|
||||
return (p1.x == p2.x and p1.y == p2.y and p1.z == p2.z)
|
||||
end
|
@ -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
|
||||
@ -41,7 +5,6 @@ else -- NEW STYLE WIRES
|
||||
|
||||
box_center = {-1/16, -.5, -1/16, 1/16, -.5+1/16, 1/16}
|
||||
box_bump1 = { -2/16, -8/16, -2/16, 2/16, -13/32, 2/16 }
|
||||
box_bump2 = { -3/32, -13/32, -3/32, 3/32, -12/32, 3/32 }
|
||||
|
||||
box_xp = {1/16, -.5, -1/16, 8/16, -.5+1/16, 1/16}
|
||||
box_zp = {-1/16, -.5, 1/16, 1/16, -.5+1/16, 8/16}
|
||||
@ -53,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
|
||||
@ -69,10 +34,10 @@ for zmy=0, 1 do
|
||||
tostring(xpy)..tostring(zpy)..tostring(xmy)..tostring(zmy)
|
||||
|
||||
if nodeid == "00000000" then
|
||||
groups = {dig_immediate = 3, mesecon = 2, mesecon_conductor_craftable=1}
|
||||
groups = {dig_immediate = 3, mesecon_conductor_craftable=1}
|
||||
wiredesc = "Mesecon"
|
||||
else
|
||||
groups = {dig_immediate = 3, mesecon = 2, not_in_creative_inventory = 1}
|
||||
groups = {dig_immediate = 3, not_in_creative_inventory = 1}
|
||||
wiredesc = "Mesecons Wire (ID: "..nodeid..")"
|
||||
end
|
||||
|
||||
@ -90,7 +55,6 @@ for zmy=0, 1 do
|
||||
|
||||
if adjx and adjz and (xp + zp + xm + zm > 2) then
|
||||
table.insert(nodebox, box_bump1)
|
||||
table.insert(nodebox, box_bump2)
|
||||
tiles_off = {
|
||||
"wires_bump_off.png",
|
||||
"wires_bump_off.png",
|
||||
@ -153,13 +117,21 @@ for zmy=0, 1 do
|
||||
groups = groups,
|
||||
walkable = false,
|
||||
stack_max = 99,
|
||||
drop = "mesecons:wire_00000000_off"
|
||||
drop = "mesecons:wire_00000000_off",
|
||||
mesecons = {conductor={
|
||||
state = mesecon.state.off,
|
||||
onstate = "mesecons:wire_"..nodeid.."_on"
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons:wire_"..nodeid.."_on", {
|
||||
description = "Wire ID:"..nodeid,
|
||||
drawtype = "nodebox",
|
||||
tiles = tiles_on,
|
||||
-- inventory_image = "wires_inv.png",
|
||||
-- wield_image = "wires_inv.png",
|
||||
inventory_image = "jeija_mesecon_off.png",
|
||||
wield_image = "jeija_mesecon_off.png",
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
sunlight_propagates = true,
|
||||
@ -174,9 +146,12 @@ for zmy=0, 1 do
|
||||
groups = {dig_immediate = 3, mesecon = 2, not_in_creative_inventory = 1},
|
||||
walkable = false,
|
||||
stack_max = 99,
|
||||
drop = "mesecons:wire_00000000_off"
|
||||
drop = "mesecons:wire_00000000_off",
|
||||
mesecons = {conductor={
|
||||
state = mesecon.state.on,
|
||||
offstate = "mesecons:wire_"..nodeid.."_off"
|
||||
}}
|
||||
})
|
||||
mesecon:register_conductor("mesecons:wire_"..nodeid.."_on", "mesecons:wire_"..nodeid.."_off")
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -186,17 +161,18 @@ end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_placenode(function(pos, node)
|
||||
if minetest.get_item_group(node.name, "mesecon") > 1 then
|
||||
mesecon:update_autoconnect(pos)
|
||||
end
|
||||
end)
|
||||
-- Updating the wires:
|
||||
-- Place the right connection wire
|
||||
|
||||
minetest.register_on_dignode(function(pos, node)
|
||||
if minetest.get_item_group(node.name, "mesecon") > 1 then
|
||||
local update_on_place_dig = function (pos, node)
|
||||
if minetest.registered_nodes[node.name]
|
||||
and minetest.registered_nodes[node.name].mesecons then
|
||||
mesecon:update_autoconnect(pos)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
minetest.register_on_placenode(update_on_place_dig)
|
||||
minetest.register_on_dignode(update_on_place_dig)
|
||||
|
||||
function mesecon:update_autoconnect(pos, secondcall, replace_old)
|
||||
local xppos = {x=pos.x+1, y=pos.y, z=pos.z}
|
||||
@ -234,65 +210,20 @@ 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_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 the groups mesecon == 1 then wires won't connect to it
|
||||
local zmg = minetest.get_item_group(minetest.env:get_node(zmpos ).name, "mesecon")
|
||||
local zmymg = minetest.get_item_group(minetest.env:get_node(zmympos).name, "mesecon")
|
||||
local xmg = minetest.get_item_group(minetest.env:get_node(xmpos ).name, "mesecon")
|
||||
local xmymg = minetest.get_item_group(minetest.env:get_node(xmympos).name, "mesecon")
|
||||
local zpg = minetest.get_item_group(minetest.env:get_node(zppos ).name, "mesecon")
|
||||
local zpymg = minetest.get_item_group(minetest.env:get_node(zpympos).name, "mesecon")
|
||||
local xpg = minetest.get_item_group(minetest.env:get_node(xppos ).name, "mesecon")
|
||||
local xpymg = minetest.get_item_group(minetest.env:get_node(xpympos).name, "mesecon")
|
||||
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
|
||||
|
||||
|
||||
local xpyg = minetest.get_item_group(minetest.env:get_node(xpypos).name, "mesecon")
|
||||
local zpyg = minetest.get_item_group(minetest.env:get_node(zpypos).name, "mesecon")
|
||||
local xmyg = minetest.get_item_group(minetest.env:get_node(xmypos).name, "mesecon")
|
||||
local zmyg = minetest.get_item_group(minetest.env:get_node(zmypos).name, "mesecon")
|
||||
|
||||
if ((zmg == 2) or (zmymg == 2)) == true then zm = 1 else zm = 0 end
|
||||
if ((xmg == 2) or (xmymg == 2)) == true then xm = 1 else xm = 0 end
|
||||
if ((zpg == 2) or (zpymg == 2)) == true then zp = 1 else zp = 0 end
|
||||
if ((xpg == 2) or (xpymg == 2)) == true then xp = 1 else xp = 0 end
|
||||
|
||||
if xpyg == 2 then xpy = 1 else xpy = 0 end
|
||||
if zpyg == 2 then zpy = 1 else zpy = 0 end
|
||||
if xmyg == 2 then xmy = 1 else xmy = 0 end
|
||||
if zmyg == 2 then zmy = 1 else zmy = 0 end
|
||||
|
||||
-- If group == 3 then the mesecon only connects to input and output ports
|
||||
if xpg == 3 and mesecon:rules_link_bothdir(pos, xppos) then xp = 1 end
|
||||
if xmg == 3 and mesecon:rules_link_bothdir(pos, xmpos) then xm = 1 end
|
||||
if zpg == 3 and mesecon:rules_link_bothdir(pos, zppos) then zp = 1 end
|
||||
if zmg == 3 and mesecon:rules_link_bothdir(pos, zmpos) then zm = 1 end
|
||||
|
||||
if xpymg == 3 and mesecon:rules_link_bothdir(pos, xpympos) then xp = 1 end
|
||||
if xmymg == 3 and mesecon:rules_link_bothdir(pos, xmympos) then xm = 1 end
|
||||
if zpymg == 3 and mesecon:rules_link_bothdir(pos, zpympos) then zp = 1 end
|
||||
if zmymg == 3 and mesecon:rules_link_bothdir(pos, zmympos) then zm = 1 end
|
||||
|
||||
if xpyg == 3 then if mesecon:rules_link(pos, xpypos) then xpy = 1 end end
|
||||
if zpyg == 3 then if mesecon:rules_link(pos, zpypos) then zpy = 1 end end
|
||||
if xmyg == 3 then if mesecon:rules_link(pos, xmypos) then xmy = 1 end end
|
||||
if zmyg == 3 then if mesecon:rules_link(pos, zmypos) then zmy = 1 end 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 mesecon:rules_link_anydir(pos, xpypos) then xpy = 1 else xpy = 0 end
|
||||
if mesecon:rules_link_anydir(pos, zpypos) then zpy = 1 else zpy = 0 end
|
||||
if mesecon:rules_link_anydir(pos, xmypos) then xmy = 1 else xmy = 0 end
|
||||
if mesecon:rules_link_anydir(pos, zmypos) then zmy = 1 else zmy = 0 end
|
||||
|
||||
if xpy == 1 then xp = 1 end
|
||||
if zpy == 1 then zp = 1 end
|
||||
@ -310,19 +241,41 @@ function mesecon:update_autoconnect(pos, secondcall, replace_old)
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.registered_nodes["default:stone_with_mese"] == nil then
|
||||
|
||||
minetest.register_craft({
|
||||
output = '"mesecons:wire_00000000_off" 16',
|
||||
output = "mesecons:wire_00000000_off 18",
|
||||
recipe = {
|
||||
{'"default:mese"'},
|
||||
{"default:mese"},
|
||||
}
|
||||
})
|
||||
else
|
||||
|
||||
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,
|
||||
minetest.register_craft({
|
||||
type = "cooking",
|
||||
output = "mesecons:wire_00000000_off 2",
|
||||
recipe = "default:mese_crystal_fragment",
|
||||
cooktime = 3,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = "cooking",
|
||||
output = "mesecons:wire_00000000_off 18",
|
||||
recipe = "default:mese_crystal",
|
||||
cooktime = 15,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = "cooking",
|
||||
output = "mesecons:wire_00000000_off 162",
|
||||
recipe = "default:mese",
|
||||
cooktime = 30,
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
minetest.register_craft({
|
||||
type = "cooking",
|
||||
output = '"mesecons:wire_00000000_off" 16',
|
||||
recipe = "default:mese_crystal",
|
||||
})
|
||||
|
@ -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:switch", "mesecons_switch:mesecon_switch_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:mesecon_torch", "mesecons_torch:mesecon_torch_on")
|
||||
minetest.register_alias("mesecons:torch", "mesecons_torch:mesecon_torch_on")
|
||||
@ -23,10 +23,16 @@ minetest.register_alias("mesecons:mesecon_inverter", "mesecons_temperest:mesecon
|
||||
minetest.register_alias("mesecons:movestone", "mesecons_movestones:movestone")
|
||||
minetest.register_alias("mesecons:sticky_movestone", "mesecons_movestones:sticky_movestone")
|
||||
minetest.register_alias("mesecons:noteblock", "mesecons_noteblock:noteblock")
|
||||
minetest.register_alias("mesecons:microcontroller", "mesecons_microcontroller:microcontroller")
|
||||
minetest.register_alias("mesecons:microcontroller", "mesecons_microcontroller:microcontroller0000")
|
||||
minetest.register_alias("mesecons:delayer", "mesecons_delayer:delayer_off_1")
|
||||
minetest.register_alias("mesecons:solarpanel", "mesecons_solarpanel:solar_panel_off")
|
||||
|
||||
|
||||
--Backwards compatibility
|
||||
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")
|
||||
|
@ -13,6 +13,9 @@ minetest.register_node("mesecons_blinkyplant:blinky_plant_off", {
|
||||
type = "fixed",
|
||||
fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
|
||||
},
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.off
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_blinkyplant:blinky_plant_on", {
|
||||
@ -30,6 +33,9 @@ minetest.register_node("mesecons_blinkyplant:blinky_plant_on", {
|
||||
type = "fixed",
|
||||
fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
|
||||
},
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.on
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
@ -64,6 +70,3 @@ minetest.register_abm({
|
||||
mesecon:receptor_off(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
mesecon:add_receptor_node("mesecons_blinkyplant:blinky_plant_on")
|
||||
mesecon:add_receptor_node_off("mesecons_blinkyplant:blinky_plant_off")
|
||||
|
@ -1,4 +1,16 @@
|
||||
-- WALL BUTTON
|
||||
-- A button that when pressed emits power for 1 second
|
||||
-- and then turns off again
|
||||
|
||||
mesecon.button_turnoff = function (pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
if node.name=="mesecons_button:button_on" then --has not been dug
|
||||
mesecon:swap_node(pos, "mesecons_button:button_off")
|
||||
local rules = mesecon.rules.buttonlike_get(node)
|
||||
mesecon:receptor_off(pos, rules)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("mesecons_button:button_off", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
@ -25,9 +37,19 @@ minetest.register_node("mesecons_button:button_off", {
|
||||
{ -4/16, -2/16, 4/16, 4/16, 2/16, 6/16 } -- the button itself
|
||||
}
|
||||
},
|
||||
groups = {dig_immediate=2, mesecon = 3, mesecon_needs_receiver = 1},
|
||||
groups = {dig_immediate=2, mesecon_needs_receiver = 1},
|
||||
description = "Button",
|
||||
on_punch = function (pos, node)
|
||||
mesecon:swap_node(pos, "mesecons_button:button_on")
|
||||
mesecon:receptor_on(pos, mesecon.rules.buttonlike_get(node))
|
||||
minetest.after(1, mesecon.button_turnoff, pos)
|
||||
end,
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.off,
|
||||
rules = mesecon.rules.buttonlike_get
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_button:button_on", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
@ -55,57 +77,18 @@ minetest.register_node("mesecons_button:button_on", {
|
||||
{ -4/16, -2/16, 11/32, 4/16, 2/16, 6/16 }
|
||||
}
|
||||
},
|
||||
groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3, mesecon_needs_receiver = 1},
|
||||
groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon_needs_receiver = 1},
|
||||
drop = 'mesecons_button:button_off',
|
||||
description = "Button",
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.on,
|
||||
rules = mesecon.rules.buttonlike_get
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_on_punchnode(function(pos, node, puncher)
|
||||
if node.name == "mesecons_button:button_off" then
|
||||
minetest.env:add_node(pos, {name="mesecons_button:button_on",param2=node.param2})
|
||||
local rules=mesecon.button_get_rules(node.param2)
|
||||
mesecon:receptor_on(pos, rules)
|
||||
minetest.after(1, mesecon.button_turnoff, {pos=pos, param2=node.param2})
|
||||
end
|
||||
end)
|
||||
|
||||
mesecon.button_turnoff = function (params)
|
||||
if minetest.env:get_node(params.pos).name=="mesecons_button:button_on" then
|
||||
minetest.env:add_node(params.pos, {name="mesecons_button:button_off", param2=params.param2})
|
||||
local rules=mesecon.button_get_rules(params.param2)
|
||||
mesecon:receptor_off(params.pos, rules)
|
||||
end
|
||||
end
|
||||
|
||||
mesecon.button_get_rules = function(param2)
|
||||
local rules=mesecon:get_rules("button")
|
||||
if param2 == 2 then
|
||||
rules=mesecon:rotate_rules_left(rules)
|
||||
end
|
||||
if param2 == 3 then
|
||||
rules=mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules))
|
||||
end
|
||||
if param2 == 0 then
|
||||
rules=mesecon:rotate_rules_right(rules)
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
minetest.register_craft({
|
||||
output = '"mesecons_button:button_off" 2',
|
||||
recipe = {
|
||||
{'"group:mesecon_conductor_craftable"','"default:stone"'},
|
||||
}
|
||||
})
|
||||
|
||||
mesecon:add_rules("button", {
|
||||
{x = 1, y = 0, z = 0},
|
||||
{x = 1, y = 1, z = 0},
|
||||
{x = 1, y =-1, z = 0},
|
||||
{x = 1, y =-1, z = 1},
|
||||
{x = 1, y =-1, z =-1},
|
||||
{x = 2, y = 0, z = 0},})
|
||||
|
||||
mesecon:add_receptor_node_off("mesecons_button:button_off", nil, mesecon.button_get_rules)
|
||||
mesecon:add_receptor_node("mesecons_button:button_on", nil, mesecon.button_get_rules)
|
||||
|
||||
|
@ -1,3 +1,25 @@
|
||||
minetest.register_chatcommand("say", {
|
||||
params = "<text>",
|
||||
description = "Say <text> as the server",
|
||||
privs = {server=true},
|
||||
func = function(name, param)
|
||||
minetest.chat_send_all(param)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("tell", {
|
||||
params = "<name> <text>",
|
||||
description = "Say <text> to <name> privately",
|
||||
func = function(name, param)
|
||||
local found, _, target, message = param:find("^([^%s]+)%s+(.*)$")
|
||||
if found == nil then
|
||||
minetest.chat_send_player(name, "Invalid usage: " .. param)
|
||||
return
|
||||
end
|
||||
minetest.chat_send_player(target, name .. " whispers: " .. message)
|
||||
end
|
||||
})
|
||||
|
||||
local initialize_data = function(meta, player, command, param)
|
||||
meta:set_string("formspec",
|
||||
"invsize[9,6;]" ..
|
||||
@ -87,50 +109,12 @@ local resolve_player = function(name, pos)
|
||||
return name
|
||||
end
|
||||
|
||||
minetest.register_node("mesecons_commandblock:commandblock_off", {
|
||||
description = "Command Block",
|
||||
tiles = {"jeija_commandblock_off.png"},
|
||||
inventory_image = minetest.inventorycube("jeija_commandblock_off.png"),
|
||||
groups = {cracky=2, mesecon_effector_off=1, mesecon=2},
|
||||
on_construct = construct,
|
||||
after_place_node = after_place,
|
||||
on_receive_fields = receive_fields,
|
||||
can_dig = function(pos,player)
|
||||
local owner = minetest.env:get_meta(pos):get_string("owner")
|
||||
return owner == "" or owner == player:get_player_name()
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_commandblock:commandblock_on", {
|
||||
tiles = {"jeija_commandblock_on.png"},
|
||||
groups = {cracky=2, mesecon_effector_on=1, mesecon=2, not_in_creative_inventory=1},
|
||||
light_source = 10,
|
||||
drop = "mesecons_commandblock:commandblock_off",
|
||||
on_construct = construct,
|
||||
after_place_node = after_place,
|
||||
on_receive_fields = receive_fields,
|
||||
can_dig = function(pos,player)
|
||||
local owner = minetest.env:get_meta(pos):get_string("owner")
|
||||
return owner == "" or owner == player:get_player_name()
|
||||
end,
|
||||
})
|
||||
|
||||
mesecon:register_effector("mesecons_commandblock:commandblock_on", "mesecons_commandblock:commandblock_off")
|
||||
|
||||
local swap_node = function(pos, name)
|
||||
local node = minetest.env:get_node(pos)
|
||||
local data = minetest.env:get_meta(pos):to_table()
|
||||
node.name = name
|
||||
minetest.env:add_node(pos, node)
|
||||
minetest.env:get_meta(pos):from_table(data)
|
||||
end
|
||||
|
||||
mesecon:register_on_signal_on(function(pos, node)
|
||||
local commandblock_action_on = function(pos, node)
|
||||
if node.name ~= "mesecons_commandblock:commandblock_off" then
|
||||
return
|
||||
end
|
||||
|
||||
swap_node(pos, "mesecons_commandblock:commandblock_on")
|
||||
mesecon:swap_node(pos, "mesecons_commandblock:commandblock_on")
|
||||
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local command = minetest.chatcommands[meta:get_string("command")]
|
||||
@ -148,10 +132,44 @@ mesecon:register_on_signal_on(function(pos, node)
|
||||
end
|
||||
local player = resolve_player(meta:get_string("player"), pos)
|
||||
command.func(player, meta:get_string("param"))
|
||||
end)
|
||||
|
||||
mesecon:register_on_signal_off(function(pos, node)
|
||||
if node.name == "mesecons_commandblock:commandblock_on" then
|
||||
swap_node(pos, "mesecons_commandblock:commandblock_off")
|
||||
end
|
||||
end)
|
||||
|
||||
local commandblock_action_off = function(pos, node)
|
||||
if node.name == "mesecons_commandblock:commandblock_on" then
|
||||
mesecon:swap_node(pos, "mesecons_commandblock:commandblock_off")
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("mesecons_commandblock:commandblock_off", {
|
||||
description = "Command Block",
|
||||
tiles = {"jeija_commandblock_off.png"},
|
||||
inventory_image = minetest.inventorycube("jeija_commandblock_off.png"),
|
||||
groups = {cracky=2, mesecon_effector_off=1},
|
||||
on_construct = construct,
|
||||
after_place_node = after_place,
|
||||
on_receive_fields = receive_fields,
|
||||
can_dig = function(pos,player)
|
||||
local owner = minetest.env:get_meta(pos):get_string("owner")
|
||||
return owner == "" or owner == player:get_player_name()
|
||||
end,
|
||||
mesecons = {effector = {
|
||||
action_on = commandblock_action_on
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_commandblock:commandblock_on", {
|
||||
tiles = {"jeija_commandblock_on.png"},
|
||||
groups = {cracky=2, mesecon_effector_on=1, not_in_creative_inventory=1},
|
||||
light_source = 10,
|
||||
drop = "mesecons_commandblock:commandblock_off",
|
||||
on_construct = construct,
|
||||
after_place_node = after_place,
|
||||
on_receive_fields = receive_fields,
|
||||
can_dig = function(pos,player)
|
||||
local owner = minetest.env:get_meta(pos):get_string("owner")
|
||||
return owner == "" or owner == player:get_player_name()
|
||||
end,
|
||||
mesecons = {effector = {
|
||||
action_off = commandblock_action_off
|
||||
}}
|
||||
})
|
||||
|
2
mesecons_compatibility/depends.txt
Normal file
@ -0,0 +1,2 @@
|
||||
mesecons
|
||||
doors
|
165
mesecons_compatibility/init.lua
Normal file
@ -0,0 +1,165 @@
|
||||
doors = {}
|
||||
|
||||
-- Registers a door - REDEFINITION ONLY | DOORS MOD MUST HAVE BEEN LOADED BEFORE
|
||||
-- name: The name of the door
|
||||
-- def: a table with the folowing fields:
|
||||
-- description
|
||||
-- inventory_image
|
||||
-- groups
|
||||
-- tiles_bottom: the tiles of the bottom part of the door {front, side}
|
||||
-- tiles_top: the tiles of the bottom part of the door {front, side}
|
||||
-- If the following fields are not defined the default values are used
|
||||
-- node_box_bottom
|
||||
-- node_box_top
|
||||
-- selection_box_bottom
|
||||
-- selection_box_top
|
||||
-- only_placer_can_open: if true only the player who placed the door can
|
||||
-- open it
|
||||
|
||||
function doors:register_door(name, def)
|
||||
def.groups.not_in_creative_inventory = 1
|
||||
|
||||
local box = {{-0.5, -0.5, -0.5, 0.5, 0.5, -0.5+1.5/16}}
|
||||
|
||||
if not def.node_box_bottom then
|
||||
def.node_box_bottom = box
|
||||
end
|
||||
if not def.node_box_top then
|
||||
def.node_box_top = box
|
||||
end
|
||||
if not def.selection_box_bottom then
|
||||
def.selection_box_bottom= box
|
||||
end
|
||||
if not def.selection_box_top then
|
||||
def.selection_box_top = box
|
||||
end
|
||||
|
||||
local tt = def.tiles_top
|
||||
local tb = def.tiles_bottom
|
||||
|
||||
local function after_dig_node(pos, name)
|
||||
if minetest.env:get_node(pos).name == name then
|
||||
minetest.env:remove_node(pos)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_rightclick(pos, dir, check_name, replace, replace_dir, params)
|
||||
pos.y = pos.y+dir
|
||||
if not minetest.env:get_node(pos).name == check_name then
|
||||
return
|
||||
end
|
||||
local p2 = minetest.env:get_node(pos).param2
|
||||
p2 = params[p2+1]
|
||||
|
||||
local meta = minetest.env:get_meta(pos):to_table()
|
||||
minetest.env:set_node(pos, {name=replace_dir, param2=p2})
|
||||
minetest.env:get_meta(pos):from_table(meta)
|
||||
|
||||
pos.y = pos.y-dir
|
||||
meta = minetest.env:get_meta(pos):to_table()
|
||||
minetest.env:set_node(pos, {name=replace, param2=p2})
|
||||
minetest.env:get_meta(pos):from_table(meta)
|
||||
end
|
||||
|
||||
local function on_mesecons_signal_open (pos, node)
|
||||
on_rightclick(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0})
|
||||
end
|
||||
|
||||
local function on_mesecons_signal_close (pos, node)
|
||||
on_rightclick(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2})
|
||||
end
|
||||
|
||||
local function check_player_priv(pos, player)
|
||||
if not def.only_placer_can_open then
|
||||
return true
|
||||
end
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local pn = player:get_player_name()
|
||||
return meta:get_string("doors_owner") == pn
|
||||
end
|
||||
|
||||
minetest.register_node(":"..name.."_b_1", {
|
||||
tiles = {tb[2], tb[2], tb[2], tb[2], tb[1], tb[1].."^[transformfx"},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drop = name,
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = def.node_box_bottom
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = def.selection_box_bottom
|
||||
},
|
||||
groups = def.groups,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
pos.y = pos.y+1
|
||||
after_dig_node(pos, name.."_t_1")
|
||||
end,
|
||||
|
||||
on_rightclick = function(pos, node, puncher)
|
||||
if check_player_priv(pos, puncher) then
|
||||
on_rightclick(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0})
|
||||
end
|
||||
end,
|
||||
|
||||
mesecons = {effector = {
|
||||
action_on = on_mesecons_signal_open
|
||||
}},
|
||||
|
||||
can_dig = check_player_priv,
|
||||
})
|
||||
|
||||
minetest.register_node(":"..name.."_b_2", {
|
||||
tiles = {tb[2], tb[2], tb[2], tb[2], tb[1].."^[transformfx", tb[1]},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drop = name,
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = def.node_box_bottom
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = def.selection_box_bottom
|
||||
},
|
||||
groups = def.groups,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
pos.y = pos.y+1
|
||||
after_dig_node(pos, name.."_t_2")
|
||||
end,
|
||||
|
||||
on_rightclick = function(pos, node, puncher)
|
||||
if check_player_priv(pos, puncher) then
|
||||
on_rightclick(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2})
|
||||
end
|
||||
end,
|
||||
|
||||
mesecons = {effector = {
|
||||
action_off = on_mesecons_signal_close
|
||||
}},
|
||||
|
||||
can_dig = check_player_priv,
|
||||
})
|
||||
end
|
||||
|
||||
doors:register_door("doors:door_wood", {
|
||||
description = "Wooden Door",
|
||||
inventory_image = "door_wood.png",
|
||||
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,door=1},
|
||||
tiles_bottom = {"door_wood_b.png", "door_brown.png"},
|
||||
tiles_top = {"door_wood_a.png", "door_brown.png"},
|
||||
})
|
||||
|
||||
doors:register_door("doors:door_steel", {
|
||||
description = "Steel Door",
|
||||
inventory_image = "door_steel.png",
|
||||
groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2,door=1},
|
||||
tiles_bottom = {"door_steel_b.png", "door_grey.png"},
|
||||
tiles_top = {"door_steel_a.png", "door_grey.png"},
|
||||
only_placer_can_open = true,
|
||||
})
|
@ -1,11 +1,62 @@
|
||||
-- Function that get the input/output rules of the delayer
|
||||
local delayer_get_output_rules = function(node)
|
||||
local rules = {{x = 0, y = 0, z = 1}}
|
||||
for i = 0, node.param2 do
|
||||
rules = mesecon:rotate_rules_left(rules)
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
local delayer_get_input_rules = function(node)
|
||||
local rules = {{x = 0, y = 0, z = -1}}
|
||||
for i = 0, node.param2 do
|
||||
rules = mesecon:rotate_rules_left(rules)
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
-- Functions that are called after the delay time
|
||||
|
||||
local delayer_turnon = function(params)
|
||||
local rules = delayer_get_output_rules(params.node)
|
||||
mesecon:receptor_on(params.pos, rules)
|
||||
end
|
||||
|
||||
local delayer_turnoff = function(params)
|
||||
local rules = delayer_get_output_rules(params.node)
|
||||
mesecon:receptor_off(params.pos, rules)
|
||||
end
|
||||
|
||||
local delayer_activate = function(pos, node)
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
local time = def.delayer_time
|
||||
mesecon:swap_node(pos, def.delayer_onstate)
|
||||
minetest.after(time, delayer_turnon , {pos = pos, node = node})
|
||||
end
|
||||
|
||||
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
|
||||
local groups = {}
|
||||
if i == 1 then
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2, mesecon = 3}
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2}
|
||||
else
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1, mesecon = 3}
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1}
|
||||
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
|
||||
|
||||
{ -2/16, -7/16, -4/16, 2/16, -26/64, -3/16 }, -- the jeweled "on" indicator
|
||||
@ -46,6 +97,31 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = true,
|
||||
drop = 'mesecons_delayer:delayer_off_1',
|
||||
on_punch = function (pos, node)
|
||||
if node.name=="mesecons_delayer:delayer_off_1" then
|
||||
mesecon:swap_node(pos,"mesecons_delayer:delayer_off_2")
|
||||
elseif node.name=="mesecons_delayer:delayer_off_2" then
|
||||
mesecon:swap_node(pos,"mesecons_delayer:delayer_off_3")
|
||||
elseif node.name=="mesecons_delayer:delayer_off_3" then
|
||||
mesecon:swap_node(pos,"mesecons_delayer:delayer_off_4")
|
||||
elseif node.name=="mesecons_delayer:delayer_off_4" then
|
||||
mesecon:swap_node(pos,"mesecons_delayer:delayer_off_1")
|
||||
end
|
||||
end,
|
||||
delayer_time = delaytime,
|
||||
delayer_onstate = "mesecons_delayer:delayer_on_"..tostring(i),
|
||||
mesecons = {
|
||||
receptor =
|
||||
{
|
||||
state = mesecon.state.off,
|
||||
rules = delayer_get_output_rules
|
||||
},
|
||||
effector =
|
||||
{
|
||||
rules = delayer_get_input_rules,
|
||||
action_on = delayer_activate
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@ -69,147 +145,44 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), {
|
||||
type = "fixed",
|
||||
fixed = boxes
|
||||
},
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1, mesecon = 3},
|
||||
groups = {bendy = 2, snappy = 1, dig_immediate = 2, not_in_creative_inventory = 1},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = true,
|
||||
drop = 'mesecons_delayer:delayer_off_1',
|
||||
on_punch = function (pos, node)
|
||||
if node.name=="mesecons_delayer:delayer_on_1" then
|
||||
mesecon:swap_node(pos,"mesecons_delayer:delayer_on_2")
|
||||
elseif node.name=="mesecons_delayer:delayer_on_2" then
|
||||
mesecon:swap_node(pos,"mesecons_delayer:delayer_on_3")
|
||||
elseif node.name=="mesecons_delayer:delayer_on_3" then
|
||||
mesecon:swap_node(pos,"mesecons_delayer:delayer_on_4")
|
||||
elseif node.name=="mesecons_delayer:delayer_on_4" then
|
||||
mesecon:swap_node(pos,"mesecons_delayer:delayer_on_1")
|
||||
end
|
||||
end,
|
||||
delayer_time = delaytime,
|
||||
delayer_offstate = "mesecons_delayer:delayer_off_"..tostring(i),
|
||||
mesecons = {
|
||||
receptor =
|
||||
{
|
||||
state = mesecon.state.on,
|
||||
rules = delayer_get_output_rules
|
||||
},
|
||||
effector =
|
||||
{
|
||||
rules = delayer_get_input_rules,
|
||||
action_off = delayer_deactivate
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
minetest.register_on_punchnode(function (pos, node)
|
||||
mesecon.delayer_get_output_rules(node.param2)
|
||||
if node.name=="mesecons_delayer:delayer_off_1" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_2", param2=node.param2})
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_off_2" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_3", param2=node.param2})
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_off_3" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_4", param2=node.param2})
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_off_4" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1", param2=node.param2})
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_punchnode(function (pos, node)
|
||||
mesecon.delayer_get_output_rules(node.param2)
|
||||
if node.name=="mesecons_delayer:delayer_on_1" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_2", param2=node.param2})
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_on_2" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_3", param2=node.param2})
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_on_3" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_4", param2=node.param2})
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_on_4" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1", param2=node.param2})
|
||||
end
|
||||
end)
|
||||
|
||||
mesecon.delayer_update = function(pos, node)
|
||||
if string.find(node.name, "mesecons_delayer:delayer_off")~=nil then
|
||||
local time = 0
|
||||
if node.name=="mesecons_delayer:delayer_off_1" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1", param2=node.param2})
|
||||
time=0.1
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_off_2" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_2", param2=node.param2})
|
||||
time=0.3
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_off_3" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_3", param2=node.param2})
|
||||
time=0.5
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_off_4" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_4", param2=node.param2})
|
||||
time=1
|
||||
end
|
||||
minetest.after(time, mesecon.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
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1", param2=node.param2})
|
||||
time=0.1
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_on_2" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_2", param2=node.param2})
|
||||
time=0.3
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_on_3" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_3", param2=node.param2})
|
||||
time=0.5
|
||||
end
|
||||
if node.name=="mesecons_delayer:delayer_on_4" then
|
||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_4", param2=node.param2})
|
||||
time=1
|
||||
end
|
||||
minetest.after(time, mesecon.delayer_turnoff, {pos=pos, param2=node.param2})
|
||||
end
|
||||
end
|
||||
|
||||
mesecon:register_on_signal_change(mesecon.delayer_update)
|
||||
|
||||
mesecon.delayer_turnon=function(params)
|
||||
local rules = mesecon.delayer_get_output_rules(params.param2)
|
||||
mesecon:receptor_on(params.pos, rules)
|
||||
end
|
||||
|
||||
mesecon.delayer_turnoff=function(params)
|
||||
local rules = mesecon.delayer_get_output_rules(params.param2)
|
||||
mesecon:receptor_off(params.pos, rules)
|
||||
end
|
||||
|
||||
mesecon.delayer_get_output_rules = function(param2)
|
||||
local rules = {}
|
||||
if param2 == 0 then
|
||||
table.insert(rules, {x = 1, y = 0, z = 0})
|
||||
elseif param2 == 2 then
|
||||
table.insert(rules, {x =-1, y = 0, z = 0})
|
||||
elseif param2 == 1 then
|
||||
table.insert(rules, {x = 0, y = 0, z =-1})
|
||||
elseif param2 == 3 then
|
||||
table.insert(rules, {x = 0, y = 0, z = 1})
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
mesecon.delayer_get_input_rules = function(param2)
|
||||
local rules = {}
|
||||
if param2 == 0 then
|
||||
table.insert(rules, {x =-1, y = 0, z = 0})
|
||||
elseif param2 == 2 then
|
||||
table.insert(rules, {x = 1, y = 0, z = 0})
|
||||
elseif param2 == 1 then
|
||||
table.insert(rules, {x = 0, y = 0, z = 1})
|
||||
elseif param2 == 3 then
|
||||
table.insert(rules, {x = 0, y = 0, z =-1})
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
all_rules = {{x = 1, y = 0, z = 0}, {x =-1, y = 0, z = 0}, {x = 0, y = 0, z =-1}, {x = 0, y = 0, z = 1}} --required to check if a newly placed should be turned on
|
||||
|
||||
mesecon:add_receptor_node("mesecons_delayer:delayer_on_1", all_rules, mesecon.delayer_get_output_rules)
|
||||
mesecon:add_receptor_node("mesecons_delayer:delayer_on_2", all_rules, mesecon.delayer_get_output_rules)
|
||||
mesecon:add_receptor_node("mesecons_delayer:delayer_on_3", all_rules, mesecon.delayer_get_output_rules)
|
||||
mesecon:add_receptor_node("mesecons_delayer:delayer_on_4", all_rules, mesecon.delayer_get_output_rules)
|
||||
|
||||
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_1", all_rules, mesecon.delayer_get_output_rules)
|
||||
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_2", all_rules, mesecon.delayer_get_output_rules)
|
||||
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_3", all_rules, mesecon.delayer_get_output_rules)
|
||||
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_4", all_rules, mesecon.delayer_get_output_rules)
|
||||
|
||||
mesecon:register_effector("mesecons_delayer:delayer_on_1", "mesecons_delayer:delayer_off_1", all_rules, mesecon.delayer_get_input_rules)
|
||||
mesecon:register_effector("mesecons_delayer:delayer_on_2", "mesecons_delayer:delayer_off_2", all_rules, mesecon.delayer_get_input_rules)
|
||||
mesecon:register_effector("mesecons_delayer:delayer_on_3", "mesecons_delayer:delayer_off_3", all_rules, mesecon.delayer_get_input_rules)
|
||||
mesecon:register_effector("mesecons_delayer:delayer_on_4", "mesecons_delayer:delayer_off_4", all_rules, mesecon.delayer_get_input_rules)
|
||||
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"},
|
||||
}
|
||||
})
|
||||
|
@ -1,19 +1,27 @@
|
||||
--SHORT RANGE DETECTORS
|
||||
-- Object detector
|
||||
-- Detects all entities in a certain radius
|
||||
-- The radius can be specified in mesecons/settings.lua
|
||||
|
||||
minetest.register_node("mesecons_detector:object_detector_off", {
|
||||
tiles = {"default_steel_block.png", "default_steel_block.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png"},
|
||||
paramtype = "light",
|
||||
walkable = true,
|
||||
groups = {cracky=3, mesecon = 2},
|
||||
groups = {cracky=3},
|
||||
description="Player Detector",
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.off
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_detector:object_detector_on", {
|
||||
tiles = {"default_steel_block.png", "default_steel_block.png", "jeija_object_detector_on.png", "jeija_object_detector_on.png", "jeija_object_detector_on.png", "jeija_object_detector_on.png"},
|
||||
paramtype = "light",
|
||||
walkable = true,
|
||||
groups = {cracky=3,not_in_creative_inventory=1, mesecon = 2},
|
||||
groups = {cracky=3,not_in_creative_inventory=1},
|
||||
drop = 'mesecons_detector:object_detector_off',
|
||||
description="Player Detector",
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.on
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
@ -30,9 +38,9 @@ minetest.register_abm(
|
||||
interval = 1.0,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local objs = minetest.env:get_objects_inside_radius(pos, 6)
|
||||
local objs = minetest.env:get_objects_inside_radius(pos, OBJECT_DETECTOR_RADIUS)
|
||||
for k, obj in pairs(objs) do
|
||||
if obj:get_entity_name()~="mesecons_pistons:piston_pusher_sticky" and obj:get_entity_name()~="mesecons_pistons:piston_pusher_normal" and obj:get_player_name()~=nil then -- Detected object is not piston pusher - will be changed if every entity has a type (like entity_type=mob)
|
||||
if obj:get_entity_name()~="mesecons_pistons:piston_pusher_sticky" and obj:get_entity_name()~="mesecons_pistons:piston_pusher_normal" and obj:get_player_name()~=nil then
|
||||
if minetest.env:get_node({x=pos.x, y=pos.y-1, z=pos.z}).name=="default:sign_wall" then
|
||||
if obj:get_player_name()~=minetest.env:get_meta({x=pos.x, y=pos.y-1, z=pos.z}):get_string("text") then
|
||||
return
|
||||
@ -40,7 +48,7 @@ minetest.register_abm(
|
||||
end
|
||||
local objpos=obj:getpos()
|
||||
minetest.env:add_node(pos, {name="mesecons_detector:object_detector_on"})
|
||||
mesecon:receptor_on(pos, mesecon:get_rules("pressureplate"))
|
||||
mesecon:receptor_on(pos)
|
||||
end
|
||||
end
|
||||
end,
|
||||
@ -51,7 +59,7 @@ minetest.register_abm(
|
||||
interval = 1.0,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local objs = minetest.env:get_objects_inside_radius(pos, 6)
|
||||
local objs = minetest.env:get_objects_inside_radius(pos, OBJECT_DETECTOR_RADIUS)
|
||||
local objectfound=0
|
||||
for k, obj in pairs(objs) do
|
||||
if obj:get_entity_name()~="mesecons_pistons:piston_pusher_sticky" and obj:get_entity_name()~="mesecons_pistons:piston_pusher_normal" and obj~=nil
|
||||
@ -68,10 +76,7 @@ minetest.register_abm(
|
||||
end
|
||||
if objectfound==0 then
|
||||
minetest.env:add_node(pos, {name="mesecons_detector:object_detector_off"})
|
||||
mesecon:receptor_off(pos, mesecon:get_rules("pressureplate"))
|
||||
mesecon:receptor_off(pos)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
mesecon:add_receptor_node("mesecons_detector:object_detector_on", mesecon:get_rules("pressureplate"))
|
||||
mesecon:add_receptor_node_off("mesecons_detector:object_detector_off", mesecon:get_rules("pressureplate"))
|
||||
|
@ -1,4 +0,0 @@
|
||||
Please note:
|
||||
The mesecons modules in here have been disabled for various reasons:
|
||||
They are old and deprecated, are not needed anymore or are buggy atm.
|
||||
You can create a module out of them, but it is not recommended to use any of them.
|
@ -1 +0,0 @@
|
||||
--read README
|
@ -1,2 +0,0 @@
|
||||
mesecons
|
||||
mesecons_materials
|
@ -1,313 +0,0 @@
|
||||
--COMMON WIRELESS FUNCTIONS
|
||||
|
||||
mesecon.wireless_receivers={}
|
||||
|
||||
function mesecon:read_wlre_from_file()
|
||||
print "[MESEcons] Reading Mesecon Data..."
|
||||
mesecon_file=io.open(minetest.get_modpath("jeija").."/mesecon_data", "r")
|
||||
if mesecon_file==nil then return end
|
||||
local row=mesecon_file:read()
|
||||
local i=1
|
||||
while row~=nil do
|
||||
mesecon.wireless_receivers[i]={}
|
||||
mesecon.wireless_receivers[i].pos={}
|
||||
mesecon.wireless_receivers[i].pos.x=tonumber(mesecon_file:read())
|
||||
mesecon.wireless_receivers[i].pos.y=tonumber(mesecon_file:read())
|
||||
mesecon.wireless_receivers[i].pos.z=tonumber(mesecon_file:read())
|
||||
mesecon.wireless_receivers[i].channel=mesecon_file:read()
|
||||
mesecon.wireless_receivers[i].requested_state=tonumber(mesecon_file:read())
|
||||
mesecon.wireless_receivers[i].inverting=tonumber(mesecon_file:read())
|
||||
i=i+1
|
||||
row=mesecon_file:read()
|
||||
end
|
||||
mesecon_file:close()
|
||||
print "[MESEcons] Finished Reading Mesecon Data..."
|
||||
end
|
||||
|
||||
|
||||
function mesecon:register_wireless_receiver(pos, inverting)
|
||||
local i = 1
|
||||
repeat
|
||||
if mesecon.wireless_receivers[i]==nil then break end
|
||||
i=i+1
|
||||
until false
|
||||
|
||||
|
||||
local node_under_pos={}
|
||||
node_under_pos.x=pos.x
|
||||
node_under_pos.y=pos.y
|
||||
node_under_pos.z=pos.z
|
||||
|
||||
node_under_pos.y=node_under_pos.y-1
|
||||
local node_under=minetest.env:get_node(node_under_pos)
|
||||
mesecon.wireless_receivers[i]={}
|
||||
mesecon.wireless_receivers[i].pos={}
|
||||
mesecon.wireless_receivers[i].pos.x=pos.x
|
||||
mesecon.wireless_receivers[i].pos.y=pos.y
|
||||
mesecon.wireless_receivers[i].pos.z=pos.z
|
||||
mesecon.wireless_receivers[i].channel=node_under.name
|
||||
mesecon.wireless_receivers[i].requested_state=0
|
||||
mesecon.wireless_receivers[i].inverting=inverting
|
||||
end
|
||||
|
||||
function mesecon:remove_wireless_receiver(pos)
|
||||
local i = 1
|
||||
while mesecon.wireless_receivers[i]~=nil do
|
||||
if mesecon.wireless_receivers[i].pos.x==pos.x and
|
||||
mesecon.wireless_receivers[i].pos.y==pos.y and
|
||||
mesecon.wireless_receivers[i].pos.z==pos.z then
|
||||
mesecon.wireless_receivers[i]=nil
|
||||
break
|
||||
end
|
||||
i=i+1
|
||||
end
|
||||
end
|
||||
|
||||
function mesecon:set_wlre_channel(pos, channel)
|
||||
--local i = 1
|
||||
--while mesecon.wireless_receivers[i]~=nil do
|
||||
-- if tonumber(mesecon.wireless_receivers[i].pos.x)==tonumber(pos.x) and
|
||||
-- tonumber(mesecon.wireless_receivers[i].pos.y)==tonumber(pos.y) and
|
||||
-- tonumber(mesecon.wireless_receivers[i].pos.z)==tonumber(pos.z) then
|
||||
-- mesecon.wireless_receivers[i].channel=channel
|
||||
-- break
|
||||
-- end
|
||||
-- i=i+1
|
||||
--end
|
||||
local wlre=mesecon:get_wlre(pos)
|
||||
if wlre~=nil then
|
||||
wlre.channel=channel
|
||||
end
|
||||
end
|
||||
|
||||
function mesecon:get_wlre(pos)
|
||||
local i=1
|
||||
while mesecon.wireless_receivers[i]~=nil do
|
||||
if mesecon.wireless_receivers[i].pos.x==pos.x and
|
||||
mesecon.wireless_receivers[i].pos.y==pos.y and
|
||||
mesecon.wireless_receivers[i].pos.z==pos.z then
|
||||
return mesecon.wireless_receivers[i]
|
||||
end
|
||||
i=i+1
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_placenode(function(pos, newnode, placer)
|
||||
pos.y=pos.y+1
|
||||
if minetest.env:get_node(pos).name == "mesecons_wireless:wireless_receiver_off" or
|
||||
minetest.env:get_node(pos).name == "mesecons_wireless:wireless_receiver_on" or
|
||||
minetest.env:get_node(pos).name == "mesecons_wireless:wireless_inverter_off" or
|
||||
minetest.env:get_node(pos).name == "mesecons_wireless:wireless_inverter_on" then
|
||||
mesecon:set_wlre_channel(pos, newnode.name)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_dignode(
|
||||
function(pos, oldnode, digger)
|
||||
local channel
|
||||
pos.y=pos.y+1
|
||||
if minetest.env:get_node(pos).name == "mesecons_wireless:wireless_receiver_on" or
|
||||
minetest.env:get_node(pos).name == "mesecons_wireless:wireless_receiver_off" or
|
||||
minetest.env:get_node(pos).name == "mesecons_wireless:wireless_inverter_on" or
|
||||
minetest.env:get_node(pos).name == "mesecons_wireless:wireless_inverter_off" then
|
||||
mesecon:set_wlre_channel(pos, "air")
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
minetest.register_abm(
|
||||
{nodenames = {"mesecons_wireless:wireless_receiver_on", "mesecons_wireless:wireless_receiver_off",
|
||||
"mesecons_wireless:wireless_inverter_on", "mesecons_wireless:wireless_inverter_off"},
|
||||
interval = 1.0,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local wlre=mesecon:get_wlre(pos)
|
||||
if (wlre==nil) then return end
|
||||
|
||||
if node.name=="mesecons_wireless:wireless_receiver_on" and wlre.requested_state==0 then
|
||||
minetest.env:add_node(pos, {name="mesecons_wireless:wireless_receiver_off"})
|
||||
mesecon:receptor_off(pos)
|
||||
end
|
||||
if node.name=="mesecons_wireless:wireless_receiver_off" and wlre.requested_state==1 then
|
||||
minetest.env:add_node(pos, {name="mesecons_wireless:wireless_receiver_on"})
|
||||
mesecon:receptor_on(pos)
|
||||
end
|
||||
if node.name=="mesecons_wireless:wireless_inverter_off" and wlre.requested_state==0 and wlre.inverting==1 then
|
||||
minetest.env:add_node(pos, {name="mesecons_wireless:wireless_inverter_on"})
|
||||
mesecon:receptor_on(pos)
|
||||
end
|
||||
if node.name=="mesecons_wireless:wireless_inverter_on" and wlre.requested_state==1 and wlre.inverting==1 then
|
||||
minetest.env:add_node(pos, {name="mesecons_wireless:wireless_inverter_off"})
|
||||
mesecon:receptor_off(pos)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
--WIRELESS RECEIVER
|
||||
|
||||
minetest.register_node("mesecons_wireless:wireless_receiver_off", {
|
||||
tile_images = {"jeija_wireless_receiver_tb_off.png", "jeija_wireless_receiver_tb_off.png", "jeija_wireless_receiver_off.png", "jeija_wireless_receiver_off.png", "jeija_wireless_receiver_off.png", "jeija_wireless_receiver_off.png"},
|
||||
inventory_image = minetest.inventorycube("jeija_wireless_receiver_off.png"),
|
||||
groups = {choppy=2},
|
||||
description="Wireless Receiver",
|
||||
after_place_node = function(pos)
|
||||
mesecon:register_wireless_receiver(pos, 0)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
mesecon:remove_wireless_receiver(pos)
|
||||
mesecon:receptor_off(pos)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_wireless:wireless_receiver_on", {
|
||||
tile_images = {"jeija_wireless_receiver_tb_on.png", "jeija_wireless_receiver_tb_on.png", "jeija_wireless_receiver_on.png", "jeija_wireless_receiver_on.png", "jeija_wireless_receiver_on.png", "jeija_wireless_receiver_on.png"},
|
||||
inventory_image = minetest.inventorycube("jeija_wireless_receiver_on.png"),
|
||||
groups = {choppy=2},
|
||||
drop = 'mesecons_wireless:wireless_receiver_off',
|
||||
description="Wireless Receiver",
|
||||
after_place_node = function(pos)
|
||||
mesecon:register_wireless_receiver(pos, 0)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
mesecon:remove_wireless_receiver(pos)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = '"mesecons_wireless:wireless_receiver_off" 2',
|
||||
recipe = {
|
||||
{'', "group:mesecon_conductor_craftable", ''},
|
||||
{'', "group:mesecon_conductor_craftable", ''},
|
||||
{'', "mesecons_materials:ic", ''},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_abm( -- SAVE WIRELESS RECEIVERS TO FILE
|
||||
{nodenames = {"mesecons_wireless:wireless_receiver_off", "mesecons_wireless:wireless_receiver_on", "mesecons_wireless:wireless_inverter_on", "mesecons_wireless:wireless_inverter_off"},
|
||||
interval = 10,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local mesecon_file = io.open(minetest.get_modpath("jeija").."/mesecon_data", "w")
|
||||
local i=1
|
||||
while mesecon.wireless_receivers[i]~=nil do
|
||||
mesecon_file:write("NEXT\n")
|
||||
mesecon_file:write(mesecon.wireless_receivers[i].pos.x.."\n")
|
||||
mesecon_file:write(mesecon.wireless_receivers[i].pos.y.."\n")
|
||||
mesecon_file:write(mesecon.wireless_receivers[i].pos.z.."\n")
|
||||
mesecon_file:write(mesecon.wireless_receivers[i].channel.."\n")
|
||||
mesecon_file:write(mesecon.wireless_receivers[i].requested_state.."\n")
|
||||
mesecon_file:write(mesecon.wireless_receivers[i].inverting.."\n")
|
||||
i=i+1
|
||||
end
|
||||
mesecon_file:close()
|
||||
end,
|
||||
})
|
||||
|
||||
mesecon:add_receptor_node("mesecons_wireless:wireless_receiver_on")
|
||||
mesecon:add_receptor_node_off("mesecons_wireless:wireless_receiver_off")
|
||||
|
||||
-- WIRELESS INVERTER OFF/ON BELONGS TO THE OUTPUT STATE (ON=INPUT OFF)
|
||||
|
||||
minetest.register_node("mesecons_wireless:wireless_inverter_off", {
|
||||
tile_images = {"jeija_wireless_inverter_tb.png", "jeija_wireless_inverter_tb.png", "jeija_wireless_inverter_off.png", "jeija_wireless_inverter_off.png", "jeija_wireless_inverter_off.png", "jeija_wireless_inverter_off.png"},
|
||||
inventory_image = minetest.inventorycube("jeija_wireless_inverter_off.png"),
|
||||
groups = {choppy=2},
|
||||
drop = 'mesecons_wireless:wireless_inverter_on',
|
||||
description = "Wireless Inverter",
|
||||
after_place_node = function(pos)
|
||||
mesecon:register_wireless_receiver(pos, 1)
|
||||
mesecon:receptor_on(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
mesecon:remove_wireless_receiver(pos)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_wireless:wireless_inverter_on", {
|
||||
tile_images = {"jeija_wireless_inverter_tb.png", "jeija_wireless_inverter_tb.png", "jeija_wireless_inverter_on.png", "jeija_wireless_inverter_on.png", "jeija_wireless_inverter_on.png", "jeija_wireless_inverter_on.png"},
|
||||
inventory_image = minetest.inventorycube("jeija_wireless_inverter_on.png"),
|
||||
groups = {choppy=2},
|
||||
description = "Wireless Inverter",
|
||||
after_place_node = function(pos)
|
||||
mesecon:register_wireless_receiver(pos, 1)
|
||||
mesecon:receptor_on(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
mesecon:remove_wireless_receiver(pos)
|
||||
mesecon:receptor_off(pos)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = '"mesecons_wireless:wireless_inverter_off" 2',
|
||||
recipe = {
|
||||
{'', 'default:steel_ingot', ''},
|
||||
{'mesecons_materials:ic', 'group:mesecon_conductor_craftable', 'mesecons_materials:ic'},
|
||||
{'', 'group:mesecon_conductor_craftable', ''},
|
||||
}
|
||||
})
|
||||
|
||||
mesecon:add_receptor_node("mesecons_wireless:wireless_inverter_on")
|
||||
mesecon:add_receptor_node_off("mesecons_wireless:wireless_inverter_off")
|
||||
|
||||
-- WIRELESS TRANSMITTER
|
||||
|
||||
function mesecon:wireless_transmit(channel, senderstate)
|
||||
local i = 1
|
||||
while mesecon.wireless_receivers[i]~=nil do
|
||||
if mesecon.wireless_receivers[i].channel==channel then
|
||||
if senderstate==1 then
|
||||
mesecon.wireless_receivers[i].requested_state=1
|
||||
elseif senderstate==0 then
|
||||
mesecon.wireless_receivers[i].requested_state=0
|
||||
end
|
||||
end
|
||||
i=i+1
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("mesecons_wireless:wireless_transmitter_on", {
|
||||
tile_images = {"jeija_wireless_transmitter_tb.png", "jeija_wireless_transmitter_tb.png", "jeija_wireless_transmitter_on.png", "jeija_wireless_transmitter_on.png", "jeija_wireless_transmitter_on.png", "jeija_wireless_transmitter_on.png"},
|
||||
inventory_image = minetest.inventorycube("jeija_wireless_transmitter_on.png"),
|
||||
groups = {choppy=2},
|
||||
drop = {'"mesecons_wireless:wireless_transmitter_off" 1'},
|
||||
description="Wireless Transmitter",
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_wireless:wireless_transmitter_off", {
|
||||
tile_images = {"jeija_wireless_transmitter_tb.png", "jeija_wireless_transmitter_tb.png", "jeija_wireless_transmitter_off.png", "jeija_wireless_transmitter_off.png", "jeija_wireless_transmitter_off.png", "jeija_wireless_transmitter_off.png"},
|
||||
inventory_image = minetest.inventorycube("jeija_wireless_transmitter_off.png"),
|
||||
groups = {choppy=2},
|
||||
description="Wireless Transmitter",
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = '"mesecons_wireless:wireless_transmitter_off" 2',
|
||||
recipe = {
|
||||
{'default:steel_ingot', 'group:mesecon_conductor_craftable', 'default:steel_ingot'},
|
||||
{'', 'group:mesecon_conductor_craftable', ''},
|
||||
{'', 'mesecons_materials:ic', ''},
|
||||
}
|
||||
})
|
||||
|
||||
mesecon:register_on_signal_on(function(pos, node)
|
||||
if node.name=="mesecons_wireless:wireless_transmitter_off" then
|
||||
minetest.env:add_node(pos, {name="mesecons_wireless:wireless_transmitter_on"})
|
||||
local node_under_pos=pos
|
||||
node_under_pos.y=node_under_pos.y-1
|
||||
local node_under=minetest.env:get_node(node_under_pos)
|
||||
mesecon:wireless_transmit(node_under.name, 1)
|
||||
end
|
||||
end)
|
||||
|
||||
mesecon:register_on_signal_off(function(pos, node)
|
||||
if node.name=="mesecons_wireless:wireless_transmitter_on" then
|
||||
minetest.env:add_node(pos, {name="mesecons_wireless:wireless_transmitter_off"})
|
||||
local node_under_pos=pos
|
||||
node_under_pos.y=node_under_pos.y-1
|
||||
local node_under=minetest.env:get_node(node_under_pos)
|
||||
mesecon:wireless_transmit(node_under.name, 0)
|
||||
end
|
||||
end)
|
||||
|
||||
mesecon:read_wlre_from_file()
|
83
mesecons_extrawires/corner.lua
Normal 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", ""},
|
||||
}
|
||||
})
|
@ -1,46 +1,16 @@
|
||||
for x=-1, 1 do for z=-1, 1 do
|
||||
rules = {}
|
||||
nodename = "mesecons_extrawires:crossing"
|
||||
if x == -1 then
|
||||
nodename = nodename .. "A"
|
||||
table.insert(rules, {x=-1, y=0, z=0})
|
||||
-- CODE NOT ACTIVE
|
||||
|
||||
local crossing_get_rules = function(node)
|
||||
--TODO: calculate the real port states and use rules to link to them only if
|
||||
end
|
||||
if z == 1 then
|
||||
nodename = nodename .. "B"
|
||||
table.insert(rules, {x=0, y=0, z=1})
|
||||
end
|
||||
if x == 1 then
|
||||
nodename = nodename .. "C"
|
||||
table.insert(rules, {x=1, y=0, z=0})
|
||||
end
|
||||
if z == -1 then
|
||||
nodename = nodename .. "D"
|
||||
table.insert(rules, {x=0, y=0, z=-1})
|
||||
end
|
||||
mesecon:add_rules(nodename, rules)
|
||||
mesecon:register_effector(nodename, nodename, all_rules)
|
||||
if nodename == "mesecons_extrawires:crossing" then
|
||||
description = "Insulated Crossing"
|
||||
groups = {dig_immediate = 3, mesecon = 3, mesecon_conductor_craftable=1}
|
||||
else
|
||||
description = "You hacker you!"
|
||||
drop = "mesecons_extrawires:crossing"
|
||||
groups = {dig_immediate = 3, not_in_creative_inventory=1, mesecon = 3}
|
||||
mesecon:add_receptor_node(nodename, rules)
|
||||
end
|
||||
minetest.register_node(nodename, {
|
||||
|
||||
minetest.register_node("mesecons_extrawires:crossing_on", {
|
||||
drawtype = "nodebox",
|
||||
description = description,
|
||||
tiles = {
|
||||
"jeija_insulated_wire_sides.png",
|
||||
},
|
||||
tiles = {"jeija_insulated_wire_sides_on.png"},
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
stack_max = 99,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -16/32-0.0001, -18/32, -16/32-0.001, 16/32+0.001, -5/32, 16/32+0.001 },
|
||||
},
|
||||
selection_box = {type="fixed", fixed={-16/32-0.0001, -18/32, -16/32-0.001, 16/32+0.001, -5/32, 16/32+0.001}},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
@ -52,73 +22,14 @@ for x=-1, 1 do for z=-1, 1 do
|
||||
{ -3/32, -17/32, 6/32, 3/32, -13/32, 16/32+0.001 },
|
||||
},
|
||||
},
|
||||
groups = groups,
|
||||
drop = drop,
|
||||
groups = {dig_immediate=3, mesecon=3, mesecon_conductor_craftable=1, not_in_creative_inventory=1},
|
||||
mesecons = {
|
||||
receptor = {
|
||||
state = mesecon.state.on,
|
||||
rules = crossing_get_rules,
|
||||
}
|
||||
},
|
||||
})
|
||||
end end
|
||||
|
||||
function receptor_set(pos, rules, on)
|
||||
if on then
|
||||
mesecon:receptor_on(pos, rules)
|
||||
else
|
||||
mesecon:receptor_off(pos, rules)
|
||||
end
|
||||
end
|
||||
|
||||
function update_plus(pos, name)
|
||||
vL = {
|
||||
a = string.find(name, "A")~=nil,
|
||||
b = string.find(name, "B")~=nil,
|
||||
c = string.find(name, "C")~=nil,
|
||||
d = string.find(name, "D")~=nil,
|
||||
}
|
||||
rL = yc_get_real_portstates(pos)
|
||||
L = {
|
||||
a = rL.c and not vL.c,
|
||||
b = rL.d and not vL.d,
|
||||
c = rL.a and not vL.a,
|
||||
d = rL.b and not vL.b,
|
||||
}
|
||||
newname = "mesecons_extrawires:crossing"
|
||||
if L.a then newname = newname .. "A" end
|
||||
if L.b then newname = newname .. "B" end
|
||||
if L.c then newname = newname .. "C" end
|
||||
if L.d then newname = newname .. "D" end
|
||||
if newname ~= name then
|
||||
minetest.env:add_node(pos, {name = newname})
|
||||
end
|
||||
if L.a ~= vL.a then
|
||||
receptor_set(pos, mesecon:get_rules("mesecons_extrawires:crossingA"), L.a)
|
||||
if not L.a and yc_get_real_portstates(pos).a then
|
||||
--catch signal changing direction while on
|
||||
update_plus(pos, newname)
|
||||
end
|
||||
end
|
||||
if L.b ~= vL.b then
|
||||
receptor_set(pos, mesecon:get_rules("mesecons_extrawires:crossingB"), L.b)
|
||||
if not L.b and yc_get_real_portstates(pos).b then
|
||||
update_plus(pos, newname)
|
||||
end
|
||||
end
|
||||
if L.c ~= vL.c then
|
||||
receptor_set(pos, mesecon:get_rules("mesecons_extrawires:crossingC"), L.c)
|
||||
if not L.c and yc_get_real_portstates(pos).c then
|
||||
update_plus(pos, newname)
|
||||
end
|
||||
end
|
||||
if L.d ~= vL.d then
|
||||
receptor_set(pos, mesecon:get_rules("mesecons_extrawires:crossingD"), L.d)
|
||||
if not L.c and yc_get_real_portstates(pos).d then
|
||||
update_plus(pos, newname)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mesecon:register_on_signal_change(function(pos, node)
|
||||
if string.find(node.name, "mesecons_extrawires:crossing")~=nil then
|
||||
update_plus(pos, node.name)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
|
@ -1,2 +1,6 @@
|
||||
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
|
||||
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").."/mesewire.lua");
|
||||
|
35
mesecons_extrawires/mesewire.lua
Normal file
@ -0,0 +1,35 @@
|
||||
local mesewire_rules =
|
||||
{
|
||||
{x = 1, y = 0, z = 0},
|
||||
{x =-1, y = 0, z = 0},
|
||||
{x = 0, y = 1, z = 0},
|
||||
{x = 0, y =-1, z = 0},
|
||||
{x = 0, y = 0, z = 1},
|
||||
{x = 0, y = 0, z =-1},
|
||||
}
|
||||
|
||||
minetest.register_node(":default:mese", {
|
||||
description = "Mese Block",
|
||||
tiles = {"default_mese_block.png"},
|
||||
is_ground_content = true,
|
||||
groups = {cracky=1},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
mesecons = {conductor = {
|
||||
state = mesecon.state.off,
|
||||
onstate = "mesecons_extrawires:mese_powered",
|
||||
rules = mesewire_rules
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_extrawires:mese_powered", {
|
||||
tiles = {"default_mese_block.png^[brighten"},
|
||||
is_ground_content = true,
|
||||
groups = {cracky=1, not_in_creative_inventory = 1},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
mesecons = {conductor = {
|
||||
state = mesecon.state.on,
|
||||
offstate = "default:mese",
|
||||
rules = mesewire_rules
|
||||
}},
|
||||
drop = "default:mese"
|
||||
})
|
@ -9,14 +9,27 @@ local tjunction_selectionbox = {
|
||||
fixed = { -16/32-0.001, -18/32, -16/32, 16/32+0.001, -12/32, 7/32 },
|
||||
}
|
||||
|
||||
local tjunction_get_rules = function (node)
|
||||
local rules =
|
||||
{{x = 0, y = 0, z = 1},
|
||||
{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:tjunction_on", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"jeija_insulated_wire_sides.png",
|
||||
"jeija_insulated_wire_sides.png",
|
||||
"jeija_insulated_wire_tjunction_tb_on.png",
|
||||
"jeija_insulated_wire_tjunction_tb_on.png^[transformR180",
|
||||
"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"
|
||||
},
|
||||
paramtype = "light",
|
||||
@ -25,20 +38,25 @@ minetest.register_node("mesecons_extrawires:tjunction_on", {
|
||||
sunlight_propagates = true,
|
||||
selection_box = tjunction_selectionbox,
|
||||
node_box = tjunction_nodebox,
|
||||
groups = {dig_immediate = 3, mesecon = 3, mesecon_conductor_craftable=1, not_in_creative_inventory = 1},
|
||||
drop = "mesecons_insulated:insulated_off",
|
||||
|
||||
groups = {dig_immediate = 3, mesecon_conductor_craftable=1, not_in_creative_inventory = 1},
|
||||
drop = "mesecons_extrawires:tjunction_off",
|
||||
mesecons = {conductor =
|
||||
{
|
||||
state = mesecon.state.on,
|
||||
rules = tjunction_get_rules,
|
||||
offstate = "mesecons_extrawires:tjunction_off"
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_extrawires:tjunction_off", {
|
||||
drawtype = "nodebox",
|
||||
description = "T-junction",
|
||||
tiles = {
|
||||
"jeija_insulated_wire_sides.png",
|
||||
"jeija_insulated_wire_sides.png",
|
||||
"jeija_insulated_wire_tjunction_tb_off.png",
|
||||
"jeija_insulated_wire_tjunction_tb_off.png^[transformR180",
|
||||
"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"
|
||||
},
|
||||
paramtype = "light",
|
||||
@ -47,7 +65,13 @@ minetest.register_node("mesecons_extrawires:tjunction_off", {
|
||||
sunlight_propagates = true,
|
||||
selection_box = tjunction_selectionbox,
|
||||
node_box = tjunction_nodebox,
|
||||
groups = {dig_immediate = 3, mesecon = 3, mesecon_conductor_craftable=1},
|
||||
groups = {dig_immediate = 3, mesecon_conductor_craftable=1},
|
||||
mesecons = {conductor =
|
||||
{
|
||||
state = mesecon.state.off,
|
||||
rules = tjunction_get_rules,
|
||||
onstate = "mesecons_extrawires:tjunction_on"
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
@ -58,28 +82,3 @@ minetest.register_craft({
|
||||
{"", "mesecons_insulated:insulated_off", ""},
|
||||
}
|
||||
})
|
||||
|
||||
mesecon:add_rules("tjunction_all", { --all possible rules
|
||||
{x = 1, y = 0, z = 0},
|
||||
{x =-1, y = 0, z = 0},
|
||||
{x = 0, y = 0, z = 1},
|
||||
{x = 0, y = 0, z =-1},})
|
||||
|
||||
mesecon:add_rules("tjunction", {
|
||||
{x = 1, y = 0, z = 0},
|
||||
{x =-1, y = 0, z = 0},
|
||||
{x = 0, y = 0, z = -1},})
|
||||
|
||||
function tjunction_get_rules(param2)
|
||||
local rules = mesecon:get_rules("tjunction")
|
||||
if param2 == 1 then
|
||||
rules = mesecon:rotate_rules_left(mesecon:get_rules("tjunction"))
|
||||
elseif param2 == 2 then
|
||||
rules = mesecon:rotate_rules_right(mesecon:rotate_rules_right(mesecon:get_rules("tjunction")))
|
||||
elseif param2 == 3 then
|
||||
rules = mesecon:rotate_rules_right(mesecon:get_rules("tjunction"))
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
mesecon:register_conductor("mesecons_extrawires:tjunction_on", "mesecons_extrawires:tjunction_off", mesecon:get_rules("tjunction_all"), tjunction_get_rules)
|
||||
|
203
mesecons_extrawires/vertical.lua
Normal file
@ -0,0 +1,203 @@
|
||||
local vbox = {
|
||||
type = "fixed",
|
||||
fixed = {-1/16, -.5, -1/16, 1/16, .5, 1/16}
|
||||
}
|
||||
|
||||
local tbox = {
|
||||
type = "fixed",
|
||||
fixed = {{-.5, -.5, -.5, .5, -.5 + 1/16, .5}}
|
||||
}
|
||||
|
||||
local bbox = {
|
||||
type = "fixed",
|
||||
fixed = {{ -.5, -.5 , -.5, .5, -.5+1/16, .5},
|
||||
{-1/16, -.5+1/16, -1/16, 1/16, .5 , 1/16}}
|
||||
}
|
||||
|
||||
local vrules =
|
||||
{{x = 0, y = 1, z = 0},
|
||||
{x = 0, y =-1, z = 0}}
|
||||
|
||||
local trules =
|
||||
{{x = 1, y = 0, z = 0},
|
||||
{x =-1, y = 0, z = 0},
|
||||
{x = 0, y = 0, z = 1},
|
||||
{x = 0, y = 0, z =-1},
|
||||
{x = 0, y =-1, z = 0}}
|
||||
|
||||
local brules =
|
||||
{{x = 1, y = 0, z = 0},
|
||||
{x =-1, y = 0, z = 0},
|
||||
{x = 0, y = 0, z = 1},
|
||||
{x = 0, y = 0, z =-1},
|
||||
{x = 0, y = 1, z = 0}}
|
||||
|
||||
local vertical_updatepos = function (pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
if minetest.registered_nodes[node.name].is_vertical_conductor then
|
||||
local node_above = minetest.env:get_node(mesecon:addPosRule(pos, vrules[1]))
|
||||
local node_below = minetest.env:get_node(mesecon:addPosRule(pos, vrules[2]))
|
||||
local namestate = minetest.registered_nodes[node.name].vertical_conductor_state
|
||||
|
||||
-- above and below: vertical mesecon
|
||||
if minetest.registered_nodes[node_above.name].is_vertical_conductor
|
||||
and minetest.registered_nodes[node_below.name].is_vertical_conductor then
|
||||
minetest.env:add_node (pos,
|
||||
{name = "mesecons_extrawires:vertical_"..namestate})
|
||||
|
||||
-- above only: bottom
|
||||
elseif minetest.registered_nodes[node_above.name].is_vertical_conductor
|
||||
and not minetest.registered_nodes[node_below.name].is_vertical_conductor then
|
||||
minetest.env:add_node (pos,
|
||||
{name = "mesecons_extrawires:vertical_bottom_"..namestate})
|
||||
|
||||
-- below only: top
|
||||
elseif not minetest.registered_nodes[node_above.name].is_vertical_conductor
|
||||
and minetest.registered_nodes[node_below.name].is_vertical_conductor then
|
||||
minetest.env:add_node (pos,
|
||||
{name = "mesecons_extrawires:vertical_top_"..namestate})
|
||||
else -- no vertical wire above, no vertical wire below: use default wire
|
||||
minetest.env:add_node (pos,
|
||||
{name = "mesecons_extrawires:vertical_"..namestate})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local vertical_update = function (pos, node)
|
||||
vertical_updatepos(pos) -- this one
|
||||
vertical_updatepos(mesecon:addPosRule(pos, vrules[1])) -- above
|
||||
vertical_updatepos(mesecon:addPosRule(pos, vrules[2])) -- below
|
||||
end
|
||||
|
||||
-- Vertical wire
|
||||
minetest.register_node("mesecons_extrawires:vertical_on", {
|
||||
description = "Vertical mesecon",
|
||||
drawtype = "nodebox",
|
||||
tiles = {"wires_vertical_on.png"},
|
||||
walkable = false,
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
||||
selection_box = vbox,
|
||||
node_box = vbox,
|
||||
is_vertical_conductor = true,
|
||||
vertical_conductor_state = "on",
|
||||
mesecons = {conductor = {
|
||||
state = mesecon.state.on,
|
||||
offstate = "mesecons_extrawires:vertical_off",
|
||||
rules = vrules
|
||||
}},
|
||||
drop = {"mesecons_extrawires:vertical_off"},
|
||||
after_place_node = vertical_update,
|
||||
after_dig_node = vertical_update
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_extrawires:vertical_off", {
|
||||
description = "Vertical mesecon",
|
||||
drawtype = "nodebox",
|
||||
tiles = {"wires_vertical_off.png"},
|
||||
walkable = false,
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
groups = {dig_immediate = 3},
|
||||
selection_box = vbox,
|
||||
node_box = vbox,
|
||||
is_vertical_conductor = true,
|
||||
vertical_conductor_state = "off",
|
||||
mesecons = {conductor = {
|
||||
state = mesecon.state.off,
|
||||
onstate = "mesecons_extrawires:vertical_on",
|
||||
rules = vrules
|
||||
}},
|
||||
after_place_node = vertical_update,
|
||||
after_dig_node = vertical_update
|
||||
})
|
||||
|
||||
-- Vertical wire top
|
||||
minetest.register_node("mesecons_extrawires:vertical_top_on", {
|
||||
description = "Vertical mesecon",
|
||||
drawtype = "nodebox",
|
||||
tiles = {"wires_full_on.png"},
|
||||
walkable = false,
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
||||
selection_box = tbox,
|
||||
node_box = tbox,
|
||||
is_vertical_conductor = true,
|
||||
vertical_conductor_state = "on",
|
||||
mesecons = {conductor = {
|
||||
state = mesecon.state.on,
|
||||
offstate = "mesecons_extrawires:vertical_top_off",
|
||||
rules = trules
|
||||
}},
|
||||
drop = {"mesecons_extrawires:vertical_off"},
|
||||
after_place_node = vertical_update,
|
||||
after_dig_node = vertical_update
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_extrawires:vertical_top_off", {
|
||||
description = "Vertical mesecon",
|
||||
drawtype = "nodebox",
|
||||
tiles = {"wires_full_off.png"},
|
||||
walkable = false,
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
||||
selection_box = tbox,
|
||||
node_box = tbox,
|
||||
is_vertical_conductor = true,
|
||||
vertical_conductor_state = "off",
|
||||
mesecons = {conductor = {
|
||||
state = mesecon.state.off,
|
||||
onstate = "mesecons_extrawires:vertical_top_on",
|
||||
rules = trules
|
||||
}},
|
||||
drop = {"mesecons_extrawires:vertical_off"},
|
||||
after_place_node = vertical_update,
|
||||
after_dig_node = vertical_update
|
||||
})
|
||||
|
||||
-- Vertical wire bottom
|
||||
minetest.register_node("mesecons_extrawires:vertical_bottom_on", {
|
||||
description = "Vertical mesecon",
|
||||
drawtype = "nodebox",
|
||||
tiles = {"wires_full_on.png"},
|
||||
walkable = false,
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
vertical_conductor_state = "on",
|
||||
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
||||
selection_box = bbox,
|
||||
node_box = bbox,
|
||||
mesecons = {conductor = {
|
||||
state = mesecon.state.on,
|
||||
offstate = "mesecons_extrawires:vertical_bottom_off",
|
||||
rules = brules
|
||||
}},
|
||||
drop = {"mesecons_extrawires:vertical_off"},
|
||||
after_place_node = vertical_update,
|
||||
after_dig_node = vertical_update
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_extrawires:vertical_bottom_off", {
|
||||
description = "Vertical mesecon",
|
||||
drawtype = "nodebox",
|
||||
tiles = {"wires_full_off.png"},
|
||||
walkable = false,
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
||||
selection_box = bbox,
|
||||
node_box = bbox,
|
||||
is_vertical_conductor = true,
|
||||
vertical_conductor_state = "off",
|
||||
mesecons = {conductor = {
|
||||
state = mesecon.state.off,
|
||||
onstate = "mesecons_extrawires:vertical_bottom_on",
|
||||
rules = brules
|
||||
}},
|
||||
drop = {"mesecons_extrawires:vertical_off"},
|
||||
after_place_node = vertical_update,
|
||||
after_dig_node = vertical_update
|
||||
})
|
@ -1,62 +1,129 @@
|
||||
outrules = {
|
||||
{x=1, y=0, z=0},
|
||||
}
|
||||
oneinput = {
|
||||
{x=-1, y=0, z=0},
|
||||
{x=1, y=0, z=0},
|
||||
}
|
||||
twoinputs = {
|
||||
{x=0, y=0, z=1},
|
||||
{x=0, y=0, z=-1},
|
||||
{x=1, y=0, z=0},
|
||||
}
|
||||
function get_gate_rules(param2, onlyout, singleinput)
|
||||
if onlyout then
|
||||
rules = outrules
|
||||
else
|
||||
if singleinput then
|
||||
rules = oneinput
|
||||
else
|
||||
rules = twoinputs
|
||||
end
|
||||
end
|
||||
for rotations=0, param2-1 do
|
||||
function gate_rotate_rules(node)
|
||||
for rotations = 0, node.param2 - 1 do
|
||||
rules = mesecon:rotate_rules_left(rules)
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
function get_gate_rules_one(param2) return get_gate_rules(param2, false, true) end
|
||||
function get_gate_rules_two(param2) return get_gate_rules(param2, false, false) end
|
||||
function get_gate_rules_out(param2) return get_gate_rules(param2, true) end
|
||||
gates = {"diode", "not", "nand", "and", "xor"}
|
||||
for g in ipairs(gates) do gate = gates[g]
|
||||
if g < 3 then
|
||||
get_rules = get_gate_rules_one
|
||||
function gate_get_output_rules(node)
|
||||
rules = {{x=1, y=0, z=0}}
|
||||
return gate_rotate_rules(node)
|
||||
end
|
||||
|
||||
function gate_get_input_rules_oneinput(node)
|
||||
rules = {{x=-1, y=0, z=0}, {x=1, y=0, z=0}}
|
||||
return gate_rotate_rules(node)
|
||||
end
|
||||
|
||||
function gate_get_input_rules_twoinputs(node)
|
||||
rules = {
|
||||
{x=0, y=0, z=1},
|
||||
{x=0, y=0, z=-1},
|
||||
{x=1, y=0, z=0}}
|
||||
return gate_rotate_rules(node)
|
||||
end
|
||||
|
||||
function update_gate(pos)
|
||||
gate = get_gate(pos)
|
||||
L = rotate_ports(
|
||||
yc_get_real_portstates(pos),
|
||||
minetest.env:get_node(pos).param2
|
||||
)
|
||||
if gate == "diode" then
|
||||
set_gate(pos, L.a)
|
||||
elseif gate == "not" then
|
||||
set_gate(pos, not L.a)
|
||||
elseif gate == "nand" then
|
||||
set_gate(pos, not(L.b and L.d))
|
||||
elseif gate == "and" then
|
||||
set_gate(pos, L.b and L.d)
|
||||
elseif gate == "xor" then
|
||||
set_gate(pos, (L.b and not L.d) or (not L.b and L.d))
|
||||
end
|
||||
end
|
||||
|
||||
function set_gate(pos, on)
|
||||
gate = get_gate(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
if on ~= gate_state(pos) then
|
||||
yc_heat(meta)
|
||||
minetest.after(0.5, yc_cool, meta)
|
||||
if yc_overheat(meta) then
|
||||
pop_gate(pos)
|
||||
else
|
||||
get_rules = get_gate_rules_two
|
||||
if on then
|
||||
mesecon:swap_node(pos, "mesecons_gates:"..gate.."_on")
|
||||
mesecon:receptor_on(pos,
|
||||
gate_get_output_rules(minetest.env:get_node(pos)))
|
||||
else
|
||||
mesecon:swap_node(pos, "mesecons_gates:"..gate.."_off")
|
||||
mesecon:receptor_off(pos,
|
||||
gate_get_output_rules(minetest.env:get_node(pos)))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function get_gate(pos)
|
||||
return minetest.registered_nodes[minetest.env:get_node(pos).name].mesecons_gate
|
||||
end
|
||||
|
||||
function gate_state(pos)
|
||||
name = minetest.env:get_node(pos).name
|
||||
return string.find(name, "_on") ~= nil
|
||||
end
|
||||
|
||||
function pop_gate(pos)
|
||||
gate = get_gate(pos)
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.after(0.2, yc_overheat_off, pos)
|
||||
minetest.env:add_item(pos, "mesecons_gates:"..gate.."_off")
|
||||
end
|
||||
|
||||
function rotate_ports(L, param2)
|
||||
for rotations=0, param2-1 do
|
||||
port = L.a
|
||||
L.a = L.b
|
||||
L.b = L.c
|
||||
L.c = L.d
|
||||
L.d = port
|
||||
end
|
||||
return L
|
||||
end
|
||||
|
||||
gates = {
|
||||
{name = "diode", inputnumber = 1},
|
||||
{name = "not" , inputnumber = 1},
|
||||
{name = "nand" , inputnumber = 2},
|
||||
{name = "and" , inputnumber = 2},
|
||||
{name = "xor" , inputnumber = 2}}
|
||||
|
||||
local onoff, drop, nodename, description, groups
|
||||
for _, gate in ipairs(gates) do
|
||||
if gate.inputnumber == 1 then
|
||||
get_rules = gate_get_input_rules_oneinput
|
||||
elseif gate.inputnumber == 2 then
|
||||
get_rules = gate_get_input_rules_twoinputs
|
||||
end
|
||||
for on = 0, 1 do
|
||||
nodename = "mesecons_gates:"..gate
|
||||
nodename = "mesecons_gates:"..gate.name
|
||||
if on == 1 then
|
||||
onoff = "on"
|
||||
drop = nodename.."_off"
|
||||
nodename = nodename.."_"..onoff
|
||||
description = "You hacker you!"
|
||||
groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3}
|
||||
mesecon:add_receptor_node(nodename, get_rules, get_gate_rules_out)
|
||||
--mesecon:add_receptor_node(nodename, mesecon:get_rules("insulated_all"))
|
||||
groups = {dig_immediate=2, not_in_creative_inventory=1}
|
||||
else
|
||||
onoff = "off"
|
||||
drop = nil
|
||||
nodename = nodename.."_"..onoff
|
||||
description = gate.." Gate"
|
||||
groups = {dig_immediate=2, mesecon = 3}
|
||||
--mesecon:add_receptor_node_off(nodename, get_gate_rules_out)
|
||||
description = gate.name.." Gate"
|
||||
groups = {dig_immediate=2}
|
||||
end
|
||||
|
||||
tiles = "jeija_microcontroller_bottom.png^"..
|
||||
"jeija_gate_"..onoff..".png^"..
|
||||
"jeija_gate_"..gate..".png"
|
||||
"jeija_gate_"..gate.name..".png"
|
||||
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
@ -65,6 +132,13 @@ for g in ipairs(gates) do gate = gates[g]
|
||||
},
|
||||
}
|
||||
|
||||
local mesecon_state
|
||||
if on == 1 then
|
||||
mesecon_state = mesecon.state.on
|
||||
else
|
||||
mesecon_state = mesecon.state.off
|
||||
end
|
||||
|
||||
minetest.register_node(nodename, {
|
||||
description = description,
|
||||
paramtype = "light",
|
||||
@ -82,103 +156,24 @@ for g in ipairs(gates) do gate = gates[g]
|
||||
end,
|
||||
groups = groups,
|
||||
drop = drop,
|
||||
|
||||
mesecons_gate = gate.name,
|
||||
mesecons =
|
||||
{
|
||||
receptor =
|
||||
{
|
||||
state = mesecon_state,
|
||||
rules = gate_get_output_rules
|
||||
},
|
||||
effector =
|
||||
{
|
||||
rules = get_rules,
|
||||
action_change = update_gate
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
mesecon:register_effector(nodename, nodename, all_rules, get_rules)
|
||||
end
|
||||
end
|
||||
|
||||
function get_gate(pos)
|
||||
return
|
||||
string.gsub(
|
||||
string.gsub(
|
||||
string.gsub(
|
||||
minetest.env:get_node(pos).name
|
||||
, "mesecons_gates:", "") --gate
|
||||
,"_on", "")
|
||||
,"_off", "")
|
||||
end
|
||||
|
||||
function gate_state(pos)
|
||||
name = minetest.env:get_node(pos).name
|
||||
return string.find(name, "_on") ~= nil
|
||||
end
|
||||
|
||||
function pop_gate(pos)
|
||||
gate = get_gate(pos)
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.after(0.2, yc_overheat_off, pos)
|
||||
minetest.env:add_item(pos, "mesecons_gates:"..gate.."_off")
|
||||
end
|
||||
|
||||
function set_gate(pos, on)
|
||||
gate = get_gate(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
if on ~= gate_state(pos) then
|
||||
yc_heat(meta)
|
||||
minetest.after(0.5, yc_cool, meta)
|
||||
if yc_overheat(meta) then
|
||||
pop_gate(pos)
|
||||
else
|
||||
heat = meta:get_int("heat")
|
||||
if on then
|
||||
onoff = "_on"
|
||||
else
|
||||
onoff = "_off"
|
||||
end
|
||||
param2 = minetest.env:get_node(pos).param2
|
||||
minetest.env:add_node(pos, {
|
||||
name = "mesecons_gates:"..gate..onoff,
|
||||
param2 = param2,
|
||||
})
|
||||
local meta2 = minetest.env:get_meta(pos)
|
||||
meta2:set_int("heat", heat)
|
||||
if on then
|
||||
mesecon:receptor_on(pos, get_gate_rules(param2, true))
|
||||
else
|
||||
mesecon:receptor_off(pos, all_rules)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function rotate_ports(L, param2)
|
||||
for rotations=0, param2-1 do
|
||||
port = L.a
|
||||
L.a = L.b
|
||||
L.b = L.c
|
||||
L.c = L.d
|
||||
L.d = port
|
||||
end
|
||||
return L
|
||||
end
|
||||
|
||||
function update_gate(pos)
|
||||
gate = get_gate(pos)
|
||||
L = rotate_ports(
|
||||
yc_get_real_portstates(pos),
|
||||
minetest.env:get_node(pos).param2
|
||||
)
|
||||
if gate == "diode" then
|
||||
set_gate(pos, L.a)
|
||||
elseif gate == "not" then
|
||||
set_gate(pos, not L.a)
|
||||
elseif gate == "nand" then
|
||||
set_gate(pos, not(L.b and L.d))
|
||||
elseif gate == "and" then
|
||||
set_gate(pos, L.b and L.d)
|
||||
else--if gate == "xor" then
|
||||
set_gate(pos, (L.b and not L.d) or (not L.b and L.d))
|
||||
end
|
||||
end
|
||||
|
||||
mesecon:register_on_signal_change(function(pos,node)
|
||||
if string.find(node.name, "mesecons_gates:")~=nil then
|
||||
update_gate(pos)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'mesecons_gates:diode_off',
|
||||
recipe = {
|
||||
|
@ -1,9 +1,12 @@
|
||||
-- HYDRO_TURBINE
|
||||
-- Water turbine:
|
||||
-- Active if flowing >water< above it
|
||||
-- (does not work with other liquids)
|
||||
|
||||
minetest.register_node("mesecons_hydroturbine:hydro_turbine_off", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {"jeija_hydro_turbine_off.png"},
|
||||
groups = {dig_immediate=2, mesecon = 2},
|
||||
groups = {dig_immediate=2},
|
||||
description="Water Turbine",
|
||||
paramtype = "light",
|
||||
selection_box = {
|
||||
@ -20,13 +23,16 @@ minetest.register_node("mesecons_hydroturbine:hydro_turbine_off", {
|
||||
{-0.45, 1.15, -0.1, 0.45, 1.45, 0.1},
|
||||
{-0.1, 1.15, -0.45, 0.1, 1.45, 0.45}},
|
||||
},
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.off
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_hydroturbine:hydro_turbine_on", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {"jeija_hydro_turbine_on.png"},
|
||||
drop = '"mesecons_hydroturbine:hydro_turbine_off" 1',
|
||||
groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon = 2},
|
||||
groups = {dig_immediate=2,not_in_creative_inventory=1},
|
||||
description="Water Turbine",
|
||||
paramtype = "light",
|
||||
selection_box = {
|
||||
@ -43,6 +49,9 @@ minetest.register_node("mesecons_hydroturbine:hydro_turbine_on", {
|
||||
{-0.5, 1.15, -0.1, 0.5, 1.45, 0.1},
|
||||
{-0.1, 1.15, -0.5, 0.1, 1.45, 0.5}},
|
||||
},
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.on
|
||||
}}
|
||||
})
|
||||
|
||||
|
||||
@ -74,9 +83,6 @@ nodenames = {"mesecons_hydroturbine:hydro_turbine_on"},
|
||||
end,
|
||||
})
|
||||
|
||||
mesecon:add_receptor_node("mesecons_hydroturbine:hydro_turbine_on")
|
||||
mesecon:add_receptor_node_off("mesecons_hydroturbine:hydro_turbine_off")
|
||||
|
||||
minetest.register_craft({
|
||||
output = '"mesecons_hydroturbine:hydro_turbine_off" 2',
|
||||
recipe = {
|
||||
|
@ -1,13 +1,22 @@
|
||||
function insulated_wire_get_rules(node)
|
||||
local rules = {{x = 1, y = 0, z = 0},
|
||||
{x =-1, y = 0, z = 0}}
|
||||
if node.param2 == 1 or node.param2 == 3 then
|
||||
return mesecon:rotate_rules_right(rules)
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
minetest.register_node("mesecons_insulated:insulated_on", {
|
||||
drawtype = "nodebox",
|
||||
description = "insulated mesecons",
|
||||
description = "Insulated Mesecon",
|
||||
tiles = {
|
||||
"jeija_insulated_wire_sides.png",
|
||||
"jeija_insulated_wire_sides.png",
|
||||
"jeija_insulated_wire_sides_on.png",
|
||||
"jeija_insulated_wire_sides_on.png",
|
||||
"jeija_insulated_wire_ends_on.png",
|
||||
"jeija_insulated_wire_ends_on.png",
|
||||
"jeija_insulated_wire_sides.png",
|
||||
"jeija_insulated_wire_sides.png"
|
||||
"jeija_insulated_wire_sides_on.png",
|
||||
"jeija_insulated_wire_sides_on.png"
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
@ -21,21 +30,25 @@ minetest.register_node("mesecons_insulated:insulated_on", {
|
||||
type = "fixed",
|
||||
fixed = { -16/32-0.001, -17/32, -3/32, 16/32+0.001, -13/32, 3/32 }
|
||||
},
|
||||
groups = {dig_immediate = 3, mesecon = 3, mesecon_conductor_craftable=1, not_in_creative_inventory = 1},
|
||||
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
||||
drop = "mesecons_insulated:insulated_off",
|
||||
|
||||
mesecons = {conductor = {
|
||||
state = mesecon.state.on,
|
||||
offstate = "mesecons_insulated:insulated_off",
|
||||
rules = insulated_wire_get_rules
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_insulated:insulated_off", {
|
||||
drawtype = "nodebox",
|
||||
description = "insulated mesecons",
|
||||
tiles = {
|
||||
"jeija_insulated_wire_sides.png",
|
||||
"jeija_insulated_wire_sides.png",
|
||||
"jeija_insulated_wire_sides_off.png",
|
||||
"jeija_insulated_wire_sides_off.png",
|
||||
"jeija_insulated_wire_ends_off.png",
|
||||
"jeija_insulated_wire_ends_off.png",
|
||||
"jeija_insulated_wire_sides.png",
|
||||
"jeija_insulated_wire_sides.png"
|
||||
"jeija_insulated_wire_sides_off.png",
|
||||
"jeija_insulated_wire_sides_off.png"
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
@ -49,7 +62,12 @@ minetest.register_node("mesecons_insulated:insulated_off", {
|
||||
type = "fixed",
|
||||
fixed = { -16/32-0.001, -17/32, -3/32, 16/32+0.001, -13/32, 3/32 }
|
||||
},
|
||||
groups = {dig_immediate = 3, mesecon = 3, mesecon_conductor_craftable=1},
|
||||
groups = {dig_immediate = 3},
|
||||
mesecons = {conductor = {
|
||||
state = mesecon.state.off,
|
||||
onstate = "mesecons_insulated:insulated_on",
|
||||
rules = insulated_wire_get_rules
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
@ -61,21 +79,6 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
mesecon:add_rules("insulated_all", { --all possible rules
|
||||
{x = 1, y = 0, z = 0},
|
||||
{x =-1, y = 0, z = 0},
|
||||
{x = 0, y = 0, z = 1},
|
||||
{x = 0, y = 0, z =-1},})
|
||||
|
||||
mesecon:add_rules("insulated", {
|
||||
{x = 1, y = 0, z = 0},
|
||||
{x =-1, y = 0, z = 0},})
|
||||
|
||||
function insulated_wire_get_rules(param2)
|
||||
if param2 == 1 or param2 == 3 then
|
||||
return mesecon:rotate_rules_right(mesecon:get_rules("insulated"))
|
||||
end
|
||||
return mesecon:get_rules("insulated")
|
||||
end
|
||||
|
||||
mesecon:register_conductor("mesecons_insulated:insulated_on", "mesecons_insulated:insulated_off", mesecon:get_rules("insulated_all"), insulated_wire_get_rules)
|
||||
{x =-1, y = 0, z = 0}})
|
||||
|
@ -1,4 +1,14 @@
|
||||
-- MESELAMPS
|
||||
-- A lamp is "is an electrical device used to create artificial light" (wikipedia)
|
||||
-- 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", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {"jeija_meselamp_on.png"},
|
||||
@ -8,20 +18,15 @@ minetest.register_node("mesecons_lamp:lamp_on", {
|
||||
sunlight_propagates = true,
|
||||
walkable = true,
|
||||
light_source = LIGHT_MAX,
|
||||
node_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},
|
||||
},
|
||||
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, mesecon = 2},
|
||||
node_box = mesecon_lamp_box,
|
||||
selection_box = mesecon_lamp_box,
|
||||
groups = {dig_immediate=3,not_in_creative_inventory=1, mesecon_effector_on = 1},
|
||||
drop='"mesecons_lamp:lamp_off" 1',
|
||||
mesecons = {effector = {
|
||||
action_off = function (pos, node)
|
||||
mesecon:swap_node(pos, "mesecons_lamp:lamp_off")
|
||||
end
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_lamp:lamp_off", {
|
||||
@ -33,20 +38,15 @@ minetest.register_node("mesecons_lamp:lamp_off", {
|
||||
paramtype2 = "wallmounted",
|
||||
sunlight_propagates = true,
|
||||
walkable = true,
|
||||
node_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},
|
||||
},
|
||||
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, mesecon = 2},
|
||||
node_box = mesecon_lamp_box,
|
||||
selection_box = mesecon_lamp_box,
|
||||
groups = {dig_immediate=3, mesecon_receptor_off = 1, mesecon_effector_off = 1},
|
||||
description="Meselamp",
|
||||
mesecons = {effector = {
|
||||
action_on = function (pos, node)
|
||||
mesecon:swap_node(pos, "mesecons_lamp:lamp_on")
|
||||
end
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
@ -57,19 +57,3 @@ minetest.register_craft({
|
||||
{'', '"default:glass"', ''},
|
||||
}
|
||||
})
|
||||
|
||||
mesecon:register_on_signal_on(function(pos, node)
|
||||
if node.name == "mesecons_lamp:lamp_off" then
|
||||
minetest.env:add_node(pos, {name="mesecons_lamp:lamp_on", param2 = node.param2})
|
||||
nodeupdate(pos)
|
||||
end
|
||||
end)
|
||||
|
||||
mesecon:register_on_signal_off(function(pos, node)
|
||||
if node.name == "mesecons_lamp:lamp_on" then
|
||||
minetest.env:add_node(pos, {name="mesecons_lamp:lamp_off", param2 = node.param2})
|
||||
nodeupdate(pos)
|
||||
end
|
||||
end)
|
||||
|
||||
mesecon:register_effector("mesecons_lamp:lamp_on", "mesecons_lamp:lamp_off")
|
||||
|
@ -4,6 +4,11 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
|
||||
inventory_image = minetest.inventorycube(texture_off),
|
||||
groups = {cracky=2, mesecon_effector_off = 1, mesecon = 2},
|
||||
description=name.." Lightstone",
|
||||
mesecons = {effector = {
|
||||
action_on = function (pos, node)
|
||||
mesecon:swap_node(pos, "mesecons_lightstone:lightstone_" .. name .. "_on")
|
||||
end
|
||||
}}
|
||||
})
|
||||
minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_on", {
|
||||
tiles = {texture_on},
|
||||
@ -11,20 +16,13 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
|
||||
groups = {cracky=2,not_in_creative_inventory=1, mesecon = 2},
|
||||
drop = "node mesecons_lightstone:lightstone_" .. name .. "_off 1",
|
||||
light_source = LIGHT_MAX-2,
|
||||
description=name.." Lightstone",
|
||||
mesecons = {effector = {
|
||||
action_off = function (pos, node)
|
||||
mesecon:swap_node(pos, "mesecons_lightstone:lightstone_" .. name .. "_off")
|
||||
end
|
||||
}}
|
||||
})
|
||||
assert(loadstring('mesecon:register_on_signal_on(function(pos, node) \n \
|
||||
if node.name == "mesecons_lightstone:lightstone_' .. name .. '_off" then \n \
|
||||
minetest.env:add_node(pos, {name="mesecons_lightstone:lightstone_' .. name .. '_on"}) \n \
|
||||
nodeupdate(pos) \n \
|
||||
end \n \
|
||||
end)'))()
|
||||
assert(loadstring('mesecon:register_on_signal_off(function(pos, node) \n \
|
||||
if node.name == "mesecons_lightstone:lightstone_' .. name .. '_on" then \n \
|
||||
minetest.env:add_node(pos, {name="mesecons_lightstone:lightstone_' .. name .. '_off"}) \n \
|
||||
nodeupdate(pos) \n \
|
||||
end \n \
|
||||
end)'))()
|
||||
|
||||
minetest.register_craft({
|
||||
output = "node mesecons_lightstone:lightstone_" .. name .. "_off 1",
|
||||
recipe = {
|
||||
@ -33,7 +31,6 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
|
||||
{'','group:mesecon_conductor_craftable',''},
|
||||
}
|
||||
})
|
||||
mesecon:register_effector("mesecons_lightstone:lightstone_" .. name .. "_on", "mesecons_lightstone:lightstone_" .. name .. "_off")
|
||||
end
|
||||
|
||||
|
||||
|
@ -23,6 +23,33 @@ if tostring(d)..tostring(c)..tostring(b)..tostring(a) ~= "0000" then
|
||||
else
|
||||
groups = {dig_immediate=2, mesecon = 3}
|
||||
end
|
||||
local rules={}
|
||||
if (a == 1) then table.insert(rules, {x = -1, y = 0, z = 0}) end
|
||||
if (b == 1) then table.insert(rules, {x = 0, y = 0, z = 1}) end
|
||||
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
|
||||
|
||||
local input_rules={}
|
||||
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, name = "B"}) 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, name = "D"}) end
|
||||
mesecon:add_rules(nodename, rules)
|
||||
|
||||
local mesecons = {effector =
|
||||
{
|
||||
rules = input_rules,
|
||||
action_change = function (pos, node, rulename)
|
||||
update_yc(pos)
|
||||
end
|
||||
}}
|
||||
if nodename ~= "mesecons_microcontroller:microcontroller0000" then
|
||||
mesecons.receptor = {
|
||||
state = mesecon.state.on,
|
||||
rules = rules
|
||||
}
|
||||
end
|
||||
|
||||
minetest.register_node(nodename, {
|
||||
description = "Microcontroller",
|
||||
drawtype = "nodebox",
|
||||
@ -101,25 +128,12 @@ minetest.register_node(nodename, {
|
||||
yc_reset (pos)
|
||||
update_yc(pos)
|
||||
end,
|
||||
mesecons = mesecons,
|
||||
after_dig_node = function (pos, node)
|
||||
rules = mesecon:get_rules(node.name)
|
||||
mesecon:receptor_off(pos, rules)
|
||||
end,
|
||||
})
|
||||
|
||||
local rules={}
|
||||
if (a == 1) then table.insert(rules, {x = -1, y = 0, z = 0}) end
|
||||
if (b == 1) then table.insert(rules, {x = 0, y = 0, z = 1}) end
|
||||
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
|
||||
|
||||
local input_rules={}
|
||||
if (a == 0) then table.insert(input_rules, {x = -1, y = 0, z = 0}) end
|
||||
if (b == 0) then table.insert(input_rules, {x = 0, y = 0, z = 1}) end
|
||||
if (c == 0) then table.insert(input_rules, {x = 1, y = 0, z = 0}) end
|
||||
if (d == 0) then table.insert(input_rules, {x = 0, y = 0, z = -1}) end
|
||||
mesecon:add_rules(nodename, rules)
|
||||
|
||||
mesecon:register_effector(nodename, nodename, input_rules)
|
||||
if nodename ~= "mesecons_microcontroller:microcontroller0000" then
|
||||
mesecon:add_receptor_node(nodename, rules)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -570,14 +584,12 @@ end
|
||||
--Real I/O functions
|
||||
function yc_action(pos, L) --L-->Lvirtual
|
||||
local Lv = yc_get_virtual_portstates(pos)
|
||||
local metatable = minetest.env:get_meta(pos):to_table()
|
||||
local name = "mesecons_microcontroller:microcontroller"
|
||||
..tonumber(L.d and 1 or 0)
|
||||
..tonumber(L.c and 1 or 0)
|
||||
..tonumber(L.b and 1 or 0)
|
||||
..tonumber(L.a and 1 or 0)
|
||||
minetest.env:add_node(pos, {name=name})
|
||||
minetest.env:get_meta(pos):from_table(metatable)
|
||||
mesecon:swap_node(pos, name)
|
||||
|
||||
yc_action_setports(pos, L, Lv)
|
||||
end
|
||||
@ -616,7 +628,7 @@ function yc_set_portstate(port, state, L)
|
||||
return L
|
||||
end
|
||||
|
||||
function yc_get_real_portstates(pos)
|
||||
function yc_get_real_portstates(pos) -- port powered or not (by itself or from outside)?
|
||||
rulesA = mesecon:get_rules("mesecons_microcontroller:microcontroller0001")
|
||||
rulesB = mesecon:get_rules("mesecons_microcontroller:microcontroller0010")
|
||||
rulesC = mesecon:get_rules("mesecons_microcontroller:microcontroller0100")
|
||||
@ -630,7 +642,7 @@ function yc_get_real_portstates(pos)
|
||||
return L
|
||||
end
|
||||
|
||||
function yc_get_virtual_portstates(pos)
|
||||
function yc_get_virtual_portstates(pos) -- portstates according to the name
|
||||
name = minetest.env:get_node(pos).name
|
||||
b, a = string.find(name, ":microcontroller")
|
||||
if a == nil then return nil end
|
||||
@ -682,16 +694,3 @@ function yc_overheat_off(pos)
|
||||
rules = mesecon:get_rules("mesecons_microcontroller:microcontroller1111")
|
||||
mesecon:receptor_off(pos, rules)
|
||||
end
|
||||
|
||||
mesecon:register_on_signal_change(function(pos, node)
|
||||
if string.find(node.name, "mesecons_microcontroller:microcontroller")~=nil then
|
||||
update_yc(pos)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_dignode(function(pos, node)
|
||||
if string.find(node.name, "mesecons_microcontroller:microcontroller") then
|
||||
rules = mesecon:get_rules(node.name)
|
||||
mesecon:receptor_off(pos, rules)
|
||||
end
|
||||
end)
|
||||
|
@ -1,10 +1,30 @@
|
||||
-- MOVESTONE
|
||||
-- Non-sticky:
|
||||
-- Moves along mesecon lines
|
||||
-- Pushes all blocks in front of it
|
||||
--
|
||||
-- Sticky one
|
||||
-- Moves along mesecon lines
|
||||
-- Pushes all block in front of it
|
||||
-- Pull all blocks in its back
|
||||
|
||||
function mesecon:get_movestone_direction(pos)
|
||||
getactivated = 0
|
||||
local lpos
|
||||
local getactivated = 0
|
||||
local rules=mesecon:get_rules("movestone")
|
||||
local rules = {
|
||||
{x=0, y=1, z=-1},
|
||||
{x=0, y=0, z=-1},
|
||||
{x=0, y=-1, z=-1},
|
||||
{x=0, y=1, z=1},
|
||||
{x=0, y=-1, z=1},
|
||||
{x=0, y=0, z=1},
|
||||
{x=1, y=0, z=0},
|
||||
{x=1, y=1, z=0},
|
||||
{x=1, y=-1, z=0},
|
||||
{x=-1, y=1, z=0},
|
||||
{x=-1, y=-1, z=0},
|
||||
{x=-1, y=0, z=0}}
|
||||
|
||||
lpos = {x=pos.x+1, y=pos.y, z=pos.z}
|
||||
for n = 1, 3 do
|
||||
@ -41,8 +61,27 @@ minetest.register_node("mesecons_movestones:movestone", {
|
||||
legacy_facedir_simple = true,
|
||||
groups = {cracky=3},
|
||||
description="Movestone",
|
||||
mesecons = {effector = {
|
||||
action_on = function (pos, node)
|
||||
local direction=mesecon:get_movestone_direction(pos)
|
||||
if not direction then return end
|
||||
local checknode={}
|
||||
local collpos={x=pos.x, y=pos.y, z=pos.z}
|
||||
repeat -- Check if it collides with a stopper
|
||||
collpos = mesecon:addPosRule(collpos, direction)
|
||||
checknode=minetest.env:get_node(collpos)
|
||||
if mesecon:is_mvps_stopper(checknode.name, direction) then
|
||||
return
|
||||
end
|
||||
until checknode.name=="air"
|
||||
or checknode.name=="ignore"
|
||||
or not(minetest.registered_nodes[checknode.name].liquidtype == "none")
|
||||
minetest.env:remove_node(pos)
|
||||
mesecon:update_autoconnect(pos)
|
||||
minetest.env:add_entity(pos, "mesecons_movestones:movestone_entity")
|
||||
end
|
||||
}}
|
||||
})
|
||||
mesecon:register_effector("mesecons_movestones:movestone", "mesecons_movestones:movestone")
|
||||
|
||||
minetest.register_entity("mesecons_movestones:movestone_entity", {
|
||||
physical = false,
|
||||
@ -50,10 +89,6 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
|
||||
textures = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_arrows.png", "jeija_movestone_arrows.png"},
|
||||
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
|
||||
visual = "cube",
|
||||
--on_activate = function(self, staticdata)
|
||||
--self.object:setsprite({x=0,y=0}, 1, 0, true)
|
||||
--self.object:setvelocity({x=-3, y=0, z=0})
|
||||
--end,
|
||||
|
||||
on_punch = function(self, hitter)
|
||||
self.object:remove()
|
||||
@ -70,10 +105,10 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
|
||||
return
|
||||
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)
|
||||
end
|
||||
mesecon:mvps_push(pos, direction, 100)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
@ -85,28 +120,6 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
mesecon:register_on_signal_on(function (pos, node)
|
||||
if node.name=="mesecons_movestones:movestone" then
|
||||
local direction=mesecon:get_movestone_direction(pos)
|
||||
if not direction then return end
|
||||
local checknode={}
|
||||
local collpos={x=pos.x, y=pos.y, z=pos.z}
|
||||
repeat -- Check if it collides with a stopper
|
||||
collpos={x=collpos.x+direction.x, y=collpos.y+direction.y, z=collpos.z+direction.z}
|
||||
checknode=minetest.env:get_node(collpos)
|
||||
if mesecon:is_mvps_stopper(checknode.name) then
|
||||
return
|
||||
end
|
||||
until checknode.name=="air"
|
||||
or checknode.name=="ignore"
|
||||
or not(minetest.registered_nodes[checknode.name].liquidtype == "none")
|
||||
minetest.env:remove_node(pos)
|
||||
nodeupdate(pos)
|
||||
minetest.env:add_entity(pos, "mesecons_movestones:movestone_entity")
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
|
||||
|
||||
-- STICKY_MOVESTONE
|
||||
@ -118,8 +131,36 @@ minetest.register_node("mesecons_movestones:sticky_movestone", {
|
||||
legacy_facedir_simple = true,
|
||||
groups = {cracky=3},
|
||||
description="Sticky Movestone",
|
||||
mesecons = {effector = {
|
||||
action_on = function (pos, node)
|
||||
local direction=mesecon:get_movestone_direction(pos)
|
||||
if not direction then return end
|
||||
local checknode={}
|
||||
local collpos={x=pos.x, y=pos.y, z=pos.z}
|
||||
repeat -- Check if it collides with a stopper
|
||||
collpos = mesecon:addPosRule(collpos, direction)
|
||||
checknode=minetest.env:get_node(collpos)
|
||||
if mesecon:is_mvps_stopper(checknode.name, direction) then
|
||||
return
|
||||
end
|
||||
until checknode.name=="air"
|
||||
or checknode.name=="ignore"
|
||||
or not(minetest.registered_nodes[checknode.name].liquidtype == "none")
|
||||
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}
|
||||
checknode=minetest.env:get_node(collpos)
|
||||
if mesecon:is_mvps_stopper(checknode.name, direction) then
|
||||
return
|
||||
end
|
||||
until checknode.name=="air"
|
||||
or checknode.name=="ignore"
|
||||
or not(minetest.registered_nodes[checknode.name].liquidtype == "none")
|
||||
minetest.env:remove_node(pos)
|
||||
mesecon:update_autoconnect(pos)
|
||||
minetest.env:add_entity(pos, "mesecons_movestones:sticky_movestone_entity")
|
||||
end
|
||||
}}
|
||||
})
|
||||
mesecon:register_effector("mesecons_movestones:sticky_movestone", "mesecons_movestones:sticky_movestone")
|
||||
|
||||
minetest.register_craft({
|
||||
output = '"mesecons_movestones:sticky_movestone" 2',
|
||||
@ -146,62 +187,16 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
|
||||
local direction=mesecon:get_movestone_direction(colp)
|
||||
|
||||
if not direction then
|
||||
--or (minetest.env:get_node_or_nil(pos).name ~="air"
|
||||
--and minetest.env:get_node_or_nil(pos).name ~= nil) then
|
||||
minetest.env:add_node(pos, {name="mesecons_movestones:sticky_movestone"})
|
||||
self.object:remove()
|
||||
return
|
||||
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
|
||||
mesecon:mvps_pull_all(pos, direction)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
mesecon:register_on_signal_on(function (pos, node)
|
||||
if node.name=="mesecons_movestones:sticky_movestone" then
|
||||
local direction=mesecon:get_movestone_direction(pos)
|
||||
if not direction then return end
|
||||
local checknode={}
|
||||
local collpos={x=pos.x, y=pos.y, z=pos.z}
|
||||
repeat -- Check if it collides with a stopper
|
||||
collpos={x=collpos.x+direction.x, y=collpos.y+direction.y, z=collpos.z+direction.z}
|
||||
checknode=minetest.env:get_node(collpos)
|
||||
if mesecon:is_mvps_stopper(checknode.name) then
|
||||
return
|
||||
end
|
||||
until checknode.name=="air"
|
||||
or checknode.name=="ignore"
|
||||
or not(minetest.registered_nodes[checknode.name].liquidtype == "none")
|
||||
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}
|
||||
checknode=minetest.env:get_node(collpos)
|
||||
if mesecon:is_mvps_stopper(checknode.name) then
|
||||
return
|
||||
end
|
||||
until checknode.name=="air"
|
||||
or checknode.name=="ignore"
|
||||
or not(minetest.registered_nodes[checknode.name].liquidtype == "none")
|
||||
minetest.env:remove_node(pos)
|
||||
nodeupdate(pos)
|
||||
minetest.env:add_entity(pos, "mesecons_movestones:sticky_movestone_entity")
|
||||
end
|
||||
end)
|
||||
|
||||
mesecon:add_rules("movestone", {
|
||||
{x=0, y=1, z=-1},
|
||||
{x=0, y=0, z=-1},
|
||||
{x=0, y=-1, z=-1},
|
||||
{x=0, y=1, z=1},
|
||||
{x=0, y=-1, z=1},
|
||||
{x=0, y=0, z=1},
|
||||
{x=1, y=0, z=0},
|
||||
{x=1, y=1, z=0},
|
||||
{x=1, y=-1, z=0},
|
||||
{x=-1, y=1, z=0},
|
||||
{x=-1, y=-1, z=0},
|
||||
{x=-1, y=0, z=0}})
|
||||
|
@ -2,44 +2,100 @@
|
||||
|
||||
mesecon.mvps_stoppers={}
|
||||
|
||||
function mesecon:is_mvps_stopper(nodename)
|
||||
local i=1
|
||||
repeat
|
||||
i=i+1
|
||||
if mesecon.mvps_stoppers[i]==nodename then return true end
|
||||
until mesecon.mvps_stoppers[i]==nil
|
||||
return false
|
||||
function mesecon:is_mvps_stopper(node, pushdir, stack, stackid)
|
||||
local get_stopper = mesecon.mvps_stoppers[node.name]
|
||||
if type (get_stopper) == "function" then
|
||||
get_stopper = get_stopper(node, pushdir, stack, stackid)
|
||||
end
|
||||
return get_stopper
|
||||
end
|
||||
|
||||
function mesecon:register_mvps_stopper(nodename)
|
||||
local i=1
|
||||
repeat
|
||||
i=i+1
|
||||
if mesecon.mvps_stoppers[i]==nil then break end
|
||||
until false
|
||||
mesecon.mvps_stoppers[i]=nodename
|
||||
function mesecon:register_mvps_stopper(nodename, get_stopper)
|
||||
if get_stopper == nil then
|
||||
get_stopper = true
|
||||
end
|
||||
mesecon.mvps_stoppers[nodename] = get_stopper
|
||||
end
|
||||
|
||||
function mesecon:mvps_push(pos, direction) -- pos: pos of mvps; direction: direction of push
|
||||
pos.x=pos.x+direction.x
|
||||
pos.y=pos.y+direction.y
|
||||
pos.z=pos.z+direction.z
|
||||
|
||||
local lpos = {x=pos.x, y=pos.y, z=pos.z}
|
||||
local lnode = minetest.env:get_node(lpos)
|
||||
local newnode
|
||||
minetest.env:remove_node(lpos)
|
||||
while not(lnode.name == "ignore" or lnode.name == "air" or not(minetest.registered_nodes[lnode.name].liquidtype == "none")) do
|
||||
lpos.x=lpos.x+direction.x
|
||||
lpos.y=lpos.y+direction.y
|
||||
lpos.z=lpos.z+direction.z
|
||||
newnode = lnode
|
||||
lnode = minetest.env:get_node(lpos)
|
||||
minetest.env:add_node(lpos, newnode)
|
||||
nodeupdate(lpos)
|
||||
function mesecon:mvps_process_stack(stack)
|
||||
-- update mesecons for placed nodes ( has to be done after all nodes have been added )
|
||||
for _, n in ipairs(stack) do
|
||||
nodeupdate(n.pos)
|
||||
mesecon.on_placenode(n.pos, minetest.env:get_node(n.pos))
|
||||
mesecon:update_autoconnect(n.pos)
|
||||
end
|
||||
end
|
||||
|
||||
function mesecon:mvps_push(pos, dir, maximum) -- pos: pos of mvps; dir: direction of push; maximum: maximum nodes to be pushed
|
||||
np = {x = pos.x, y = pos.y, z = pos.z}
|
||||
|
||||
-- determine the number of nodes to be pushed
|
||||
local nodes = {}
|
||||
while true do
|
||||
nn = minetest.env:get_node_or_nil(np)
|
||||
if not nn or #nodes > maximum then
|
||||
-- don't push at all, something is in the way (unloaded map or too many nodes)
|
||||
return
|
||||
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)
|
||||
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)
|
||||
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
|
||||
|
||||
function mesecon:mvps_pull_all(pos, direction) -- pos: pos of mvps; direction: direction of pull
|
||||
local lpos = {x=pos.x-direction.x, y=pos.y-direction.y, z=pos.z-direction.z} -- 1 away
|
||||
local lnode = minetest.env:get_node(lpos)
|
||||
|
@ -1,15 +1,25 @@
|
||||
minetest.register_node("mesecons_noteblock:noteblock", {
|
||||
description = "Noteblock",
|
||||
tiles = {"mesecons_noteblock.png"},
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2},
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
|
||||
drawtype = "allfaces_optional",
|
||||
visual_scale = 1.3,
|
||||
paramtype="light",
|
||||
after_place_node = function(pos)
|
||||
minetest.env:add_node(pos, {name="mesecons_noteblock:noteblock", param2=0})
|
||||
end,
|
||||
on_punch = function (pos, node) -- change sound when punched
|
||||
local param2 = node.param2+1
|
||||
if param2==12 then param2=0 end
|
||||
minetest.env:add_node(pos, {name = node.name, param2 = param2})
|
||||
mesecon.noteblock_play(pos, param2)
|
||||
end,
|
||||
mesecons = {effector = { -- play sound when activated
|
||||
action_on = function (pos, node)
|
||||
mesecon.noteblock_play(pos, node.param2)
|
||||
end
|
||||
}}
|
||||
})
|
||||
mesecon:register_effector("mesecons_noteblock:noteblock", "mesecons_noteblock:noteblock")
|
||||
|
||||
minetest.register_craft({
|
||||
output = '"mesecons_noteblock:noteblock" 1',
|
||||
@ -20,15 +30,6 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_on_punchnode(function (pos, node)
|
||||
if node.name=="mesecons_noteblock:noteblock" then
|
||||
local param2 = node.param2+1
|
||||
if param2==12 then param2=0 end
|
||||
minetest.env:add_node(pos, {name=node.name, param2=param2})
|
||||
mesecon.noteblock_play(pos, param2)
|
||||
end
|
||||
end)
|
||||
|
||||
mesecon.noteblock_play = function (pos, param2)
|
||||
local soundname
|
||||
if param2==8 then
|
||||
@ -75,9 +76,3 @@ mesecon.noteblock_play = function (pos, param2)
|
||||
minetest.sound_play(soundname,
|
||||
{pos = pos, gain = 1.0, max_hear_distance = 32,})
|
||||
end
|
||||
|
||||
mesecon:register_on_signal_on(function(pos, node)
|
||||
if node.name=="mesecons_noteblock:noteblock" then
|
||||
mesecon.noteblock_play(pos, node.param2)
|
||||
end
|
||||
end)
|
||||
|
@ -1,3 +1,2 @@
|
||||
mesecons
|
||||
mesecons_materials
|
||||
mesecons_mvps
|
||||
|
@ -1,63 +1,696 @@
|
||||
--PISTONS
|
||||
-- Get mesecon rules of pistons
|
||||
piston_rules =
|
||||
{{x=0, y=0, z=1}, --everything apart from z- (pusher side)
|
||||
{x=1, y=0, z=0},
|
||||
{x=-1, y=0, z=0},
|
||||
{x=1, y=1, z=0},
|
||||
{x=1, y=-1, z=0},
|
||||
{x=-1, y=1, z=0},
|
||||
{x=-1, y=-1, z=0},
|
||||
{x=0, y=1, z=1},
|
||||
{x=0, y=-1, z=1}}
|
||||
|
||||
minetest.register_node("mesecons_pistons:piston_normal", {
|
||||
local piston_get_rules = function (node)
|
||||
local rules = piston_rules
|
||||
for i = 1, node.param2 do
|
||||
rules = mesecon:rotate_rules_left(rules)
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
piston_facedir_direction = function (node)
|
||||
local rules = {{x = 0, y = 0, z = -1}}
|
||||
for i = 1, node.param2 do
|
||||
rules = mesecon:rotate_rules_left(rules)
|
||||
end
|
||||
return rules[1]
|
||||
end
|
||||
|
||||
piston_get_direction = function (dir, node)
|
||||
if type(dir) == "function" then
|
||||
return dir(node)
|
||||
else
|
||||
return dir
|
||||
end
|
||||
end
|
||||
|
||||
local piston_remove_pusher = function (pos, node)
|
||||
pistonspec = minetest.registered_nodes[node.name].mesecons_piston
|
||||
|
||||
dir = piston_get_direction(pistonspec.dir, node)
|
||||
local pusherpos = mesecon:addPosRule(pos, dir)
|
||||
local pushername = minetest.env:get_node(pusherpos).name
|
||||
|
||||
if pushername == pistonspec.pusher then --make sure there actually is a pusher (for compatibility reasons mainly)
|
||||
minetest.env:remove_node(pusherpos)
|
||||
nodeupdate(pusherpos)
|
||||
end
|
||||
end
|
||||
|
||||
local piston_on = function (pos, node)
|
||||
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
|
||||
|
||||
dir = piston_get_direction(pistonspec.dir, node)
|
||||
local np = mesecon:addPosRule(pos, dir)
|
||||
success, stack = mesecon:mvps_push(np, dir, PISTON_MAXIMUM_PUSH)
|
||||
if success then
|
||||
minetest.env:add_node(pos, {param2 = node.param2, name = pistonspec.onname})
|
||||
minetest.env:add_node(np, {param2 = node.param2, name = pistonspec.pusher})
|
||||
mesecon:mvps_process_stack(stack)
|
||||
end
|
||||
end
|
||||
|
||||
local piston_off = function (pos, node)
|
||||
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
|
||||
minetest.env:add_node(pos, {param2 = node.param2, name = pistonspec.offname})
|
||||
piston_remove_pusher (pos, node)
|
||||
|
||||
if pistonspec.sticky then
|
||||
dir = piston_get_direction(pistonspec.dir, node)
|
||||
pullpos = mesecon:addPosRule(pos, dir)
|
||||
stack = mesecon:mvps_pull_single(pullpos, dir)
|
||||
mesecon:mvps_process_stack(stack)
|
||||
end
|
||||
end
|
||||
|
||||
local piston_orientate = function (pos, placer)
|
||||
-- not placed by player
|
||||
if not placer then return end
|
||||
|
||||
-- placer pitch in degrees
|
||||
local pitch = placer:get_look_pitch() * (180 / math.pi)
|
||||
|
||||
local node = minetest.env:get_node(pos)
|
||||
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
|
||||
if pitch > 55 then --looking upwards
|
||||
minetest.env:add_node(pos, {name=pistonspec.piston_down})
|
||||
elseif pitch < -55 then --looking downwards
|
||||
minetest.env:add_node(pos, {name=pistonspec.piston_up})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Horizontal pistons
|
||||
|
||||
local pt = 3/16 -- pusher thickness
|
||||
|
||||
local piston_pusher_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-2/16, -2/16, -.5 + pt, 2/16, 2/16, .5 + pt},
|
||||
{-.5 , -.5 , -.5 , .5 , .5 , -.5 + pt},
|
||||
}
|
||||
}
|
||||
|
||||
local piston_on_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-.5, -.5, -.5 + pt, .5, .5, .5}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-- Normal (non-sticky) ones:
|
||||
|
||||
local pistonspec_normal = {
|
||||
offname = "mesecons_pistons:piston_normal_off",
|
||||
onname = "mesecons_pistons:piston_normal_on",
|
||||
dir = piston_facedir_direction,
|
||||
pusher = "mesecons_pistons:piston_pusher_normal",
|
||||
piston_down = "mesecons_pistons:piston_down_normal_off",
|
||||
piston_up = "mesecons_pistons:piston_up_normal_off",
|
||||
}
|
||||
|
||||
-- offstate
|
||||
minetest.register_node("mesecons_pistons:piston_normal_off", {
|
||||
description = "Piston",
|
||||
tiles = {"jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_side.png"},
|
||||
groups = {cracky=3, mesecon=2},
|
||||
tiles = {
|
||||
"mesecons_piston_top.png",
|
||||
"mesecons_piston_bottom.png",
|
||||
"mesecons_piston_left.png",
|
||||
"mesecons_piston_right.png",
|
||||
"mesecons_piston_back.png",
|
||||
"mesecons_piston_pusher_front.png"
|
||||
},
|
||||
groups = {cracky = 3},
|
||||
paramtype2 = "facedir",
|
||||
after_destruct = function(pos, oldnode)
|
||||
local dir = mesecon:piston_get_direction(oldnode)
|
||||
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
|
||||
|
||||
--ensure piston is extended
|
||||
local checknode = minetest.env:get_node(pos)
|
||||
if checknode.name == "mesecons_pistons:piston_pusher_normal" then
|
||||
if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
|
||||
minetest.env:remove_node(pos) --remove the pusher
|
||||
end
|
||||
end
|
||||
end,
|
||||
on_timer = function(pos, elapsed)
|
||||
if mesecon:is_powered(pos) then
|
||||
mesecon:piston_push(pos)
|
||||
else
|
||||
mesecon:piston_pull(pos)
|
||||
end
|
||||
return false
|
||||
end,
|
||||
after_place_node = piston_orientate,
|
||||
mesecons_piston = pistonspec_normal,
|
||||
mesecons = {effector={
|
||||
action_on = piston_on,
|
||||
rules = piston_get_rules
|
||||
}}
|
||||
})
|
||||
mesecon:register_effector("mesecons_pistons:piston_normal", "mesecons_pistons:piston_normal")
|
||||
|
||||
minetest.register_node("mesecons_pistons:piston_sticky", {
|
||||
-- onstate
|
||||
minetest.register_node("mesecons_pistons:piston_normal_on", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"mesecons_piston_top.png",
|
||||
"mesecons_piston_bottom.png",
|
||||
"mesecons_piston_left.png",
|
||||
"mesecons_piston_right.png",
|
||||
"mesecons_piston_back.png",
|
||||
"mesecons_piston_on_front.png"
|
||||
},
|
||||
inventory_image = "mesecons_piston_top.png",
|
||||
wield_image = "mesecons_piston_top.png",
|
||||
groups = {cracky = 3, not_in_creative_inventory = 1},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drop = "mesecons_pistons:piston_normal_off",
|
||||
after_dig_node = piston_remove_pusher,
|
||||
node_box = piston_on_box,
|
||||
selection_box = piston_on_box,
|
||||
mesecons_piston = pistonspec_normal,
|
||||
mesecons = {effector={
|
||||
action_off = piston_off,
|
||||
rules = piston_get_rules
|
||||
}}
|
||||
})
|
||||
|
||||
-- pusher
|
||||
minetest.register_node("mesecons_pistons:piston_pusher_normal", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"mesecons_piston_pusher_top.png",
|
||||
"mesecons_piston_pusher_bottom.png",
|
||||
"mesecons_piston_pusher_left.png",
|
||||
"mesecons_piston_pusher_right.png",
|
||||
"mesecons_piston_pusher_back.png",
|
||||
"mesecons_piston_pusher_front.png"
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
diggable = false,
|
||||
corresponding_piston = "mesecons_pistons:piston_normal_on",
|
||||
selection_box = piston_pusher_box,
|
||||
node_box = piston_pusher_box,
|
||||
})
|
||||
|
||||
-- Sticky ones
|
||||
|
||||
local pistonspec_sticky = {
|
||||
offname = "mesecons_pistons:piston_sticky_off",
|
||||
onname = "mesecons_pistons:piston_sticky_on",
|
||||
dir = piston_facedir_direction,
|
||||
pusher = "mesecons_pistons:piston_pusher_sticky",
|
||||
sticky = true,
|
||||
piston_down = "mesecons_pistons:piston_down_sticky_off",
|
||||
piston_up = "mesecons_pistons:piston_up_sticky_off",
|
||||
}
|
||||
|
||||
-- offstate
|
||||
minetest.register_node("mesecons_pistons:piston_sticky_off", {
|
||||
description = "Sticky Piston",
|
||||
tiles = {"jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_sticky_side.png"},
|
||||
groups = {cracky=3, mesecon=2},
|
||||
tiles = {
|
||||
"mesecons_piston_top.png",
|
||||
"mesecons_piston_bottom.png",
|
||||
"mesecons_piston_left.png",
|
||||
"mesecons_piston_right.png",
|
||||
"mesecons_piston_back.png",
|
||||
"mesecons_piston_pusher_front_sticky.png"
|
||||
},
|
||||
groups = {cracky = 3},
|
||||
paramtype2 = "facedir",
|
||||
after_destruct = function(pos, oldnode)
|
||||
local dir = mesecon:piston_get_direction(oldnode)
|
||||
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
|
||||
|
||||
--ensure piston is extended
|
||||
local checknode = minetest.env:get_node(pos)
|
||||
if checknode.name == "mesecons_pistons:piston_pusher_sticky" then
|
||||
if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
|
||||
minetest.env:remove_node(pos) --remove the pusher
|
||||
end
|
||||
end
|
||||
end,
|
||||
on_timer = function(pos, elapsed)
|
||||
if mesecon:is_powered(pos) then
|
||||
mesecon:piston_push(pos)
|
||||
else
|
||||
mesecon:piston_pull(pos)
|
||||
end
|
||||
return false
|
||||
end,
|
||||
after_place_node = piston_orientate,
|
||||
mesecons_piston = pistonspec_sticky,
|
||||
mesecons = {effector={
|
||||
action_on = piston_on,
|
||||
rules = piston_get_rules
|
||||
}}
|
||||
})
|
||||
mesecon:register_effector("mesecons_pistons:piston_sticky", "mesecons_pistons:piston_sticky")
|
||||
|
||||
-- onstate
|
||||
minetest.register_node("mesecons_pistons:piston_sticky_on", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"mesecons_piston_top.png",
|
||||
"mesecons_piston_bottom.png",
|
||||
"mesecons_piston_left.png",
|
||||
"mesecons_piston_right.png",
|
||||
"mesecons_piston_back.png",
|
||||
"mesecons_piston_on_front.png"
|
||||
},
|
||||
inventory_image = "mesecons_piston_top.png",
|
||||
wield_image = "mesecons_piston_top.png",
|
||||
groups = {cracky = 3, not_in_creative_inventory = 1},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drop = "mesecons_pistons:piston_normal_off",
|
||||
after_dig_node = piston_remove_pusher,
|
||||
node_box = piston_on_box,
|
||||
selection_box = piston_on_box,
|
||||
mesecons_piston = pistonspec_sticky,
|
||||
mesecons = {effector={
|
||||
action_off = piston_off,
|
||||
rules = piston_get_rules
|
||||
}}
|
||||
})
|
||||
|
||||
-- pusher
|
||||
minetest.register_node("mesecons_pistons:piston_pusher_sticky", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"mesecons_piston_pusher_top.png",
|
||||
"mesecons_piston_pusher_bottom.png",
|
||||
"mesecons_piston_pusher_left.png",
|
||||
"mesecons_piston_pusher_right.png",
|
||||
"mesecons_piston_pusher_back.png",
|
||||
"mesecons_piston_pusher_front_sticky.png"
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
diggable = false,
|
||||
corresponding_piston = "mesecons_pistons:piston_sticky_on",
|
||||
selection_box = piston_pusher_box,
|
||||
node_box = piston_pusher_box,
|
||||
})
|
||||
|
||||
--
|
||||
--
|
||||
-- UP
|
||||
--
|
||||
--
|
||||
|
||||
local piston_up_pusher_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-2/16, -.5 - pt, -2/16, 2/16, .5, 2/16},
|
||||
{-.5 , .5 - pt, -.5 , .5 , .5, .5},
|
||||
}
|
||||
}
|
||||
|
||||
local piston_up_on_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-.5, -.5, -.5 , .5, .5-pt, .5}
|
||||
}
|
||||
}
|
||||
|
||||
-- Normal
|
||||
|
||||
local pistonspec_normal_up = {
|
||||
offname = "mesecons_pistons:piston_up_normal_off",
|
||||
onname = "mesecons_pistons:piston_up_normal_on",
|
||||
dir = {x = 0, y = 1, z = 0},
|
||||
pusher = "mesecons_pistons:piston_up_pusher_normal"
|
||||
}
|
||||
|
||||
-- offstate
|
||||
minetest.register_node("mesecons_pistons:piston_up_normal_off", {
|
||||
tiles = {
|
||||
"mesecons_piston_pusher_front.png",
|
||||
"mesecons_piston_back.png",
|
||||
"mesecons_piston_left.png^[transformR270",
|
||||
"mesecons_piston_right.png^[transformR90",
|
||||
"mesecons_piston_bottom.png",
|
||||
"mesecons_piston_top.png^[transformR180",
|
||||
},
|
||||
inventory_image = "mesecons_piston_top.png",
|
||||
wield_image = "mesecons_piston_top.png",
|
||||
groups = {cracky = 3, not_in_creative_inventory = 1},
|
||||
paramtype2 = "facedir",
|
||||
drop = "mesecons_pistons:piston_normal_off",
|
||||
mesecons_piston = pistonspec_normal_up,
|
||||
mesecons = {effector={
|
||||
action_on = piston_on,
|
||||
}}
|
||||
})
|
||||
|
||||
-- onstate
|
||||
minetest.register_node("mesecons_pistons:piston_up_normal_on", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"mesecons_piston_on_front.png",
|
||||
"mesecons_piston_back.png",
|
||||
"mesecons_piston_left.png^[transformR270",
|
||||
"mesecons_piston_right.png^[transformR90",
|
||||
"mesecons_piston_bottom.png",
|
||||
"mesecons_piston_top.png^[transformR180",
|
||||
},
|
||||
inventory_image = "mesecons_piston_top.png",
|
||||
wield_image = "mesecons_piston_top.png",
|
||||
groups = {cracky = 3, not_in_creative_inventory = 1},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drop = "mesecons_pistons:piston_normal_off",
|
||||
after_dig_node = piston_remove_pusher,
|
||||
node_box = piston_up_on_box,
|
||||
selection_box = piston_up_on_box,
|
||||
mesecons_piston = pistonspec_normal_up,
|
||||
mesecons = {effector={
|
||||
action_off = piston_off,
|
||||
}}
|
||||
})
|
||||
|
||||
-- pusher
|
||||
minetest.register_node("mesecons_pistons:piston_up_pusher_normal", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"mesecons_piston_pusher_front.png",
|
||||
"mesecons_piston_pusher_back.png",
|
||||
"mesecons_piston_pusher_left.png^[transformR270",
|
||||
"mesecons_piston_pusher_right.png^[transformR90",
|
||||
"mesecons_piston_pusher_bottom.png",
|
||||
"mesecons_piston_pusher_top.png^[transformR180",
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
diggable = false,
|
||||
corresponding_piston = "mesecons_pistons:piston_up_normal_on",
|
||||
selection_box = piston_up_pusher_box,
|
||||
node_box = piston_up_pusher_box,
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- Sticky
|
||||
|
||||
|
||||
local pistonspec_sticky_up = {
|
||||
offname = "mesecons_pistons:piston_up_sticky_off",
|
||||
onname = "mesecons_pistons:piston_up_sticky_on",
|
||||
dir = {x = 0, y = 1, z = 0},
|
||||
pusher = "mesecons_pistons:piston_up_pusher_sticky",
|
||||
sticky = true
|
||||
}
|
||||
|
||||
-- offstate
|
||||
minetest.register_node("mesecons_pistons:piston_up_sticky_off", {
|
||||
tiles = {
|
||||
"mesecons_piston_pusher_front_sticky.png",
|
||||
"mesecons_piston_back.png",
|
||||
"mesecons_piston_left.png^[transformR270",
|
||||
"mesecons_piston_right.png^[transformR90",
|
||||
"mesecons_piston_bottom.png",
|
||||
"mesecons_piston_top.png^[transformR180",
|
||||
"mesecons_piston_tb.png"
|
||||
},
|
||||
inventory_image = "mesecons_piston_top.png",
|
||||
wield_image = "mesecons_piston_top.png",
|
||||
groups = {cracky = 3, not_in_creative_inventory = 1},
|
||||
paramtype2 = "facedir",
|
||||
drop = "mesecons_pistons:piston_sticky_off",
|
||||
mesecons_piston = pistonspec_sticky_up,
|
||||
mesecons = {effector={
|
||||
action_on = piston_on,
|
||||
}}
|
||||
})
|
||||
|
||||
-- onstate
|
||||
minetest.register_node("mesecons_pistons:piston_up_sticky_on", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"mesecons_piston_on_front.png",
|
||||
"mesecons_piston_back.png",
|
||||
"mesecons_piston_left.png^[transformR270",
|
||||
"mesecons_piston_right.png^[transformR90",
|
||||
"mesecons_piston_bottom.png",
|
||||
"mesecons_piston_top.png^[transformR180",
|
||||
},
|
||||
inventory_image = "mesecons_piston_top.png",
|
||||
wield_image = "mesecons_piston_top.png",
|
||||
groups = {cracky = 3, not_in_creative_inventory = 1},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drop = "mesecons_pistons:piston_normal_off",
|
||||
after_dig_node = piston_remove_pusher,
|
||||
node_box = piston_up_on_box,
|
||||
selection_box = piston_up_on_box,
|
||||
mesecons_piston = pistonspec_sticky_up,
|
||||
mesecons = {effector={
|
||||
action_off = piston_off,
|
||||
}}
|
||||
})
|
||||
|
||||
-- pusher
|
||||
minetest.register_node("mesecons_pistons:piston_up_pusher_sticky", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"mesecons_piston_pusher_front_sticky.png",
|
||||
"mesecons_piston_pusher_back.png",
|
||||
"mesecons_piston_pusher_left.png^[transformR270",
|
||||
"mesecons_piston_pusher_right.png^[transformR90",
|
||||
"mesecons_piston_pusher_bottom.png",
|
||||
"mesecons_piston_pusher_top.png^[transformR180",
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
diggable = false,
|
||||
corresponding_piston = "mesecons_pistons:piston_up_sticky_on",
|
||||
selection_box = piston_up_pusher_box,
|
||||
node_box = piston_up_pusher_box,
|
||||
})
|
||||
|
||||
--
|
||||
--
|
||||
-- DOWN
|
||||
--
|
||||
--
|
||||
|
||||
local piston_down_pusher_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-2/16, -.5, -2/16, 2/16, .5 + pt, 2/16},
|
||||
{-.5 , -.5, -.5 , .5 , -.5 + pt, .5},
|
||||
}
|
||||
}
|
||||
|
||||
local piston_down_on_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-.5, -.5+pt, -.5 , .5, .5, .5}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- Normal
|
||||
|
||||
local pistonspec_normal_down = {
|
||||
offname = "mesecons_pistons:piston_down_normal_off",
|
||||
onname = "mesecons_pistons:piston_down_normal_on",
|
||||
dir = {x = 0, y = -1, z = 0},
|
||||
pusher = "mesecons_pistons:piston_down_pusher_normal",
|
||||
}
|
||||
|
||||
-- offstate
|
||||
minetest.register_node("mesecons_pistons:piston_down_normal_off", {
|
||||
tiles = {
|
||||
"mesecons_piston_back.png",
|
||||
"mesecons_piston_pusher_front.png",
|
||||
"mesecons_piston_left.png^[transformR90",
|
||||
"mesecons_piston_right.png^[transformR270",
|
||||
"mesecons_piston_bottom.png^[transformR180",
|
||||
"mesecons_piston_top.png",
|
||||
},
|
||||
inventory_image = "mesecons_piston_top.png",
|
||||
wield_image = "mesecons_piston_top.png",
|
||||
groups = {cracky = 3, not_in_creative_inventory = 1},
|
||||
paramtype2 = "facedir",
|
||||
drop = "mesecons_pistons:piston_normal_off",
|
||||
mesecons_piston = pistonspec_normal_down,
|
||||
mesecons = {effector={
|
||||
action_on = piston_on,
|
||||
}}
|
||||
})
|
||||
|
||||
-- onstate
|
||||
minetest.register_node("mesecons_pistons:piston_down_normal_on", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"mesecons_piston_back.png",
|
||||
"mesecons_piston_on_front.png",
|
||||
"mesecons_piston_left.png^[transformR90",
|
||||
"mesecons_piston_right.png^[transformR270",
|
||||
"mesecons_piston_bottom.png^[transformR180",
|
||||
"mesecons_piston_top.png",
|
||||
},
|
||||
inventory_image = "mesecons_piston_top.png",
|
||||
wield_image = "mesecons_piston_top.png",
|
||||
groups = {cracky = 3, not_in_creative_inventory = 1},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drop = "mesecons_pistons:piston_normal_off",
|
||||
after_dig_node = piston_remove_pusher,
|
||||
node_box = piston_down_on_box,
|
||||
selection_box = piston_down_on_box,
|
||||
mesecons_piston = pistonspec_normal_down,
|
||||
mesecons = {effector={
|
||||
action_off = piston_off,
|
||||
}}
|
||||
})
|
||||
|
||||
-- pusher
|
||||
minetest.register_node("mesecons_pistons:piston_down_pusher_normal", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"mesecons_piston_pusher_back.png",
|
||||
"mesecons_piston_pusher_front.png",
|
||||
"mesecons_piston_pusher_left.png^[transformR90",
|
||||
"mesecons_piston_pusher_right.png^[transformR270",
|
||||
"mesecons_piston_pusher_bottom.png^[transformR180",
|
||||
"mesecons_piston_pusher_top.png",
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
diggable = false,
|
||||
corresponding_piston = "mesecons_pistons:piston_down_normal_on",
|
||||
selection_box = piston_down_pusher_box,
|
||||
node_box = piston_down_pusher_box,
|
||||
})
|
||||
|
||||
-- Sticky
|
||||
|
||||
local pistonspec_sticky_down = {
|
||||
onname = "mesecons_pistons:piston_down_sticky_on",
|
||||
offname = "mesecons_pistons:piston_down_sticky_off",
|
||||
dir = {x = 0, y = -1, z = 0},
|
||||
pusher = "mesecons_pistons:piston_down_pusher_sticky",
|
||||
sticky = true
|
||||
}
|
||||
|
||||
-- offstate
|
||||
minetest.register_node("mesecons_pistons:piston_down_sticky_off", {
|
||||
tiles = {
|
||||
"mesecons_piston_back.png",
|
||||
"mesecons_piston_pusher_front_sticky.png",
|
||||
"mesecons_piston_left.png^[transformR90",
|
||||
"mesecons_piston_right.png^[transformR270",
|
||||
"mesecons_piston_bottom.png^[transformR180",
|
||||
"mesecons_piston_top.png",
|
||||
},
|
||||
inventory_image = "mesecons_piston_top.png",
|
||||
wield_image = "mesecons_piston_top.png",
|
||||
groups = {cracky = 3, not_in_creative_inventory = 1},
|
||||
paramtype2 = "facedir",
|
||||
drop = "mesecons_pistons:piston_sticky_off",
|
||||
mesecons_piston = pistonspec_sticky_down,
|
||||
mesecons = {effector={
|
||||
action_on = piston_on,
|
||||
}}
|
||||
})
|
||||
|
||||
-- onstate
|
||||
minetest.register_node("mesecons_pistons:piston_down_sticky_on", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"mesecons_piston_back.png",
|
||||
"mesecons_piston_on_front.png",
|
||||
"mesecons_piston_left.png^[transformR90",
|
||||
"mesecons_piston_right.png^[transformR270",
|
||||
"mesecons_piston_bottom.png^[transformR180",
|
||||
"mesecons_piston_top.png",
|
||||
},
|
||||
inventory_image = "mesecons_piston_top.png",
|
||||
wield_image = "mesecons_piston_top.png",
|
||||
groups = {cracky = 3, not_in_creative_inventory = 1},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drop = "mesecons_pistons:piston_sticky_off",
|
||||
after_dig_node = piston_remove_pusher,
|
||||
node_box = piston_down_on_box,
|
||||
selection_box = piston_down_on_box,
|
||||
mesecons_piston = pistonspec_sticky_down,
|
||||
mesecons = {effector={
|
||||
action_off = piston_off,
|
||||
}}
|
||||
})
|
||||
|
||||
-- pusher
|
||||
minetest.register_node("mesecons_pistons:piston_down_pusher_sticky", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"mesecons_piston_pusher_back.png",
|
||||
"mesecons_piston_pusher_front_sticky.png",
|
||||
"mesecons_piston_pusher_left.png^[transformR90",
|
||||
"mesecons_piston_pusher_right.png^[transformR270",
|
||||
"mesecons_piston_pusher_bottom.png^[transformR180",
|
||||
"mesecons_piston_pusher_top.png",
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
diggable = false,
|
||||
corresponding_piston = "mesecons_pistons:piston_down_sticky_on",
|
||||
selection_box = piston_down_pusher_box,
|
||||
node_box = piston_down_pusher_box,
|
||||
})
|
||||
|
||||
|
||||
-- Register pushers as stoppers if they would be seperated from the piston
|
||||
local piston_pusher_get_stopper = function (node, dir, stack, stackid)
|
||||
if (stack[stackid + 1]
|
||||
and stack[stackid + 1].node.name == minetest.registered_nodes[node.name].corresponding_piston
|
||||
and stack[stackid + 1].node.param2 == node.param2)
|
||||
or (stack[stackid - 1]
|
||||
and stack[stackid - 1].node.name == minetest.registered_nodes[node.name].corresponding_piston
|
||||
and stack[stackid - 1].node.param2 == node.param2) then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local piston_pusher_up_down_get_stopper = function (node, dir, stack, stackid)
|
||||
if (stack[stackid + 1]
|
||||
and stack[stackid + 1].node.name == minetest.registered_nodes[node.name].corresponding_piston)
|
||||
or (stack[stackid - 1]
|
||||
and stack[stackid - 1].node.name == minetest.registered_nodes[node.name].corresponding_piston) then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_normal", piston_pusher_get_stopper)
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_sticky", piston_pusher_get_stopper)
|
||||
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_pusher_normal", piston_pusher_up_down_get_stopper)
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_pusher_sticky", piston_pusher_up_down_get_stopper)
|
||||
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_pusher_normal", piston_pusher_up_down_get_stopper)
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_pusher_sticky", piston_pusher_up_down_get_stopper)
|
||||
|
||||
|
||||
-- Register pistons as stoppers if they would be seperated from the stopper
|
||||
local piston_up_down_get_stopper = function (node, dir, stack, stackid)
|
||||
if (stack[stackid + 1]
|
||||
and stack[stackid + 1].node.name == minetest.registered_nodes[node.name].mesecons_piston.pusher)
|
||||
or (stack[stackid - 1]
|
||||
and stack[stackid - 1].node.name == minetest.registered_nodes[node.name].mesecons_piston.pusher) then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local piston_get_stopper = function (node, dir, stack, stackid)
|
||||
pistonspec = minetest.registered_nodes[node.name].mesecons_piston
|
||||
dir = piston_get_direction(pistonspec.dir, node)
|
||||
local pusherpos = mesecon:addPosRule(stack[stackid].pos, dir)
|
||||
local pushernode = minetest.env:get_node(pusherpos)
|
||||
|
||||
if minetest.registered_nodes[node.name].mesecons_piston.pusher == pushernode.name then
|
||||
for _, s in ipairs(stack) do
|
||||
if mesecon:cmpPos(s.pos, pusherpos) -- pusher is also to be pushed
|
||||
and s.node.param2 == node.param2 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_normal_on", piston_get_stopper)
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_sticky_on", piston_get_stopper)
|
||||
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_normal_on", piston_up_down_get_stopper)
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_sticky_on", piston_up_down_get_stopper)
|
||||
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_normal_on", piston_up_down_get_stopper)
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_sticky_on", piston_up_down_get_stopper)
|
||||
|
||||
--craft recipes
|
||||
minetest.register_craft({
|
||||
output = '"mesecons_pistons:piston_normal" 2',
|
||||
output = 'mesecons_pistons:piston_normal_off 2',
|
||||
recipe = {
|
||||
{"default:wood", "default:wood", "default:wood"},
|
||||
{"default:cobble", "default:steel_ingot", "default:cobble"},
|
||||
@ -66,188 +699,9 @@ minetest.register_craft({
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "mesecons_pistons:piston_sticky",
|
||||
output = "mesecons_pistons:piston_sticky_off",
|
||||
recipe = {
|
||||
{"mesecons_materials:glue"},
|
||||
{"mesecons_pistons:piston_normal"},
|
||||
{"mesecons_pistons:piston_normal_off"},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_pistons:piston_pusher_normal", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {"jeija_piston_pusher_normal.png"},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
diggable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.2, -0.2, -0.3, 0.2, 0.2, 0.5},
|
||||
{-0.5, -0.5, -0.5, 0.5, 0.5, -0.3},
|
||||
},
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.2, -0.2, -0.3, 0.2, 0.2, 0.5},
|
||||
{-0.5, -0.5, -0.5, 0.5, 0.5, -0.3},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_pistons:piston_pusher_sticky", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"jeija_piston_pusher_normal.png",
|
||||
"jeija_piston_pusher_normal.png",
|
||||
"jeija_piston_pusher_normal.png",
|
||||
"jeija_piston_pusher_normal.png",
|
||||
"jeija_piston_pusher_normal.png",
|
||||
"jeija_piston_pusher_sticky.png"
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
diggable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.2, -0.2, -0.3, 0.2, 0.2, 0.5},
|
||||
{-0.5, -0.5, -0.5, 0.5, 0.5, -0.3},
|
||||
},
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.2, -0.2, -0.3, 0.2, 0.2, 0.5},
|
||||
{-0.5, -0.5, -0.5, 0.5, 0.5, -0.3},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_normal")
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_sticky")
|
||||
|
||||
local update = function(pos, node)
|
||||
if node.name ~= "mesecons_pistons:piston_normal" and node.name ~= "mesecons_pistons:piston_sticky" then
|
||||
return
|
||||
end
|
||||
|
||||
local timer = minetest.env:get_node_timer(pos)
|
||||
timer:stop()
|
||||
timer:start(0)
|
||||
end
|
||||
mesecon:register_on_signal_on(update) --push action
|
||||
mesecon:register_on_signal_off(update) --pull action
|
||||
|
||||
function mesecon:piston_push(pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
local dir = mesecon:piston_get_direction(node)
|
||||
pos = {x=pos.x + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --move to first node being pushed
|
||||
|
||||
--determine the number of nodes that need to be pushed
|
||||
local count = 0
|
||||
local checkpos = {x=pos.x, y=pos.y, z=pos.z} --first node being pushed
|
||||
while true do
|
||||
local checknode = minetest.env:get_node(checkpos)
|
||||
|
||||
--check for collision with stopper or bounds
|
||||
if mesecon:is_mvps_stopper(checknode.name) or checknode.name == "ignore" then
|
||||
return
|
||||
end
|
||||
|
||||
--check for column end
|
||||
if checknode.name == "air"
|
||||
or not(minetest.registered_nodes[checknode.name].liquidtype == "none") then
|
||||
break
|
||||
end
|
||||
|
||||
--limit piston pushing capacity
|
||||
count = count + 1
|
||||
if count > 15 then
|
||||
return
|
||||
end
|
||||
|
||||
checkpos.x, checkpos.y, checkpos.z = checkpos.x + dir.x, checkpos.y + dir.y, checkpos.z + dir.z
|
||||
end
|
||||
|
||||
local checknode = minetest.env:get_node(pos)
|
||||
|
||||
--add pusher
|
||||
if node.name == "mesecons_pistons:piston_normal" then
|
||||
minetest.env:add_node(pos, {name="mesecons_pistons:piston_pusher_normal", param2=node.param2})
|
||||
else
|
||||
minetest.env:add_node(pos, {name="mesecons_pistons:piston_pusher_sticky", param2=node.param2})
|
||||
end
|
||||
|
||||
--move nodes forward
|
||||
for i = 1, count do
|
||||
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the next node
|
||||
|
||||
--check for conductor
|
||||
if mesecon:is_conductor_on(checknode.name) then
|
||||
checknode.name = mesecon:get_conductor_off(checknode.name)
|
||||
end
|
||||
|
||||
--move the node forward
|
||||
local nextnode = minetest.env:get_node(pos)
|
||||
minetest.env:add_node(pos, checknode)
|
||||
checknode = nextnode
|
||||
end
|
||||
|
||||
--update nodes
|
||||
for i = 1, count do
|
||||
mesecon:updatenode(pos)
|
||||
nodeupdate(pos)
|
||||
|
||||
pos.x, pos.y, pos.z = pos.x - dir.x, pos.y - dir.y, pos.z - dir.z --move to the previous node
|
||||
end
|
||||
end
|
||||
|
||||
function mesecon:piston_pull(pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
local dir = mesecon:piston_get_direction(node)
|
||||
pos = {x=pos.x + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --move to first node being replaced
|
||||
|
||||
--ensure piston is extended
|
||||
local checknode = minetest.env:get_node(pos)
|
||||
if checknode.name ~= "mesecons_pistons:piston_pusher_normal" and checknode.name ~= "mesecons_pistons:piston_pusher_sticky" then
|
||||
return
|
||||
end
|
||||
if checknode.param2 ~= node.param2 then --pusher is not facing the same direction as the piston
|
||||
return --piston is not extended
|
||||
end
|
||||
|
||||
--retract piston
|
||||
minetest.env:remove_node(pos) --remove pusher
|
||||
if node.name == "mesecons_pistons:piston_sticky" then --retract block
|
||||
local checkpos = {x=pos.x + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --move to the node to be retracted
|
||||
checknode = minetest.env:get_node(checkpos)
|
||||
if checknode.name ~= "air"
|
||||
and checknode.name ~= "ignore"
|
||||
and minetest.registered_nodes[checknode.name].liquidtype == "none"
|
||||
and not mesecon:is_mvps_stopper(checknode.name) then
|
||||
minetest.env:add_node(pos, checknode)
|
||||
minetest.env:remove_node(checkpos)
|
||||
mesecon:updatenode(checkpos)
|
||||
nodeupdate(checkpos)
|
||||
end
|
||||
end
|
||||
mesecon:updatenode(pos)
|
||||
nodeupdate(pos)
|
||||
end
|
||||
|
||||
-- get piston direction
|
||||
function mesecon:piston_get_direction(node)
|
||||
if node.param2 == 3 then
|
||||
return {x=1, y=0, z=0}
|
||||
elseif node.param2 == 2 then
|
||||
return {x=0, y=0, z=1}
|
||||
elseif node.param2 == 1 then
|
||||
return {x=-1, y=0, z=0}
|
||||
else --node.param2 == 0
|
||||
return {x=0, y=0, z=-1}
|
||||
end
|
||||
end
|
||||
|
||||
dofile(minetest.get_modpath("mesecons_pistons").."/pistons_down.lua")
|
||||
dofile(minetest.get_modpath("mesecons_pistons").."/pistons_up.lua")
|
||||
|
@ -1,214 +0,0 @@
|
||||
--PISTONS
|
||||
--registration normal one:
|
||||
minetest.register_node("mesecons_pistons:piston_down_normal", {
|
||||
description = "Piston DOWN",
|
||||
tiles = {"jeija_piston_tb.png", "jeija_piston_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"},
|
||||
groups = {cracky=3, mesecon = 2},
|
||||
after_dig_node = function(pos, oldnode)
|
||||
local dir = {x=0, y=-1, z=0}
|
||||
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
|
||||
|
||||
--ensure piston is extended
|
||||
local checknode = minetest.env:get_node(pos)
|
||||
if checknode.name == "mesecons_pistons:piston_down_pusher_normal" then
|
||||
if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
|
||||
minetest.env:remove_node(pos) --remove the pusher
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
mesecon:register_effector("mesecons_pistons:piston_down_normal", "mesecons_pistons:piston_down_normal")
|
||||
|
||||
--registration sticky one:
|
||||
minetest.register_node("mesecons_pistons:piston_down_sticky", {
|
||||
description = "Sticky Piston DOWN",
|
||||
tiles = {"jeija_piston_tb.png", "jeija_piston_sticky_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"},
|
||||
groups = {cracky=3, mesecon = 2},
|
||||
after_dig_node = function(pos, oldnode)
|
||||
local dir = {x=0, y=-1, z=0}
|
||||
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
|
||||
|
||||
--ensure piston is extended
|
||||
local checknode = minetest.env:get_node(pos)
|
||||
if checknode.name == "mesecons_pistons:piston_down_pusher_sticky" then
|
||||
if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
|
||||
minetest.env:remove_node(pos) --remove the pusher
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
mesecon:register_effector("mesecons_pistons:piston_down_sticky", "mesecons_pistons:piston_down_sticky")
|
||||
|
||||
minetest.register_craft({
|
||||
output = "mesecons_pistons:piston_down_normal",
|
||||
recipe = {
|
||||
{"mesecons_pistons:piston_up_normal"},
|
||||
}
|
||||
})
|
||||
minetest.register_craft({
|
||||
output = "mesecons_pistons:piston_normal",
|
||||
recipe = {
|
||||
{"mesecons_pistons:piston_down_normal"},
|
||||
}
|
||||
})
|
||||
minetest.register_craft({
|
||||
output = "mesecons_pistons:piston_down_sticky",
|
||||
recipe = {
|
||||
{"mesecons_pistons:piston_up_sticky"},
|
||||
}
|
||||
})
|
||||
minetest.register_craft({
|
||||
output = "mesecons_pistons:piston_sticky",
|
||||
recipe = {
|
||||
{"mesecons_pistons:piston_down_sticky"},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_pistons:piston_down_pusher_normal", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {"jeija_piston_pusher_normal.png"},
|
||||
paramtype = "light",
|
||||
diggable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.2, -0.3, -0.2, 0.2, 0.5, 0.2},
|
||||
{-0.5, -0.5, -0.5, 0.5, -0.3, 0.5},
|
||||
},
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.2, -0.3, -0.2, 0.2, 0.5, 0.2},
|
||||
{-0.5, -0.5, -0.5, 0.5, -0.3, 0.5},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_pusher_normal")
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_pusher_sticky")
|
||||
|
||||
minetest.register_node("mesecons_pistons:piston_down_pusher_sticky", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"jeija_piston_pusher_sticky.png",
|
||||
"jeija_piston_pusher_normal.png",
|
||||
"jeija_piston_pusher_normal.png",
|
||||
"jeija_piston_pusher_normal.png",
|
||||
"jeija_piston_pusher_normal.png",
|
||||
"jeija_piston_pusher_normal.png"
|
||||
},
|
||||
paramtype = "light",
|
||||
diggable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.2, -0.3, -0.2, 0.2, 0.5, 0.2},
|
||||
{-0.5, -0.5, -0.5, 0.5, -0.3, 0.5},
|
||||
},
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.2, -0.3, -0.2, 0.2, 0.5, 0.2},
|
||||
{-0.5, -0.5, -0.5, 0.5, -0.3, 0.5},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
-- Push action
|
||||
mesecon:register_on_signal_on(function(pos, node)
|
||||
if node.name ~= "mesecons_pistons:piston_down_normal" and node.name ~= "mesecons_pistons:piston_down_sticky" then
|
||||
return
|
||||
end
|
||||
|
||||
local dir = {x=0, y=-1, z=0}
|
||||
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node being pushed
|
||||
|
||||
--determine the number of nodes that need to be pushed
|
||||
local count = 0
|
||||
local checkpos = {x=pos.x, y=pos.y, z=pos.z} --first node being pushed
|
||||
while true do
|
||||
local checknode = minetest.env:get_node(checkpos)
|
||||
|
||||
--check for collision with stopper or bounds
|
||||
if mesecon:is_mvps_stopper(checknode.name) or checknode.name == "ignore" then
|
||||
return
|
||||
end
|
||||
|
||||
--check for column end
|
||||
if checknode.name == "air"
|
||||
or not(minetest.registered_nodes[checknode.name].liquidtype == "none") then
|
||||
break
|
||||
end
|
||||
|
||||
--limit piston pushing capacity
|
||||
count = count + 1
|
||||
if count > 15 then
|
||||
return
|
||||
end
|
||||
|
||||
checkpos.x, checkpos.y, checkpos.z = checkpos.x + dir.x, checkpos.y + dir.y, checkpos.z + dir.z
|
||||
end
|
||||
|
||||
local checknode = minetest.env:get_node(pos)
|
||||
minetest.env:remove_node(pos) --remove the first node
|
||||
mesecon:updatenode(pos)
|
||||
|
||||
--add pusher
|
||||
if node.name == "mesecons_pistons:piston_down_normal" then
|
||||
minetest.env:add_node(pos, {name="mesecons_pistons:piston_down_pusher_normal", param2=node.param2})
|
||||
else
|
||||
minetest.env:add_node(pos, {name="mesecons_pistons:piston_down_pusher_sticky", param2=node.param2})
|
||||
end
|
||||
|
||||
--move nodes forward
|
||||
for i = 1, count do
|
||||
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the next node
|
||||
|
||||
--move the node forward
|
||||
local nextnode = minetest.env:get_node(pos)
|
||||
--minetest.env:dig_node(pos)
|
||||
minetest.env:set_node(pos, checknode)
|
||||
mesecon:updatenode(pos)
|
||||
checknode = nextnode
|
||||
end
|
||||
end)
|
||||
|
||||
--Pull action
|
||||
mesecon:register_on_signal_off(function(pos, node)
|
||||
if node.name ~= "mesecons_pistons:piston_down_normal" and node.name ~= "mesecons_pistons:piston_down_sticky" then
|
||||
return
|
||||
end
|
||||
|
||||
local dir = {x=0, y=-1, z=0}
|
||||
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the node to be replaced
|
||||
|
||||
--ensure piston is extended
|
||||
local checknode = minetest.env:get_node(pos)
|
||||
if checknode.name ~= "mesecons_pistons:piston_down_pusher_normal" and checknode.name ~= "mesecons_pistons:piston_down_pusher_sticky" then
|
||||
return
|
||||
end
|
||||
if checknode.param2 ~= node.param2 then --pusher is not facing the same direction as the piston
|
||||
return --piston is not extended
|
||||
end
|
||||
|
||||
--retract piston
|
||||
minetest.env:remove_node(pos) --remove pusher
|
||||
if node.name == "mesecons_pistons:piston_down_sticky" then --retract block
|
||||
local checkpos = {x=pos.x + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --move to the node to be retracted
|
||||
checknode = minetest.env:get_node(checkpos)
|
||||
if checknode.name ~= "air"
|
||||
and checknode.name ~= "ignore"
|
||||
and minetest.registered_nodes[checknode.name].liquidtype == "none"
|
||||
and not mesecon:is_mvps_stopper(checknode.name) then
|
||||
minetest.env:remove_node(checkpos)
|
||||
mesecon:updatenode(checkpos)
|
||||
minetest.env:set_node(pos, checknode)
|
||||
mesecon:updatenode(pos)
|
||||
end
|
||||
end
|
||||
nodeupdate(pos)
|
||||
end)
|
@ -1,202 +0,0 @@
|
||||
--PISTONS
|
||||
--registration normal one:
|
||||
minetest.register_node("mesecons_pistons:piston_up_normal", {
|
||||
description = "Piston UP",
|
||||
tiles = {"jeija_piston_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"},
|
||||
groups = {cracky=3, mesecon = 2},
|
||||
after_dig_node = function(pos, oldnode)
|
||||
local dir = {x=0, y=1, z=0}
|
||||
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
|
||||
|
||||
--ensure piston is extended
|
||||
local checknode = minetest.env:get_node(pos)
|
||||
if checknode.name == "mesecons_pistons:piston_up_pusher_normal" then
|
||||
if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
|
||||
minetest.env:remove_node(pos) --remove the pusher
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
mesecon:register_effector("mesecons_pistons:piston_up_normal", "mesecons_pistons:piston_up_normal")
|
||||
|
||||
--registration sticky one:
|
||||
minetest.register_node("mesecons_pistons:piston_up_sticky", {
|
||||
description = "Sticky Piston UP",
|
||||
tiles = {"jeija_piston_sticky_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"},
|
||||
groups = {cracky=3, mesecon = 2},
|
||||
after_dig_node = function(pos, oldnode)
|
||||
local dir = {x=0, y=1, z=0}
|
||||
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check
|
||||
|
||||
--ensure piston is extended
|
||||
local checknode = minetest.env:get_node(pos)
|
||||
if checknode.name == "mesecons_pistons:piston_up_pusher_sticky" then
|
||||
if checknode.param2 == oldnode.param2 then --pusher is facing the same direction as the piston
|
||||
minetest.env:remove_node(pos) --remove the pusher
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
mesecon:register_effector("mesecons_pistons:piston_up_sticky", "mesecons_pistons:piston_up_sticky")
|
||||
|
||||
minetest.register_craft({
|
||||
output = "mesecons_pistons:piston_up_normal",
|
||||
recipe = {
|
||||
{"mesecons_pistons:piston_normal"},
|
||||
}
|
||||
})
|
||||
minetest.register_craft({
|
||||
output = "mesecons_pistons:piston_up_sticky",
|
||||
recipe = {
|
||||
{"mesecons_pistons:piston_sticky"},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_pistons:piston_up_pusher_normal", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {"jeija_piston_pusher_normal.png"},
|
||||
paramtype = "light",
|
||||
diggable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.2, -0.5, -0.2, 0.2, 0.3, 0.2},
|
||||
{-0.5, 0.3, -0.5, 0.5, 0.5, 0.5},
|
||||
},
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.2, -0.5, -0.2, 0.2, 0.3, 0.2},
|
||||
{-0.5, 0.3, -0.5, 0.5, 0.5, 0.5},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_pusher_normal")
|
||||
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_pusher_sticky")
|
||||
|
||||
minetest.register_node("mesecons_pistons:piston_up_pusher_sticky", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"jeija_piston_pusher_normal.png",
|
||||
"jeija_piston_pusher_sticky.png",
|
||||
"jeija_piston_pusher_normal.png",
|
||||
"jeija_piston_pusher_normal.png",
|
||||
"jeija_piston_pusher_normal.png",
|
||||
"jeija_piston_pusher_normal.png"
|
||||
},
|
||||
paramtype = "light",
|
||||
diggable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.2, -0.5, -0.2, 0.2, 0.3, 0.2},
|
||||
{-0.5, 0.3, -0.5, 0.5, 0.5, 0.5},
|
||||
},
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.2, -0.5, -0.2, 0.2, 0.3, 0.2},
|
||||
{-0.5, 0.3, -0.5, 0.5, 0.5, 0.5},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
-- Push action
|
||||
mesecon:register_on_signal_on(function(pos, node)
|
||||
if node.name ~= "mesecons_pistons:piston_up_normal" and node.name ~= "mesecons_pistons:piston_up_sticky" then
|
||||
return
|
||||
end
|
||||
|
||||
local dir = {x=0, y=1, z=0}
|
||||
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node being pushed
|
||||
|
||||
--determine the number of nodes that need to be pushed
|
||||
local count = 0
|
||||
local checkpos = {x=pos.x, y=pos.y, z=pos.z} --first node being pushed
|
||||
while true do
|
||||
local checknode = minetest.env:get_node(checkpos)
|
||||
|
||||
--check for collision with stopper or bounds
|
||||
if mesecon:is_mvps_stopper(checknode.name) or checknode.name == "ignore" then
|
||||
return
|
||||
end
|
||||
|
||||
--check for column end
|
||||
if checknode.name == "air"
|
||||
or not(minetest.registered_nodes[checknode.name].liquidtype == "none") then
|
||||
break
|
||||
end
|
||||
|
||||
--limit piston pushing capacity
|
||||
count = count + 1
|
||||
if count > 15 then
|
||||
return
|
||||
end
|
||||
|
||||
checkpos.x, checkpos.y, checkpos.z = checkpos.x + dir.x, checkpos.y + dir.y, checkpos.z + dir.z
|
||||
end
|
||||
|
||||
local checknode = minetest.env:get_node(pos)
|
||||
minetest.env:remove_node(pos) --remove the first node
|
||||
mesecon:updatenode(pos)
|
||||
|
||||
--add pusher
|
||||
if node.name == "mesecons_pistons:piston_up_normal" then
|
||||
minetest.env:add_node(pos, {name="mesecons_pistons:piston_up_pusher_normal", param2=node.param2})
|
||||
else
|
||||
minetest.env:add_node(pos, {name="mesecons_pistons:piston_up_pusher_sticky", param2=node.param2})
|
||||
end
|
||||
|
||||
--move nodes forward
|
||||
for i = 1, count do
|
||||
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the next node
|
||||
|
||||
--move the node forward
|
||||
local nextnode = minetest.env:get_node(pos)
|
||||
--minetest.env:dig_node(pos)
|
||||
minetest.env:set_node(pos, checknode)
|
||||
mesecon:updatenode(pos)
|
||||
checknode = nextnode
|
||||
end
|
||||
end)
|
||||
|
||||
--Pull action
|
||||
mesecon:register_on_signal_off(function(pos, node)
|
||||
if node.name ~= "mesecons_pistons:piston_up_normal" and node.name ~= "mesecons_pistons:piston_up_sticky" then
|
||||
return
|
||||
end
|
||||
|
||||
local dir = {x=0, y=1, z=0}
|
||||
pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to the node to be replaced
|
||||
|
||||
--ensure piston is extended
|
||||
local checknode = minetest.env:get_node(pos)
|
||||
if checknode.name ~= "mesecons_pistons:piston_up_pusher_normal" and checknode.name ~= "mesecons_pistons:piston_up_pusher_sticky" then
|
||||
return
|
||||
end
|
||||
if checknode.param2 ~= node.param2 then --pusher is not facing the same direction as the piston
|
||||
return --piston is not extended
|
||||
end
|
||||
|
||||
--retract piston
|
||||
minetest.env:remove_node(pos) --remove pusher
|
||||
if node.name == "mesecons_pistons:piston_up_sticky" then --retract block
|
||||
local checkpos = {x=pos.x + dir.x, y=pos.y + dir.y, z=pos.z + dir.z} --move to the node to be retracted
|
||||
checknode = minetest.env:get_node(checkpos)
|
||||
if checknode.name ~= "air"
|
||||
and checknode.name ~= "ignore"
|
||||
and minetest.registered_nodes[checknode.name].liquidtype == "none"
|
||||
and not mesecon:is_mvps_stopper(checknode.name) then
|
||||
minetest.env:remove_node(checkpos)
|
||||
mesecon:updatenode(checkpos)
|
||||
minetest.env:set_node(pos, checknode)
|
||||
mesecon:updatenode(pos)
|
||||
end
|
||||
end
|
||||
nodeupdate(pos)
|
||||
end)
|
@ -1,4 +1,5 @@
|
||||
-- The POWER_PLANT
|
||||
-- Just emits power. always.
|
||||
|
||||
minetest.register_node("mesecons_powerplant:power_plant", {
|
||||
drawtype = "plantlike",
|
||||
@ -14,6 +15,9 @@ minetest.register_node("mesecons_powerplant:power_plant", {
|
||||
type = "fixed",
|
||||
fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
|
||||
},
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.on
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
@ -24,5 +28,3 @@ minetest.register_craft({
|
||||
{'"default:sapling"'},
|
||||
}
|
||||
})
|
||||
|
||||
mesecon:add_receptor_node("mesecons_powerplant:power_plant")
|
||||
|
@ -1,174 +1,113 @@
|
||||
-- PRESSURE PLATE WOOD
|
||||
|
||||
minetest.register_node("mesecons_pressureplates:pressure_plate_wood_off", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {"jeija_pressure_plate_wood_off.png"},
|
||||
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 = {
|
||||
local pp_box_off = {
|
||||
type = "fixed",
|
||||
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
|
||||
},
|
||||
node_box = {
|
||||
}
|
||||
|
||||
local pp_box_on = {
|
||||
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",
|
||||
}
|
||||
|
||||
pp_on_timer = function (pos, elapsed)
|
||||
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
|
||||
|
||||
on_timer = function(pos, elapsed)
|
||||
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
|
||||
local objpos = obj:getpos()
|
||||
if objpos.y > pos.y-1 and objpos.y < pos.y then
|
||||
minetest.env:add_node(pos, {name="mesecons_pressureplates:pressure_plate_wood_on"})
|
||||
mesecon:receptor_on(pos, mesecon:get_rules("pressureplate"))
|
||||
minetest.env:add_node(pos, {name=ppspec.onstate})
|
||||
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
|
||||
return true
|
||||
end,
|
||||
end
|
||||
|
||||
-- Register a Pressure Plate
|
||||
-- offstate: name of the pressure plate when inactive
|
||||
-- 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
|
||||
|
||||
function mesecon:register_pressure_plate(offstate, onstate, description, texture_off, texture_on, recipe)
|
||||
local ppspec = {
|
||||
offstate = offstate,
|
||||
onstate = onstate
|
||||
}
|
||||
|
||||
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_wood_on", {
|
||||
minetest.register_node(onstate, {
|
||||
drawtype = "nodebox",
|
||||
tiles = {"jeija_pressure_plate_wood_on.png"},
|
||||
tiles = {texture_on},
|
||||
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, 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, mesecon:get_rules("pressureplate"))
|
||||
end
|
||||
return true
|
||||
end,
|
||||
|
||||
selection_box = pp_box_on,
|
||||
node_box = pp_box_on,
|
||||
groups = {snappy = 2, oddly_breakable_by_hand = 3, not_in_creative_inventory = 1},
|
||||
drop = offstate,
|
||||
pressureplate = ppspec,
|
||||
on_timer = pp_on_timer,
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.on
|
||||
}},
|
||||
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"'},
|
||||
}
|
||||
output = offstate,
|
||||
recipe = recipe,
|
||||
})
|
||||
|
||||
-- PRESSURE PLATE STONE
|
||||
|
||||
minetest.register_node("mesecons_pressureplates:pressure_plate_stone_off", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {"jeija_pressure_plate_stone_off.png"},
|
||||
inventory_image = "jeija_pressure_plate_stone_off.png",
|
||||
wield_image = "jeija_pressure_plate_stone_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="Stone Pressure Plate",
|
||||
|
||||
on_timer = function(pos, elapsed)
|
||||
local objs = minetest.env:get_objects_inside_radius(pos, 1)
|
||||
for k, obj in pairs(objs) do
|
||||
local objpos=obj:getpos()
|
||||
if objpos.y>pos.y-1 and objpos.y<pos.y then
|
||||
minetest.env:add_node(pos, {name="mesecons_pressureplates:pressure_plate_stone_on"})
|
||||
mesecon:receptor_on(pos, mesecon:get_rules("pressureplate"))
|
||||
end
|
||||
end
|
||||
return true
|
||||
end,
|
||||
|
||||
on_construct = function(pos)
|
||||
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
|
||||
end,
|
||||
})
|
||||
mesecon:register_pressure_plate(
|
||||
"mesecons_pressureplates:pressure_plate_wood_off",
|
||||
"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"}})
|
||||
|
||||
minetest.register_node("mesecons_pressureplates:pressure_plate_stone_on", {
|
||||
drawtype = "nodebox",
|
||||
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, mesecon = 2},
|
||||
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, mesecon:get_rules("pressureplate"))
|
||||
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_stone_off" 1',
|
||||
recipe = {
|
||||
{'"default:cobble"', '"default:cobble"'},
|
||||
}
|
||||
})
|
||||
|
||||
mesecon:add_rules("pressureplate",
|
||||
{{x=0, y=1, z=-1},
|
||||
{x=0, y=0, z=-1},
|
||||
{x=0, y=-1, z=-1},
|
||||
{x=0, y=1, z=1},
|
||||
{x=0, y=-1, z=1},
|
||||
{x=0, y=0, z=1},
|
||||
{x=1, y=0, z=0},
|
||||
{x=1, y=1, z=0},
|
||||
{x=1, y=-1, z=0},
|
||||
{x=-1, y=1, z=0},
|
||||
{x=-1, y=-1, z=0},
|
||||
{x=-1, y=0, z=0},
|
||||
{x=0, y=-1, z=0},
|
||||
{x=0, y=-2, z=0},
|
||||
{x=0, y=1, z=0}})
|
||||
|
||||
mesecon:add_receptor_node("mesecons_pressureplates:pressure_plate_wood_on", mesecon:get_rules("pressureplate"))
|
||||
mesecon:add_receptor_node_off("mesecons_pressureplates:pressure_plate_wood_off", mesecon:get_rules("pressureplate"))
|
||||
|
||||
mesecon:add_receptor_node("mesecons_pressureplates:pressure_plate_stone_on", mesecon:get_rules("pressureplate"))
|
||||
mesecon:add_receptor_node_off("mesecons_pressureplates:pressure_plate_stone_off", mesecon:get_rules("pressureplate"))
|
||||
mesecon:register_pressure_plate(
|
||||
"mesecons_pressureplates:pressure_plate_stone_off",
|
||||
"mesecons_pressureplates:pressure_plate_stone_on",
|
||||
"Stone Pressure Plate",
|
||||
"jeija_pressure_plate_stone_off.png",
|
||||
"jeija_pressure_plate_stone_on.png",
|
||||
{{"default:cobble", "default:cobble"}})
|
||||
|
@ -3,12 +3,16 @@
|
||||
minetest.register_node("mesecons_random:removestone", {
|
||||
tiles = {"jeija_removestone.png"},
|
||||
inventory_image = minetest.inventorycube("jeija_removestone_inv.png"),
|
||||
groups = {cracky=3, mesecon=2},
|
||||
groups = {cracky=3},
|
||||
description="Removestone",
|
||||
mesecons = {effector = {
|
||||
action_on = function (pos, node)
|
||||
minetest.env:remove_node(pos)
|
||||
mesecon:update_autoconnect(pos)
|
||||
end
|
||||
}}
|
||||
})
|
||||
|
||||
mesecon:register_effector(nil, "mesecons_random:removestone")
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'mesecons_random:removestone 4',
|
||||
recipe = {
|
||||
@ -18,12 +22,6 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
mesecon:register_on_signal_on(function(pos, node)
|
||||
if node.name == "mesecons_random:removestone" then
|
||||
minetest.env:remove_node(pos)
|
||||
end
|
||||
end)
|
||||
|
||||
-- GHOSTSTONE
|
||||
|
||||
minetest.register_node("mesecons_random:ghoststone", {
|
||||
@ -31,8 +29,20 @@ minetest.register_node("mesecons_random:ghoststone", {
|
||||
tiles = {"jeija_ghoststone.png"},
|
||||
is_ground_content = true,
|
||||
inventory_image = minetest.inventorycube("jeija_ghoststone_inv.png"),
|
||||
groups = {cracky=3, mesecon=2},
|
||||
groups = {cracky=3},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
mesecons = {conductor = {
|
||||
state = mesecon.state.off,
|
||||
rules = { --axes
|
||||
{x = -1, y = 0, z = 0},
|
||||
{x = 1, y = 0, z = 0},
|
||||
{x = 0, y = -1, z = 0},
|
||||
{x = 0, y = 1, z = 0},
|
||||
{x = 0, y = 0, z = -1},
|
||||
{x = 0, y = 0, z = 1},
|
||||
},
|
||||
onstate = "mesecons_random:ghoststone_active"
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_random:ghoststone_active", {
|
||||
@ -41,10 +51,28 @@ minetest.register_node("mesecons_random:ghoststone_active", {
|
||||
walkable = false,
|
||||
diggable = false,
|
||||
sunlight_propagates = true,
|
||||
groups = {mesecon=2},
|
||||
paramtype = "light",
|
||||
mesecons = {conductor = {
|
||||
state = mesecon.state.on,
|
||||
rules = {
|
||||
{x = -1, y = 0, z = 0},
|
||||
{x = 1, y = 0, z = 0},
|
||||
{x = 0, y = -1, z = 0},
|
||||
{x = 0, y = 1, z = 0},
|
||||
{x = 0, y = 0, z = -1},
|
||||
{x = 0, y = 0, z = 1},
|
||||
},
|
||||
offstate = "mesecons_random:ghoststone"
|
||||
}},
|
||||
on_construct = function(pos)
|
||||
--remove shadow
|
||||
pos2 = {x = pos.x, y = pos.y + 1, z = pos.z}
|
||||
if ( minetest.env:get_node(pos2).name == "air" ) then
|
||||
minetest.env:dig_node(pos2)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
mesecon:register_effector("mesecons_random:ghoststone_active", "mesecons_random:ghoststone")
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'mesecons_random:ghoststone 4',
|
||||
@ -54,17 +82,3 @@ minetest.register_craft({
|
||||
{"default:steel_ingot", "default:cobble", "default:steel_ingot"},
|
||||
}
|
||||
})
|
||||
|
||||
mesecon:register_on_signal_on(function(pos, node)
|
||||
if node.name == "mesecons_random:ghoststone" then
|
||||
minetest.env:add_node(pos, {name="mesecons_random:ghoststone_active"})
|
||||
nodeupdate(pos)
|
||||
end
|
||||
end)
|
||||
|
||||
mesecon:register_on_signal_off(function(pos, node)
|
||||
if node.name == "mesecons_random:ghoststone_active" then
|
||||
minetest.env:add_node(pos, {name="mesecons_random:ghoststone"})
|
||||
nodeupdate(pos)
|
||||
end
|
||||
end)
|
@ -1,10 +1,23 @@
|
||||
rcvboxes = {
|
||||
{ -3/16, -3/16 , -8/16 , 3/16, 3/16, -13/32 }, -- the smaller bump
|
||||
{ -5/32, -5/32 , -13/32 , 5/32, 5/32, -12/32 }, -- the receiver itself
|
||||
{ -3/32, -.5-1/32, -.5 , 3/32, 0 , -.5002+3/32 }, -- the vertical wire bit
|
||||
{ -3/32, -17/32 , -7/16+0.002 , 3/32, -13/32, 16/32+0.001 } -- the horizontal wire
|
||||
{ -1/32, -1/32 , -3/2 , 1/32, 1/32, -1/2 }, -- the wire through the block
|
||||
{ -2/32, -.5-1/32, -.5 , 2/32, 0 , -.5002+3/32 }, -- the vertical wire bit
|
||||
{ -2/32, -17/32 , -7/16+0.002 , 2/32, -14/32, 16/32+0.001 } -- the horizontal wire
|
||||
}
|
||||
|
||||
local receiver_get_rules = function (node)
|
||||
local rules = { {x = 1, y = 0, z = 0},
|
||||
{x = -2, y = 0, z = 0}}
|
||||
if node.param2 == 2 then
|
||||
rules = mesecon:rotate_rules_left(rules)
|
||||
elseif node.param2 == 3 then
|
||||
rules = mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules))
|
||||
elseif node.param2 == 0 then
|
||||
rules = mesecon:rotate_rules_right(rules)
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
minetest.register_node("mesecons_receiver:receiver_on", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
@ -18,6 +31,7 @@ minetest.register_node("mesecons_receiver:receiver_on", {
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
sunlight_propagates = true,
|
||||
walkable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -3/16, -8/16, -8/16, 3/16, 3/16, 8/16 }
|
||||
@ -26,9 +40,13 @@ minetest.register_node("mesecons_receiver:receiver_on", {
|
||||
type = "fixed",
|
||||
fixed = rcvboxes
|
||||
},
|
||||
groups = {dig_immediate = 3, mesecon = 3, not_in_creative_inventory = 1},
|
||||
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
||||
drop = "mesecons:wire_00000000_off",
|
||||
|
||||
mesecons = {conductor = {
|
||||
state = mesecon.state.on,
|
||||
rules = receiver_get_rules,
|
||||
offstate = "mesecons_receiver:receiver_off"
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_receiver:receiver_off", {
|
||||
@ -45,6 +63,7 @@ minetest.register_node("mesecons_receiver:receiver_off", {
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
sunlight_propagates = true,
|
||||
walkable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -3/16, -8/16, -8/16, 3/16, 3/16, 8/16 }
|
||||
@ -53,8 +72,13 @@ minetest.register_node("mesecons_receiver:receiver_off", {
|
||||
type = "fixed",
|
||||
fixed = rcvboxes
|
||||
},
|
||||
groups = {dig_immediate = 3, mesecon = 3, not_in_creative_inventory = 1},
|
||||
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
||||
drop = "mesecons:wire_00000000_off",
|
||||
mesecons = {conductor = {
|
||||
state = mesecon.state.off,
|
||||
rules = receiver_get_rules,
|
||||
onstate = "mesecons_receiver:receiver_on"
|
||||
}}
|
||||
})
|
||||
|
||||
mesecon:add_rules("receiver_pos", {{x = 2, y = 0, z = 0}})
|
||||
@ -65,34 +89,6 @@ mesecon:add_rules("receiver_pos_all", {
|
||||
{x = 0, y = 0, z = 2},
|
||||
{x = 0, y = 0, z =-2}})
|
||||
|
||||
mesecon:add_rules("mesecon_receiver", {
|
||||
{x = 1, y = 0, z = 0},
|
||||
{x = -2, y = 0, z = 0},})
|
||||
|
||||
mesecon:add_rules("mesecon_receiver_all", {
|
||||
{x = 1, y = 0, z = 0},
|
||||
{x =-2, y = 0, z = 0},
|
||||
{x =-1, y = 0, z = 0},
|
||||
{x = 2, y = 0, z = 0},
|
||||
{x = 0, y = 0, z = 1},
|
||||
{x = 0, y = 0, z =-2},
|
||||
{x = 1, y = 0, z =-1},
|
||||
{x =-2, y = 0, z = 2},})
|
||||
|
||||
function receiver_get_rules(param2)
|
||||
local rules = mesecon:get_rules("mesecon_receiver")
|
||||
if param2 == 2 then
|
||||
rules = mesecon:rotate_rules_left(rules)
|
||||
elseif param2 == 3 then
|
||||
rules = mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules))
|
||||
elseif param2 == 0 then
|
||||
rules = mesecon:rotate_rules_right(rules)
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
mesecon:register_conductor("mesecons_receiver:receiver_on", "mesecons_receiver:receiver_off", mesecon:get_rules("mesecon_receiver_all"), receiver_get_rules)
|
||||
|
||||
function mesecon:receiver_get_pos_from_rcpt(pos, param2)
|
||||
local rules = mesecon:get_rules("receiver_pos")
|
||||
if param2 == nil then param2 = minetest.env:get_node(pos).param2 end
|
||||
@ -119,7 +115,7 @@ function mesecon:receiver_place(rcpt_pos)
|
||||
minetest.env:dig_node(pos)
|
||||
if mesecon:is_power_on(rcpt_pos) then
|
||||
minetest.env:add_node(pos, {name = "mesecons_receiver:receiver_on", param2 = node.param2})
|
||||
mesecon:receptor_on(pos, receiver_get_rules(node.param2))
|
||||
mesecon:receptor_on(pos, receiver_get_rules(node))
|
||||
else
|
||||
minetest.env:add_node(pos, {name = "mesecons_receiver:receiver_off", param2 = node.param2})
|
||||
end
|
||||
@ -132,8 +128,10 @@ function mesecon:receiver_remove(rcpt_pos, dugnode)
|
||||
local nn = minetest.env:get_node(pos)
|
||||
if string.find(nn.name, "mesecons_receiver:receiver_") ~=nil then
|
||||
minetest.env:dig_node(pos)
|
||||
minetest.env:place_node(pos, {name = "mesecons:wire_00000000_off"})
|
||||
local node = {name = "mesecons:wire_00000000_off"}
|
||||
minetest.env:add_node(pos, node)
|
||||
mesecon:update_autoconnect(pos)
|
||||
mesecon.on_placenode(pos, node)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -21,8 +21,10 @@ minetest.register_node("mesecons_solarpanel:solar_panel_on", {
|
||||
wall_side = { -8/16, -7/16, -7/16, -7/16, 7/16, 7/16 },
|
||||
},
|
||||
drop = "mesecons_solarpanel:solar_panel_off",
|
||||
groups = {dig_immediate=3, mesecon = 2, not_in_creative_inventory = 1},
|
||||
description="Solar Panel",
|
||||
groups = {dig_immediate=3, not_in_creative_inventory = 1},
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.on
|
||||
}}
|
||||
})
|
||||
|
||||
-- Solar Panel
|
||||
@ -47,8 +49,11 @@ minetest.register_node("mesecons_solarpanel:solar_panel_off", {
|
||||
wall_top = { -7/16, 7/16, -7/16, 7/16, 8/16, 7/16 },
|
||||
wall_side = { -8/16, -7/16, -7/16, -7/16, 7/16, 7/16 },
|
||||
},
|
||||
groups = {dig_immediate=3, mesecon = 2},
|
||||
groups = {dig_immediate=3},
|
||||
description="Solar Panel",
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.off
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
@ -86,6 +91,3 @@ minetest.register_abm(
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
mesecon:add_receptor_node("mesecons_solarpanel:solar_panel_on")
|
||||
mesecon:add_receptor_node_off("mesecons_solarpanel:solar_panel_off")
|
||||
|
@ -3,32 +3,30 @@
|
||||
minetest.register_node("mesecons_switch:mesecon_switch_off", {
|
||||
tiles = {"jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_off.png"},
|
||||
paramtype2="facedir",
|
||||
groups = {dig_immediate=2, mesecon = 2},
|
||||
groups = {dig_immediate=2},
|
||||
description="Switch",
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.off
|
||||
}},
|
||||
on_punch = function(pos, node)
|
||||
mesecon:swap_node(pos, "mesecons_switch:mesecon_switch_on")
|
||||
mesecon:receptor_on(pos)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_switch:mesecon_switch_on", {
|
||||
tiles = {"jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_on.png"},
|
||||
paramtype2="facedir",
|
||||
groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon = 2},
|
||||
groups = {dig_immediate=2,not_in_creative_inventory=1},
|
||||
drop='"mesecons_switch:mesecon_switch_off" 1',
|
||||
description="Switch",
|
||||
})
|
||||
|
||||
mesecon:register_receptor("mesecons_switch:mesecon_switch_on", "mesecons_switch:mesecon_switch_off")
|
||||
|
||||
minetest.register_on_punchnode(function(pos, node, puncher)
|
||||
if node.name == "mesecons_switch:mesecon_switch_on" then
|
||||
minetest.env:add_node(pos, {name="mesecons_switch:mesecon_switch_off", param2=node.param2})
|
||||
nodeupdate(pos)
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.on
|
||||
}},
|
||||
on_punch = function(pos, node)
|
||||
mesecon:swap_node(pos, "mesecons_switch:mesecon_switch_off")
|
||||
mesecon:receptor_off(pos)
|
||||
end
|
||||
if node.name == "mesecons_switch:mesecon_switch_off" then
|
||||
minetest.env:add_node(pos, {name="mesecons_switch:mesecon_switch_on", param2=node.param2})
|
||||
nodeupdate(pos)
|
||||
mesecon:receptor_on(pos)
|
||||
end
|
||||
end)
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = '"mesecons_switch:mesecon_switch_off" 2',
|
||||
|
Before Width: | Height: | Size: 462 B |
After Width: | Height: | Size: 253 B |
BIN
mesecons_textures/textures/jeija_insulated_wire_curved_tb_on.png
Normal file
After Width: | Height: | Size: 196 B |
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 173 B |
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 166 B |
Before Width: | Height: | Size: 200 B After Width: | Height: | Size: 200 B |
BIN
mesecons_textures/textures/jeija_insulated_wire_sides_on.png
Normal file
After Width: | Height: | Size: 169 B |
After Width: | Height: | Size: 244 B |
After Width: | Height: | Size: 207 B |
Before Width: | Height: | Size: 793 B |
Before Width: | Height: | Size: 782 B |
Before Width: | Height: | Size: 793 B |
Before Width: | Height: | Size: 782 B |
Before Width: | Height: | Size: 778 B |
Before Width: | Height: | Size: 635 B |
Before Width: | Height: | Size: 715 B |
Before Width: | Height: | Size: 678 B |
Before Width: | Height: | Size: 579 B |
Before Width: | Height: | Size: 620 B |
Before Width: | Height: | Size: 678 B |
Before Width: | Height: | Size: 678 B |
Before Width: | Height: | Size: 590 B |
Before Width: | Height: | Size: 621 B |
Before Width: | Height: | Size: 678 B |
BIN
mesecons_textures/textures/mesecons_piston_back.png
Normal file
After Width: | Height: | Size: 763 B |
BIN
mesecons_textures/textures/mesecons_piston_bottom.png
Normal file
After Width: | Height: | Size: 791 B |
BIN
mesecons_textures/textures/mesecons_piston_left.png
Normal file
After Width: | Height: | Size: 790 B |
BIN
mesecons_textures/textures/mesecons_piston_on_front.png
Normal file
After Width: | Height: | Size: 759 B |
BIN
mesecons_textures/textures/mesecons_piston_pusher_back.png
Normal file
After Width: | Height: | Size: 781 B |
BIN
mesecons_textures/textures/mesecons_piston_pusher_bottom.png
Normal file
After Width: | Height: | Size: 762 B |
BIN
mesecons_textures/textures/mesecons_piston_pusher_front.png
Normal file
After Width: | Height: | Size: 759 B |
After Width: | Height: | Size: 738 B |
BIN
mesecons_textures/textures/mesecons_piston_pusher_left.png
Normal file
After Width: | Height: | Size: 790 B |
BIN
mesecons_textures/textures/mesecons_piston_pusher_right.png
Normal file
After Width: | Height: | Size: 802 B |
BIN
mesecons_textures/textures/mesecons_piston_pusher_top.png
Normal file
After Width: | Height: | Size: 787 B |
BIN
mesecons_textures/textures/mesecons_piston_right.png
Normal file
After Width: | Height: | Size: 786 B |
BIN
mesecons_textures/textures/mesecons_piston_top.png
Normal file
After Width: | Height: | Size: 790 B |
Before Width: | Height: | Size: 242 B After Width: | Height: | Size: 494 B |
Before Width: | Height: | Size: 247 B After Width: | Height: | Size: 239 B |
Before Width: | Height: | Size: 374 B After Width: | Height: | Size: 494 B |
Before Width: | Height: | Size: 517 B After Width: | Height: | Size: 239 B |
Before Width: | Height: | Size: 317 B After Width: | Height: | Size: 494 B |
Before Width: | Height: | Size: 321 B After Width: | Height: | Size: 239 B |
Before Width: | Height: | Size: 240 B After Width: | Height: | Size: 494 B |
Before Width: | Height: | Size: 245 B After Width: | Height: | Size: 239 B |
BIN
mesecons_textures/textures/wires_full_off.png
Normal file
After Width: | Height: | Size: 465 B |
BIN
mesecons_textures/textures/wires_full_on.png
Normal file
After Width: | Height: | Size: 464 B |
@ -1,13 +1,54 @@
|
||||
--MESECON TORCHES
|
||||
|
||||
local rotate_torch_rules = function (rules, param2)
|
||||
if param2 == 5 then
|
||||
return mesecon:rotate_rules_right(rules)
|
||||
elseif param2 == 2 then
|
||||
return mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules)) --180 degrees
|
||||
elseif param2 == 4 then
|
||||
return mesecon:rotate_rules_left(rules)
|
||||
elseif param2 == 1 then
|
||||
return mesecon:rotate_rules_down(rules)
|
||||
elseif param2 == 0 then
|
||||
return mesecon:rotate_rules_up(rules)
|
||||
else
|
||||
return rules
|
||||
end
|
||||
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
|
||||
|
||||
local torch_get_input_rules = function(node)
|
||||
local rules = {{x = -2, y = 0, z = 0},
|
||||
{x = -1, y = 1, z = 0}}
|
||||
|
||||
return rotate_torch_rules(rules, node.param2)
|
||||
end
|
||||
|
||||
minetest.register_craft({
|
||||
output = '"mesecons_torch:mesecon_torch_on" 4',
|
||||
recipe = {
|
||||
{"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", {
|
||||
drawtype = "torchlike",
|
||||
tiles = {"jeija_torches_off.png", "jeija_torches_off_ceiling.png", "jeija_torches_off_side.png"},
|
||||
@ -15,16 +56,13 @@ minetest.register_node("mesecons_torch:mesecon_torch_off", {
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
paramtype2 = "wallmounted",
|
||||
selection_box = {
|
||||
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,not_in_creative_inventory=1, mesecon = 2},
|
||||
drop = '"mesecons_torch:mesecon_torch_on" 1',
|
||||
description="Mesecon Torch",
|
||||
selection_box = torch_selectionbox,
|
||||
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
||||
drop = "mesecons_torch:mesecon_torch_on",
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.off,
|
||||
rules = torch_get_output_rules
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_node("mesecons_torch:mesecon_torch_on", {
|
||||
@ -36,87 +74,41 @@ minetest.register_node("mesecons_torch:mesecon_torch_on", {
|
||||
sunlight_propagates = true,
|
||||
walkable = false,
|
||||
paramtype2 = "wallmounted",
|
||||
selection_box = {
|
||||
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, mesecon = 2},
|
||||
selection_box = torch_selectionbox,
|
||||
groups = {dig_immediate=3},
|
||||
light_source = LIGHT_MAX-5,
|
||||
description="Mesecon Torch",
|
||||
mesecons = {receptor = {
|
||||
state = mesecon.state.on,
|
||||
rules = torch_get_output_rules
|
||||
}},
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"mesecons_torch:mesecon_torch_off","mesecons_torch:mesecon_torch_on"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local rules=mesecon.torch_get_rules(minetest.env:get_node(pos).param2)
|
||||
local pa = mesecon.torch_get_input_rules(node.param2)
|
||||
action = function(pos, node)
|
||||
local is_powered = false
|
||||
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 mesecon:is_power_on(postc) then
|
||||
if node.name ~= "mesecons_torch:mesecon_torch_off" then
|
||||
minetest.env:add_node(pos, {name="mesecons_torch:mesecon_torch_off",param2=node.param2})
|
||||
mesecon:receptor_off(pos, rules_string)
|
||||
end
|
||||
else
|
||||
if node.name ~= "mesecons_torch:mesecon_torch_on" then
|
||||
minetest.env:add_node(pos, {name="mesecons_torch:mesecon_torch_on",param2=node.param2})
|
||||
mesecon:receptor_on(pos, rules_string)
|
||||
if is_powered then
|
||||
if node.name == "mesecons_torch:mesecon_torch_on" then
|
||||
mesecon:swap_node(pos, "mesecons_torch:mesecon_torch_off")
|
||||
mesecon:receptor_off(pos, torch_get_output_rules(node))
|
||||
end
|
||||
elseif node.name == "mesecons_torch:mesecon_torch_off" then
|
||||
mesecon:swap_node(pos, "mesecons_torch:mesecon_torch_on")
|
||||
mesecon:receptor_on(pos, torch_get_output_rules(node))
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
mesecon.torch_get_rules = function(param2)
|
||||
local rules=mesecon:get_rules("mesecontorch")
|
||||
if param2 == 5 then
|
||||
rules=mesecon:rotate_rules_right(rules)
|
||||
elseif param2 == 2 then
|
||||
rules=mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules)) --180 degrees
|
||||
elseif param2 == 4 then
|
||||
rules=mesecon:rotate_rules_left(rules)
|
||||
elseif param2 == 1 then
|
||||
rules=mesecon:rotate_rules_down(rules)
|
||||
elseif param2 == 0 then
|
||||
rules=mesecon:rotate_rules_up(rules)
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
mesecon.torch_get_input_rules = function(param2)
|
||||
local rules = {x=0, y=0, z=0}
|
||||
|
||||
if param2 == 4 then
|
||||
rules.z = -2
|
||||
elseif param2 == 2 then
|
||||
rules.x = -2
|
||||
elseif param2 == 5 then
|
||||
rules.z = 2
|
||||
elseif param2 == 3 then
|
||||
rules.x = 2
|
||||
elseif param2 == 1 then
|
||||
rules.y = 2
|
||||
elseif param2 == 0 then
|
||||
rules.y = -2
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
mesecon:add_rules("mesecontorch",
|
||||
{{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}})
|
||||
|
||||
mesecon:add_receptor_node("mesecons_torch:mesecon_torch_on", nil, mesecon.torch_get_rules)
|
||||
mesecon:add_receptor_node_off("mesecons_torch:mesecon_torch_off", nil, mesecon.torch_get_rules)
|
||||
mesecon:register_effector("mesecons_torch:mesecon_torch_on","mesecons_torch:mesecon_torch_off", nil, mesecon.torch_get_input_rules)
|
||||
|
||||
-- Param2 Table (Block Attached To)
|
||||
-- 5 = z-1
|
||||
-- 3 = x-1
|
||||
|
@ -1,4 +1,6 @@
|
||||
-- WALL LEVER
|
||||
-- Basically a switch that can be attached to a wall
|
||||
-- Powers the block 2 nodes behind (using a receiver)
|
||||
minetest.register_node("mesecons_walllever:wall_lever_off", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
@ -27,8 +29,16 @@ minetest.register_node("mesecons_walllever:wall_lever_off", {
|
||||
{ -2/16, -1/16, 3/16, 2/16, 1/16, 4/16 }, -- the lever "hinge"
|
||||
{ -1/16, -8/16, 4/16, 1/16, 0, 6/16 }} -- the lever itself.
|
||||
},
|
||||
groups = {dig_immediate=2, mesecon = 3, mesecon_needs_receiver = 1},
|
||||
groups = {dig_immediate=2, mesecon_needs_receiver = 1},
|
||||
description="Lever",
|
||||
on_punch = function (pos, node)
|
||||
mesecon:swap_node(pos, "mesecons_walllever:wall_lever_on")
|
||||
mesecon:receptor_on(pos, mesecon.rules.buttonlike_get(node))
|
||||
end,
|
||||
mesecons = {receptor = {
|
||||
rules = mesecon.rules.buttonlike_get,
|
||||
state = mesecon.state.off
|
||||
}}
|
||||
})
|
||||
minetest.register_node("mesecons_walllever:wall_lever_on", {
|
||||
drawtype = "nodebox",
|
||||
@ -58,22 +68,19 @@ minetest.register_node("mesecons_walllever:wall_lever_on", {
|
||||
{ -2/16, -1/16, 3/16, 2/16, 1/16, 4/16 }, -- the lever "hinge"
|
||||
{ -1/16, 0, 4/16, 1/16, 8/16, 6/16 }} -- the lever itself.
|
||||
},
|
||||
groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon = 3, mesecon_needs_receiver = 1},
|
||||
groups = {dig_immediate = 2, not_in_creative_inventory = 1, mesecon_needs_receiver = 1},
|
||||
drop = '"mesecons_walllever:wall_lever_off" 1',
|
||||
description="Lever",
|
||||
on_punch = function (pos, node)
|
||||
mesecon:swap_node(pos, "mesecons_walllever:wall_lever_off")
|
||||
mesecon:receptor_off(pos, mesecon.rules.buttonlike_get(node))
|
||||
end,
|
||||
mesecons = {receptor = {
|
||||
rules = mesecon.rules.buttonlike_get,
|
||||
state = mesecon.state.on
|
||||
}}
|
||||
})
|
||||
|
||||
minetest.register_on_punchnode(function(pos, node, puncher)
|
||||
if node.name == "mesecons_walllever:wall_lever_off" then
|
||||
minetest.env:add_node(pos, {name="mesecons_walllever:wall_lever_on",param2=node.param2})
|
||||
mesecon:receptor_on(pos, mesecon.walllever_get_rules(node.param2))
|
||||
end
|
||||
if node.name == "mesecons_walllever:wall_lever_on" then
|
||||
minetest.env:add_node(pos, {name="mesecons_walllever:wall_lever_off",param2=node.param2})
|
||||
mesecon:receptor_off(pos, mesecon.walllever_get_rules(node.param2))
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_craft({
|
||||
output = '"mesecons_walllever:wall_lever_off" 2',
|
||||
recipe = {
|
||||
@ -82,29 +89,3 @@ minetest.register_craft({
|
||||
{'"default:stick"'},
|
||||
}
|
||||
})
|
||||
|
||||
mesecon:add_rules("walllever", {
|
||||
{x = 1, y = 0, z = 0},
|
||||
{x = 1, y = 1, z = 0},
|
||||
{x = 1, y =-1, z = 0},
|
||||
{x = 1, y =-1, z = 1},
|
||||
{x = 1, y =-1, z =-1},
|
||||
{x = 2, y = 0, z = 0},})
|
||||
|
||||
|
||||
mesecon.walllever_get_rules = function(param2)
|
||||
local rules=mesecon:get_rules("walllever")
|
||||
if param2 == 2 then
|
||||
rules=mesecon:rotate_rules_left(rules)
|
||||
end
|
||||
if param2 == 3 then
|
||||
rules=mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules))
|
||||
end
|
||||
if param2 == 0 then
|
||||
rules=mesecon:rotate_rules_right(rules)
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
mesecon:add_receptor_node("mesecons_walllever:wall_lever_on", nil, mesecon.walllever_get_rules)
|
||||
mesecon:add_receptor_node_off("mesecons_walllever:wall_lever_off", nil, mesecon.walllever_get_rules)
|
||||
|