Compare commits

...

43 Commits

Author SHA1 Message Date
DS
d80c788fab Change sticky movestone craft recipe
It used to be so that you could gain two sticky movestones out of one normal one,
this didn't make much sense.
2017-03-04 09:10:44 +01:00
Wuzzy
03ab151c87 Fix active ghoststones being droppable with sand
Fixes 
2017-02-15 23:00:02 +01:00
Vanessa Ezekowitz
dd2b36c41c fix wrong UV mapping on "on" turbine blades 2017-02-13 14:24:29 -05:00
Vanessa Ezekowitz
0cb286b425 Merge pull request from Jeija/animated_turbine
Make "on" water turbine animated!
2017-02-12 19:56:29 -05:00
Vanessa Ezekowitz
46cbc76988 make "on" water turbine animated!
This uses a fairly simple trick: the textures are animated, while the
model is static and has a number of rotated copies of the parts that are
seen to move (four copies of the blades, eight copies of the top/bottom
and their edges).  The opaque parts of the textures then decide which of
those faces' copies are visible in each frame.
2017-02-12 13:57:30 -05:00
Vanessa Ezekowitz
fa3bd19270 fix Z-fighting on water turbine 2017-02-12 10:56:54 -05:00
sfan5
2bc3c5d97c fpga: Make formspec usage less prone to breakage 2017-01-28 11:54:27 +01:00
sfan5
07d074075c FPGAs () 2017-01-28 11:33:13 +01:00
sfan5
5188853014 Make descriptions of insulated wires consistent
This allows finding all of them by searching
"insulated" in the creative menu.
2017-01-22 13:39:10 +01:00
sfan5
7667e7d8c5 Fix Lua error with microcontrollers
caused by an oversight in ececf525b6f717956a38fa314d2472f72451159d
2017-01-19 16:31:36 +01:00
sfan5
ececf525b6 Fix remaining namespace pollutions (closes ) 2017-01-15 23:12:13 +01:00
Jeija
54daee236e Luacontroller: Revert function stripping from digiline messages 2017-01-15 20:11:12 +01:00
sfan5
c2e3d7c4e5 Fix most of the namespace pollutions reported in 2017-01-15 11:53:49 +01:00
DS-Minetest
7415036f5b Make insulated cossover to mesh
This removes the weird "holes" in the isolation of the crossing
2017-01-02 14:59:52 +01:00
Carter Kolwey
1bd936ad8c Properly handle rotation of buttons / levers
Buttons and levers can now also be pointed upwards / downwards which will make them connect to corresponding up / down receivers. You will need to use the screwdriver for this.

Receivers cannot be rotated using the screwdriver anymore.
2017-01-02 14:51:28 +01:00
Carter Kolwey
79edbed8d7 Allow water turbines to work with river water (fixes )
This also makes turbines compatible with any liquid that is in the `water` group and has `liquidtype == "flowing"`.
2016-12-31 10:57:50 +01:00
Jeija
8743699298 Luacontroller: Fix bugs in 703e6fda, no more functions as keys
Thanks to @ShadowNinja for reporting this
Make sure functions that are keys in tables and functions inside nested tables also get removed when using digiline_send.
2016-12-31 10:43:45 +01:00
Jeija
703e6fdadb Luacontroller: Restrict digiline messages
Restrict maximum length of messages to 50.000 characters and disable sending functions or table references over the wire. Restrict types of channel variable to string, number or boolean.

The missing length restriction made DoS-like attacks possible by overflowing memory using string concatenation. Thanks to gamemanj for disclosing this issue.
2016-12-28 10:07:59 +01:00
Yutao Yuan
67cd17aa79 Fix crash with movestones 2016-12-04 19:37:31 +08:00
Christopher Head
203aaf3c90 Remove an unused function. 2016-11-17 14:55:02 +01:00
Jeija
95fedc88bc Never postpone action_on or action_off
There is no more need for that since VoxelManip caching makes sure we
always get an answer to get_node_force.
2016-09-04 09:50:30 +02:00
Jeija
433778c2ec Add Hawk777 to contributor list, update developer documentation URL 2016-09-04 09:32:41 +02:00
Jeija
54efc64558 Duplicate unhash_blockpos code to legacy.lua
Duplicating that small piece of code seems like a better idea than
putting the undo-forceloading code back into util.lua. This way, it is
easier to remember to remove that unneccesary code after a couple of
months / years, when people have transitioned. This also means we can
make changes to the code in util.lua without breaking old code.
2016-08-31 08:46:11 +02:00
Jeija
dfeb070a20 Remove some long unused legacy code
The change that required this compatibility layer happened in
2014, so other mods have had a lot of time to update.
2016-08-30 20:54:20 +02:00
Jeija
6dacdaee1f Small cleanups in internal.lua, move forceloading reversal to legacy 2016-08-30 19:37:43 +02:00
Jeija
e561be7fa3 Greatly improve performance by making use of VoxelManips in turnoff
Instead of seperately looking for onstate receptors along equipotential
sections of the circuit before turning off, do that while already
modifying the VoxelManip. In case an onstate receptor is found, discard
the VoxelManip cache, otherwise commit it after turnoff is completed.
2016-08-30 19:12:09 +02:00
Jeija
89153f6909 Further simplification of turnon/turnoff 2016-08-30 18:24:08 +02:00
Christopher Head
8e6536ca2e Simplify turnon/turnoff.
It is no longer possible for get_node_force to return nil if the target
location does, in fact, exist, because a VM will always be able to load
it (whereas a forceload might not, due to exhaustion of forceload
resources). So it is no longer necessary to handle get_node_force
returning nil by deferring processing.
2016-08-24 00:42:40 -07:00
Christopher Head
bc9d4c2d5a Use VM transactions for conductor state changes.
VoxelManipulator-based transactions are used to hopefully speed up
scanning and replacing of networks of conductors when receptors start or
stop driving signals into them.
2016-08-24 00:42:40 -07:00
Christopher Head
6d79272ed4 Implement VoxelManipulator-based transactions.
Rather than calling out through the Lua-to-C API for each node that
needs to be read or written, a group of map reads (and optionally
writes) can be grouped into a transaction. Access to map data within the
transaction is provided at high speed by means of VoxelManipulators.
Once the reads and writes are finished, the transaction can be committed
or aborted.
2016-08-24 00:42:38 -07:00
Christopher Head
564cee346a Use VoxelManipulators for get_node_force.
A VoxelManipulator, when asked to read a mapblock, in addition to making
that mapblock available to the caller, also pulls it into the server’s
map cache, thus making get_node calls in the immediate future succeed.

This has the dual advantages that not every mapblock containing a
Mesecons circuit need remain loaded at all times (rather mapblocks can
be loaded on demand as signals are sent), and that the server need not
bother running ABMs and ticking entities within those mapblocks that are
loaded due to Mesecons signalling.
2016-08-24 00:41:47 -07:00
Carter Kolwey
912f17f335 Split wires into their own mod, introduce autoconnect hooks
The update_autoconnect function had to be abstracted away from the
default wires, any kind of wire can now register autoconnect hooks,
which should make having multiple different wire types much easier.

mesecons_mvps, mesecons_receiver and mesecons_random made use of
update_autoconnect, their code was also adapted. This also fixes a
receiver bug: If a receiver was placed with a onstate receptor next
to it (but not the wall lever / button that caused the receiver to
appear) the receiver didn't turn on in the past.

Also move documentation for mesecon wire into mesecons_wire.
2016-08-23 11:08:53 +02:00
Carter Kolwey
4816dee396 Move shared textures into base mod (fixes a few LuaC issues) 2016-08-23 11:02:12 +02:00
Florian Euchner
a3042b44fc Merge pull request from Hawk777/luacontroller-comment
Remove an obsolete comment.
2016-08-16 12:14:33 +02:00
Christopher Head
53eaf2af11 Remove an obsolete comment. 2016-08-16 00:16:24 -07:00
Jeija
778ee427f4 Fix bug introduced in previous commit that broke all logic blocks
turnon / turnoff were calling activate / deactivate on nodes even though
their rules didn't link

Fixes , thanks to @darkfeels
2016-07-31 22:26:33 +02:00
Jeija
7c7595fd7d Fix : Fix bugs in block forceloading in turnon / turnoff
Thanks to @Hawk777 for reporting this problem
2016-07-25 10:01:43 +02:00
Carter Kolwey
acd41b5773 Don't bother checking if a node can overheat before cooling it 2016-07-09 11:17:08 +02:00
number Zero
f9f7600017 Command block server crash fixed
Before that, command block would crash the server if activated when no
players are online
2016-07-09 11:01:27 +02:00
Carter Kolwey
40487a65f4 Add protection support to Luacontrollers,
protection is ignored with protection_bypass_priv
2016-05-17 07:58:50 +02:00
Florian Euchner
75308f73e4 Merge pull request from Emon-Omen/patch-1
Fixed missing capital letter in "ghoststone"
2016-05-17 07:53:35 +02:00
Emon
478680292c fixed missing capital letter @ line 29 2016-05-16 22:24:56 +02:00
Jeija
85bc62a65d Add COPYING.txt file to clarify coprights and licenses 2016-05-16 08:04:57 +02:00
72 changed files with 3400 additions and 525 deletions
COPYING.txtREADME.mddocumentation.json
mesecons
mesecons_button
mesecons_commandblock
mesecons_delayer
mesecons_extrawires
mesecons_fpga
mesecons_gates
mesecons_hydroturbine
mesecons_insulated
mesecons_lamp
mesecons_luacontroller
mesecons_microcontroller
mesecons_movestones
doc/movestone_sticky
init.lua
mesecons_mvps
mesecons_pistons
mesecons_pressureplates
mesecons_random
mesecons_receiver
mesecons_walllever
mesecons_wires

30
COPYING.txt Normal file

@ -0,0 +1,30 @@
The Mesecons Mod for Minetest is
Copyright (C) 2011-2016 Mesecons Mod Developer Team and contributors
See the version control system log for information about other authors.
License of source code
----------------------
Copyright (C) 2011-2016 Mesecons Mod Developer Team and contributors
This program is free software; you can redistribute the Mesecons Mod and/or
modify it under the terms of the GNU Lesser General Public License version 3
published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
License of media (textures, sounds and documentation)
-----------------------------------------------------
Copyright (C) 2011-2016 Mesecons Mod Developer Team and contributors
All textures, sounds and documentation files are licensed under the
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
http://creativecommons.org/licenses/by-sa/3.0/

@ -53,6 +53,7 @@ These awesome people made Mesecons possible!
| Contributor | Contribution |
| --------------- | -------------------------------- |
| Hawk777 | Code for VoxelManip caching |
| Jat15 | Various tweaks. |
| Jeija | **Main developer! Everything.** |
| Jordach | Noteblock sounds. |

@ -1,6 +1,6 @@
{
"Conductors" : {
"Mesecon" : "mesecons/doc/mesecon",
"Mesecon" : "mesecons_wires/doc/mesecon",
"Insulated Wire" : "mesecons_insulated/doc/insulated",
"T-Junction" : "mesecons_extrawires/doc/tjunction",
"Crossing" : "mesecons_extrawires/doc/crossing",
@ -42,6 +42,8 @@
},
"Logic" : {
"Luacontroller" : "mesecons_luacontroller/doc/luacontroller",
"FPGA" : "mesecons_fpga/doc/fpga",
"FPGA Programmer" : "mesecons_fpga/doc/programmer",
"Torch" : "mesecons_torch/doc/torch",
"Delayer" : "mesecons_delayer/doc/delayer",
"Gates" : {

@ -87,7 +87,11 @@ minetest.register_globalstep(function (dtime)
end)
function mesecon.queue:execute(action)
mesecon.queue.funcs[action.func](action.pos, unpack(action.params))
-- ignore if action queue function name doesn't exist,
-- (e.g. in case the action queue savegame was written by an old mesecons version)
if mesecon.queue.funcs[action.func] then
mesecon.queue.funcs[action.func](action.pos, unpack(action.params))
end
end

@ -1 +0,0 @@
Mesecons are the wires, use them to connect effectors with receptors.

@ -3,7 +3,7 @@
-- | \/ | |___ ____ |___ | | | | \ | |____
-- | | | | | | | | | \ | |
-- | | |___ ____| |___ |____ |____| | \| ____|
-- by Jeija, Uberi (Temperest), sfan5, VanessaE
-- by Jeija, Uberi (Temperest), sfan5, VanessaE, Hawk777 and contributors
--
--
--
@ -11,7 +11,7 @@
-- See the documentation on the forum for additional information, especially about crafting
--
--
-- For developer documentation see the Developers' section on mesecons.TK
-- For basic development resources, see http://mesecons.net/developers.html
--
--
--
@ -70,19 +70,11 @@ dofile(minetest.get_modpath("mesecons").."/internal.lua");
-- these are the only functions you need to remember
mesecon.queue:add_function("receptor_on", function (pos, rules)
mesecon.vm_begin()
rules = rules or mesecon.rules.default
-- if area (any of the rule targets) is not loaded, keep trying and call this again later
for _, rule in ipairs(mesecon.flattenrules(rules)) do
local np = vector.add(pos, rule)
-- if area is not loaded, keep trying
if minetest.get_node_or_nil(np) == nil then
mesecon.queue:add_action(pos, "receptor_on", {rules}, nil, rules)
return
end
end
-- execute action
-- Call turnon on all linking positions
for _, rule in ipairs(mesecon.flattenrules(rules)) do
local np = vector.add(pos, rule)
local rulenames = mesecon.rules_link_rule_all(pos, rule)
@ -90,6 +82,8 @@ mesecon.queue:add_function("receptor_on", function (pos, rules)
mesecon.turnon(np, rulename)
end
end
mesecon.vm_commit()
end)
function mesecon.receptor_on(pos, rules)
@ -99,23 +93,21 @@ end
mesecon.queue:add_function("receptor_off", function (pos, rules)
rules = rules or mesecon.rules.default
-- if area (any of the rule targets) is not loaded, keep trying and call this again later
for _, rule in ipairs(mesecon.flattenrules(rules)) do
local np = vector.add(pos, rule)
if minetest.get_node_or_nil(np) == nil then
mesecon.queue:add_action(pos, "receptor_off", {rules}, nil, rules)
return
end
end
-- Call turnoff on all linking positions
for _, rule in ipairs(mesecon.flattenrules(rules)) do
local np = vector.add(pos, rule)
local rulenames = mesecon.rules_link_rule_all(pos, rule)
for _, rulename in ipairs(rulenames) do
if not mesecon.connected_to_receptor(np, mesecon.invertRule(rule)) then
mesecon.turnoff(np, rulename)
mesecon.vm_begin()
mesecon.changesignal(np, minetest.get_node(np), rulename, mesecon.state.off, 2)
-- Turnoff returns true if turnoff process was successful, no onstate receptor
-- was found along the way. Commit changes that were made in voxelmanip. If turnoff
-- returns true, an onstate receptor was found, abort voxelmanip transaction.
if (mesecon.turnoff(np, rulename)) then
mesecon.vm_commit()
else
mesecon.changesignal(np, minetest.get_node(np), rulename, mesecon.state.off, 2)
mesecon.vm_abort()
end
end
end
@ -132,8 +124,5 @@ print("[OK] Mesecons")
-- To be removed in future releases
dofile(minetest.get_modpath("mesecons").."/legacy.lua");
--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");

@ -37,11 +37,6 @@
-- 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, link) --> link is the input rule that caused calling turnon, turns on every connected node, iterative
-- mesecon.turnoff(pos, link) --> link is the input rule that caused calling turnoff, turns off every connected node, iterative
-- mesecon.connected_to_receptor(pos, link) --> Returns true if pos is connected to a receptor directly or via conductors, iterative
-- 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 helpers
@ -76,7 +71,7 @@ function mesecon.get_conductor(nodename)
end
end
function mesecon.get_any_outputrules (node)
function mesecon.get_any_outputrules(node)
if not node then return nil end
if mesecon.is_conductor(node.name) then
@ -86,7 +81,7 @@ function mesecon.get_any_outputrules (node)
end
end
function mesecon.get_any_inputrules (node)
function mesecon.get_any_inputrules(node)
if not node then return nil end
if mesecon.is_conductor(node.name) then
@ -96,7 +91,7 @@ function mesecon.get_any_inputrules (node)
end
end
function mesecon.get_any_rules (node)
function mesecon.get_any_rules(node)
return mesecon.mergetable(mesecon.get_any_inputrules(node) or {},
mesecon.get_any_outputrules(node) or {})
end
@ -371,38 +366,32 @@ function mesecon.is_power_off(pos, rulename)
return false
end
-- Turn off an equipotential section starting at `pos`, which outputs in the direction of `link`.
-- Breadth-first search. Map is abstracted away in a voxelmanip.
-- Follow all all conductor paths replacing conductors that were already
-- looked at, activating / changing all effectors along the way.
function mesecon.turnon(pos, link)
local frontiers = {{pos = pos, link = link}}
local depth = 1
while frontiers[depth] do
local f = frontiers[depth]
while frontiers[1] do
local f = table.remove(frontiers, 1)
local node = mesecon.get_node_force(f.pos)
-- area not loaded, postpone action
if not node then
mesecon.queue:add_action(f.pos, "turnon", {link}, nil, true)
-- Area does not exist; do nothing
elseif mesecon.is_conductor_off(node, f.link) then
local rules = mesecon.conductor_get_rules(node)
minetest.swap_node(f.pos, {name = mesecon.get_conductor_on(node, f.link),
param2 = node.param2})
-- call turnon on neighbors: normal rules
-- Call turnon on neighbors
for _, r in ipairs(mesecon.rule2meta(f.link, rules)) do
local np = vector.add(f.pos, r)
-- area not loaded, postpone action
if not mesecon.get_node_force(np) then
mesecon.queue:add_action(np, "turnon", {rulename},
nil, true)
else
local links = mesecon.rules_link_rule_all(f.pos, r)
for _, l in ipairs(links) do
table.insert(frontiers, {pos = np, link = l})
end
for _, l in ipairs(mesecon.rules_link_rule_all(f.pos, r)) do
table.insert(frontiers, {pos = np, link = l})
end
end
mesecon.swap_node_force(f.pos, mesecon.get_conductor_on(node, f.link))
elseif mesecon.is_effector(node.name) then
mesecon.changesignal(f.pos, node, f.link, mesecon.state.on, depth)
if mesecon.is_effector_off(node.name) then
@ -413,141 +402,81 @@ function mesecon.turnon(pos, link)
end
end
mesecon.queue:add_function("turnon", function (pos, rulename, recdepth)
mesecon.turnon(pos, rulename, recdepth)
end)
-- Turn on an equipotential section starting at `pos`, which outputs in the direction of `link`.
-- Breadth-first search. Map is abstracted away in a voxelmanip.
-- Follow all all conductor paths replacing conductors that were already
-- looked at, deactivating / changing all effectors along the way.
-- In case an onstate receptor is discovered, abort the process by returning false, which will
-- cause `receptor_off` to discard all changes made in the voxelmanip.
-- Contrary to turnon, turnoff has to cache all change and deactivate signals so that they will only
-- be called in the very end when we can be sure that no conductor was found along the path.
--
-- Signal table entry structure:
-- {
-- pos = position of effector,
-- node = node descriptor (name, param1 and param2),
-- link = link the effector is connected to,
-- depth = indicates order in which signals wire fired, higher is later
-- }
function mesecon.turnoff(pos, link)
local frontiers = {{pos = pos, link = link}}
local signals = {}
local depth = 1
while frontiers[depth] do
local f = frontiers[depth]
while frontiers[1] do
local f = table.remove(frontiers, 1)
local node = mesecon.get_node_force(f.pos)
-- area not loaded, postpone action
if not node then
mesecon.queue:add_action(f.pos, "turnoff", {link}, nil, true)
-- Area does not exist; do nothing
elseif mesecon.is_conductor_on(node, f.link) then
local rules = mesecon.conductor_get_rules(node)
minetest.swap_node(f.pos, {name = mesecon.get_conductor_off(node, f.link),
param2 = node.param2})
-- call turnoff on neighbors: normal rules
for _, r in ipairs(mesecon.rule2meta(f.link, rules)) do
local np = vector.add(f.pos, r)
-- area not loaded, postpone action
if not mesecon.get_node_force(np) then
mesecon.queue:add_action(np, "turnoff", {rulename},
nil, true)
else
local links = mesecon.rules_link_rule_all(f.pos, r)
for _, l in ipairs(links) do
table.insert(frontiers, {pos = np, link = l})
-- Check if an onstate receptor is connected. If that is the case,
-- abort this turnoff process by returning false. `receptor_off` will
-- discard all the changes that we made in the voxelmanip:
for _, l in ipairs(mesecon.rules_link_rule_all_inverted(f.pos, r)) do
if mesecon.is_receptor_on(mesecon.get_node_force(np).name) then
return false
end
end
-- Call turnoff on neighbors
for _, l in ipairs(mesecon.rules_link_rule_all(f.pos, r)) do
table.insert(frontiers, {pos = np, link = l})
end
end
mesecon.swap_node_force(f.pos, mesecon.get_conductor_off(node, f.link))
elseif mesecon.is_effector(node.name) then
mesecon.changesignal(f.pos, node, f.link, mesecon.state.off, depth)
if mesecon.is_effector_on(node.name) and not mesecon.is_powered(f.pos) then
mesecon.deactivate(f.pos, node, f.link, depth)
end
table.insert(signals, {
pos = f.pos,
node = node,
link = f.link,
depth = depth
})
end
depth = depth + 1
end
end
mesecon.queue:add_function("turnoff", function (pos, rulename, recdepth)
mesecon.turnoff(pos, rulename, recdepth)
end)
function mesecon.connected_to_receptor(pos, link)
local node = mesecon.get_node_force(pos)
if not node then return false end
-- Check if conductors around are connected
local rules = mesecon.get_any_inputrules(node)
if not rules then return false end
for _, rule in ipairs(mesecon.rule2meta(link, rules)) do
local links = mesecon.rules_link_rule_all_inverted(pos, rule)
for _, l in ipairs(links) do
local np = vector.add(pos, l)
if mesecon.find_receptor_on(np, mesecon.invertRule(l)) then
return true
end
for _, sig in ipairs(signals) do
mesecon.changesignal(sig.pos, sig.node, sig.link, mesecon.state.off, sig.depth)
if mesecon.is_effector_on(sig.node.name) and not mesecon.is_powered(sig.pos) then
mesecon.deactivate(sig.pos, sig.node, sig.link, sig.depth)
end
end
return false
end
function mesecon.find_receptor_on(pos, link)
local frontiers = {{pos = pos, link = link}}
local checked = {}
-- List of positions that have been searched for onstate receptors
local depth = 1
while frontiers[depth] do
local f = frontiers[depth]
local node = mesecon.get_node_force(f.pos)
if not node then return false end
if mesecon.is_receptor_on(node.name) then return true end
if mesecon.is_conductor_on(node, f.link) then
local rules = mesecon.conductor_get_rules(node)
-- call turnoff on neighbors: normal rules
for _, r in ipairs(mesecon.rule2meta(f.link, rules)) do
local np = vector.add(f.pos, r)
local links = mesecon.rules_link_rule_all_inverted(f.pos, r)
for _, l in ipairs(links) do
local checkedstring = np.x..np.y..np.z..l.x..l.y..l.z
if not checked[checkedstring] then
table.insert(frontiers, {pos = np, link = l})
checked[checkedstring] = true
end
end
end
end
depth = depth + 1
end
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 = mesecon.get_node_force(output)
local inputnode = mesecon.get_node_force(input)
local outputrules = dug_outputrules or mesecon.get_any_outputrules (outputnode)
local inputrules = mesecon.get_any_inputrules (inputnode)
if not outputrules or not inputrules then
return
end
for _, outputrule in ipairs(mesecon.flattenrules(outputrules)) do
-- Check if output sends to input
if vector.equals(vector.add(output, outputrule), input) then
for _, inputrule in ipairs(mesecon.flattenrules(inputrules)) do
-- Check if input accepts from output
if vector.equals(vector.add(input, inputrule), output) then
return true, inputrule
end
end
end
end
return false
return true
end
-- Get all linking inputrules of inputnode (effector or conductor) that is connected to
-- outputnode (receptor or conductor) at position `output` and has an output in direction `rule`
function mesecon.rules_link_rule_all(output, rule)
local input = vector.add(output, rule)
local inputnode = mesecon.get_node_force(input)
local inputrules = mesecon.get_any_inputrules (inputnode)
local inputrules = mesecon.get_any_inputrules(inputnode)
if not inputrules then
return {}
end
@ -563,11 +492,12 @@ function mesecon.rules_link_rule_all(output, rule)
return rules
end
-- Get all linking outputnodes of outputnode (receptor or conductor) that is connected to
-- inputnode (effector or conductor) at position `input` and has an input in direction `rule`
function mesecon.rules_link_rule_all_inverted(input, rule)
--local irule = mesecon.invertRule(rule)
local output = vector.add(input, rule)
local outputnode = mesecon.get_node_force(output)
local outputrules = mesecon.get_any_outputrules (outputnode)
local outputrules = mesecon.get_any_outputrules(outputnode)
if not outputrules then
return {}
end
@ -581,10 +511,6 @@ function mesecon.rules_link_rule_all_inverted(input, rule)
return rules
end
function mesecon.rules_link_anydir(pos1, pos2)
return mesecon.rules_link(pos1, pos2) or mesecon.rules_link(pos2, pos1)
end
function mesecon.is_powered(pos, rule)
local node = mesecon.get_node_force(pos)
local rules = mesecon.get_any_inputrules(node)

@ -1,30 +1,14 @@
-- Ugly hack to prevent breaking compatibility with other mods
-- Just remove the following two functions to delete the hack, to be done when other mods have updated
function mesecon.receptor_on(self, pos, rules)
if (self.receptor_on) then
print("[Mesecons] Warning: A mod with mesecon support called mesecon:receptor_on.")
print("[Mesecons] If you are the programmer of this mod, please update it ")
print("[Mesecons] to use mesecon.receptor_on instead. mesecon:* is deprecated")
print("[Mesecons] Otherwise, please make sure you're running the latest version")
print("[Mesecons] of that mod and inform the mod creator.")
else
rules = pos
pos = self
end
mesecon.queue:add_action(pos, "receptor_on", {rules}, nil, rules)
-- Un-forceload any forceloaded mapblocks from older versions of Mesecons which
-- used forceloading instead of VoxelManipulators.
local BLOCKSIZE = 16
-- convert block hash --> node position
local function unhash_blockpos(hash)
return vector.multiply(minetest.get_position_from_hash(hash), BLOCKSIZE)
end
function mesecon.receptor_off(self, pos, rules)
if (self.receptor_off) then
print("[Mesecons] Warning: A mod with mesecon support called mesecon:receptor_off.")
print("[Mesecons] If you are the programmer of this mod, please update it ")
print("[Mesecons] to use mesecon.receptor_off instead. mesecon:* is deprecated")
print("[Mesecons] Otherwise, please make sure you're running the latest version")
print("[Mesecons] of that mod and inform the mod creator.")
else
rules = pos
pos = self
end
mesecon.queue:add_action(pos, "receptor_off", {rules}, nil, rules)
local old_forceloaded_blocks = mesecon.file2table("mesecon_forceloaded")
for hash, _ in pairs(old_forceloaded_blocks) do
minetest.forceload_free_block(unhash_blockpos(hash))
end
os.remove(minetest.get_worldpath()..DIR_DELIM.."mesecon_forceloaded")

@ -41,12 +41,19 @@ mesecon.rules.alldirs =
mesecon.rules.buttonlike_get = function(node)
local rules = mesecon.rules.buttonlike
if node.param2 == 2 then
local dir = minetest.facedir_to_dir(node.param2)
if dir.x == 1 then
-- No action needed
elseif dir.z == -1 then
rules=mesecon.rotate_rules_left(rules)
elseif node.param2 == 3 then
elseif dir.x == -1 then
rules=mesecon.rotate_rules_right(mesecon.rotate_rules_right(rules))
elseif node.param2 == 0 then
elseif dir.z == 1 then
rules=mesecon.rotate_rules_right(rules)
elseif dir.y == -1 then
rules=mesecon.rotate_rules_up(rules)
elseif dir.y == 1 then
rules=mesecon.rotate_rules_down(rules)
end
return rules
end

@ -1,7 +1,7 @@
-- Dig and place services
mesecon.on_placenode = function (pos, node)
mesecon.update_autoconnect(pos, node)
mesecon.on_placenode = function(pos, node)
mesecon.execute_autoconnect_hooks_now(pos, node)
-- Receptors: Send on signal when active
if mesecon.is_receptor_on(node.name) then
@ -52,16 +52,15 @@ mesecon.on_placenode = function (pos, node)
end
end
mesecon.on_dignode = function (pos, node)
mesecon.on_dignode = function(pos, node)
if mesecon.is_conductor_on(node) 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
mesecon.queue:add_action(pos, "update_autoconnect", {node})
end
mesecon.queue:add_function("update_autoconnect", mesecon.update_autoconnect)
mesecon.execute_autoconnect_hooks_queue(pos, node)
end
minetest.register_on_placenode(mesecon.on_placenode)
minetest.register_on_dignode(mesecon.on_dignode)
@ -87,10 +86,6 @@ end
mesecon.queue:add_function("cooldown", function (pos)
if minetest.get_item_group(minetest.get_node(pos).name, "overheat") == 0 then
return -- node has been moved, this one does not use overheating - ignore
end
local meta = minetest.get_meta(pos)
local heat = meta:get_int("heat")

@ -219,7 +219,7 @@ function mesecon.table2file(filename, table)
f:close()
end
-- Forceloading: Force server to load area if node is nil
-- Block position "hashing" (convert to integer) functions for voxelmanip cache
local BLOCKSIZE = 16
-- convert node position --> block hash
@ -231,45 +231,160 @@ local function hash_blockpos(pos)
})
end
-- convert block hash --> node position
local function unhash_blockpos(hash)
return vector.multiply(minetest.get_position_from_hash(hash), BLOCKSIZE)
-- Maps from a hashed mapblock position (as returned by hash_blockpos) to a
-- table.
--
-- Contents of the table are:
-- “vm” → the VoxelManipulator
-- “va” → the VoxelArea
-- “data” → the data array
-- “param1” → the param1 array
-- “param2” → the param2 array
-- “dirty” → true if data has been modified
--
-- Nil if no VM-based transaction is in progress.
local vm_cache = nil
-- Starts a VoxelManipulator-based transaction.
--
-- During a VM transaction, calls to vm_get_node and vm_swap_node operate on a
-- cached copy of the world loaded via VoxelManipulators. That cache can later
-- be committed to the real map by means of vm_commit or discarded by means of
-- vm_abort.
function mesecon.vm_begin()
vm_cache = {}
end
mesecon.forceloaded_blocks = {}
-- Finishes a VoxelManipulator-based transaction, freeing the VMs and map data
-- and writing back any modified areas.
function mesecon.vm_commit()
for hash, tbl in pairs(vm_cache) do
if tbl.dirty then
local vm = tbl.vm
vm:set_data(tbl.data)
vm:write_to_map()
vm:update_map()
end
end
vm_cache = nil
end
-- get node and force-load area
function mesecon.get_node_force(pos)
-- Finishes a VoxelManipulator-based transaction, freeing the VMs and throwing
-- away any modified areas.
function mesecon.vm_abort()
vm_cache = nil
end
-- Gets the cache entry covering a position, populating it if necessary.
local function vm_get_or_create_entry(pos)
local hash = hash_blockpos(pos)
if mesecon.forceloaded_blocks[hash] == nil then
-- if no more forceload spaces are available, try again next time
if minetest.forceload_block(pos) then
mesecon.forceloaded_blocks[hash] = 0
end
else
mesecon.forceloaded_blocks[hash] = 0
local tbl = vm_cache[hash]
if not tbl then
local vm = minetest.get_voxel_manip(pos, pos)
local min_pos, max_pos = vm:get_emerged_area()
local va = VoxelArea:new{MinEdge = min_pos, MaxEdge = max_pos}
tbl = {vm = vm, va = va, data = vm:get_data(), param1 = vm:get_light_data(), param2 = vm:get_param2_data(), dirty = false}
vm_cache[hash] = tbl
end
return minetest.get_node_or_nil(pos)
return tbl
end
minetest.register_globalstep(function (dtime)
for hash, time in pairs(mesecon.forceloaded_blocks) do
-- unload forceloaded blocks after 10 minutes without usage
if (time > mesecon.setting("forceload_timeout", 600)) then
minetest.forceload_free_block(unhash_blockpos(hash))
mesecon.forceloaded_blocks[hash] = nil
else
mesecon.forceloaded_blocks[hash] = time + dtime
end
-- Gets the node at a given position during a VoxelManipulator-based
-- transaction.
function mesecon.vm_get_node(pos)
local tbl = vm_get_or_create_entry(pos)
local index = tbl.va:indexp(pos)
local node_value = tbl.data[index]
if node_value == core.CONTENT_IGNORE then
return nil
else
local node_param1 = tbl.param1[index]
local node_param2 = tbl.param2[index]
return {name = minetest.get_name_from_content_id(node_value), param1 = node_param1, param2 = node_param2}
end
end)
end
-- Store and read the forceloaded blocks to / from a file
-- so that those blocks are remembered when the game
-- is restarted
mesecon.forceloaded_blocks = mesecon.file2table("mesecon_forceloaded")
minetest.register_on_shutdown(function()
mesecon.table2file("mesecon_forceloaded", mesecon.forceloaded_blocks)
end)
-- Sets a nodes name during a VoxelManipulator-based transaction.
--
-- Existing param1, param2, and metadata are left alone.
function mesecon.vm_swap_node(pos, name)
local tbl = vm_get_or_create_entry(pos)
local index = tbl.va:indexp(pos)
tbl.data[index] = minetest.get_content_id(name)
tbl.dirty = true
end
-- Gets the node at a given position, regardless of whether it is loaded or
-- not, respecting a transaction if one is in progress.
--
-- Outside a VM transaction, if the mapblock is not loaded, it is pulled into
-- the servers main map data cache and then accessed from there.
--
-- Inside a VM transaction, the transactions VM cache is used.
function mesecon.get_node_force(pos)
if vm_cache then
return mesecon.vm_get_node(pos)
else
local node = minetest.get_node_or_nil(pos)
if node == nil then
-- Node is not currently loaded; use a VoxelManipulator to prime
-- the mapblock cache and try again.
minetest.get_voxel_manip(pos, pos)
node = minetest.get_node_or_nil(pos)
end
return node
end
end
-- Swaps the node at a given position, regardless of whether it is loaded or
-- not, respecting a transaction if one is in progress.
--
-- Outside a VM transaction, if the mapblock is not loaded, it is pulled into
-- the servers main map data cache and then accessed from there.
--
-- Inside a VM transaction, the transactions VM cache is used.
--
-- This function can only be used to change the nodes name, not its parameters
-- or metadata.
function mesecon.swap_node_force(pos, name)
if vm_cache then
return mesecon.vm_swap_node(pos, name)
else
-- This serves to both ensure the mapblock is loaded and also hand us
-- the old node table so we can preserve param2.
local node = mesecon.get_node_force(pos)
node.name = name
minetest.swap_node(pos, node)
end
end
-- Autoconnect Hooks
-- Nodes like conductors may change their appearance and their connection rules
-- right after being placed or after being dug, e.g. the default wires use this
-- to automatically connect to linking nodes after placement.
-- After placement, the update function will be executed immediately so that the
-- possibly changed rules can be taken into account when recalculating the circuit.
-- After digging, the update function will be queued and executed after
-- recalculating the circuit. The update function must take care of updating the
-- node at the given position itself, but also all of the other nodes the given
-- position may have (had) a linking connection to.
mesecon.autoconnect_hooks = {}
-- name: A unique name for the hook, e.g. "foowire". Used to name the actionqueue function.
-- fct: The update function with parameters function(pos, node)
function mesecon.register_autoconnect_hook(name, fct)
mesecon.autoconnect_hooks[name] = fct
mesecon.queue:add_function("autoconnect_hook_"..name, fct)
end
function mesecon.execute_autoconnect_hooks_now(pos, node)
for _, fct in pairs(mesecon.autoconnect_hooks) do
fct(pos, node)
end
end
function mesecon.execute_autoconnect_hooks_queue(pos, node)
for name in pairs(mesecon.autoconnect_hooks) do
mesecon.queue:add_action(pos, "autoconnect_hook_"..name, {node})
end
end

@ -26,6 +26,7 @@ minetest.register_node("mesecons_button:button_off", {
paramtype2 = "facedir",
legacy_wallmounted = true,
walkable = false,
on_rotate = mesecon.buttonlike_onrotate,
sunlight_propagates = true,
selection_box = {
type = "fixed",
@ -67,6 +68,7 @@ minetest.register_node("mesecons_button:button_on", {
paramtype2 = "facedir",
legacy_wallmounted = true,
walkable = false,
on_rotate = false,
light_source = default.LIGHT_MAX-7,
sunlight_propagates = true,
selection_box = {

@ -93,9 +93,22 @@ local function receive_fields(pos, formname, fields, sender)
end
local function resolve_commands(commands, pos)
local players = minetest.get_connected_players()
-- No players online: remove all commands containing
-- @nearest, @farthest and @random
if #players == 0 then
commands = commands:gsub("[^\r\n]+", function (line)
if line:find("@nearest") then return "" end
if line:find("@farthest") then return "" end
if line:find("@random") then return "" end
return line
end)
return commands
end
local nearest, farthest = nil, nil
local min_distance, max_distance = math.huge, -1
local players = minetest.get_connected_players()
for index, player in pairs(players) do
local distance = vector.distance(pos, player:getpos())
if distance < min_distance then

@ -47,7 +47,8 @@ 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
local 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
{ -3/16, -7/16, -3/16, 3/16, -26/64, -2/16 },
@ -57,7 +58,8 @@ boxes = {{ -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, -- the main slab
{ -6/16, -7/16, -6/16, -4/16, -27/64, -4/16 }, -- the timer indicator
{ -8/16, -8/16, -1/16, -6/16, -7/16, 1/16 }, -- the two wire stubs
{ 6/16, -8/16, -1/16, 8/16, -7/16, 1/16 }}
{ 6/16, -8/16, -1/16, 8/16, -7/16, 1/16 }
}
minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
description = "Delayer",

@ -49,7 +49,7 @@ minetest.register_node("mesecons_extrawires:corner_on", {
minetest.register_node("mesecons_extrawires:corner_off", {
drawtype = "nodebox",
description = "Mesecon Corner",
description = "Insulated Mesecon Corner",
tiles = {
"jeija_insulated_wire_curved_tb_off.png",
"jeija_insulated_wire_curved_tb_off.png^[transformR270",

@ -1,4 +1,4 @@
function crossover_get_rules(node)
local function crossover_get_rules(node)
return {
{--first wire
{x=-1,y=0,z=0},
@ -19,28 +19,19 @@ local crossover_states = {
}
minetest.register_node("mesecons_extrawires:crossover_off", {
description = "Insulated Crossover",
drawtype = "nodebox",
description = "Insulated Mesecon Crossover",
drawtype = "mesh",
mesh = "mesecons_extrawires_crossover.b3d",
tiles = {
"jeija_insulated_wire_crossing_tb_off.png",
"jeija_insulated_wire_crossing_tb_off.png",
"jeija_insulated_wire_ends_off.png",
"jeija_insulated_wire_sides_off.png",
"jeija_insulated_wire_sides_off.png",
"jeija_insulated_wire_ends_off.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}},
node_box = {
type = "fixed",
fixed = {
{ -16/32-0.001, -17/32, -3/32, 16/32+0.001, -13/32, 3/32 },
{ -3/32, -17/32, -16/32-0.001, 3/32, -13/32, -6/32 },
{ -3/32, -13/32, -9/32, 3/32, -6/32, -6/32 },
{ -3/32, -9/32, -9/32, 3/32, -6/32, 9/32 },
{ -3/32, -13/32, 6/32, 3/32, -6/32, 9/32 },
{ -3/32, -17/32, 6/32, 3/32, -13/32, 16/32+0.001 },
},
},
groups = {dig_immediate=3, mesecon=3},
mesecons = {
conductor = {
@ -53,30 +44,18 @@ minetest.register_node("mesecons_extrawires:crossover_off", {
minetest.register_node("mesecons_extrawires:crossover_01", {
description = "You hacker you!",
drop = "mesecons_extrawires:crossover_off",
drawtype = "nodebox",
drawtype = "mesh",
mesh = "mesecons_extrawires_crossover.b3d",
tiles = {
"jeija_insulated_wire_crossing_tb_01.png",
"jeija_insulated_wire_crossing_tb_01.png",
"jeija_insulated_wire_ends_01x.png",
"jeija_insulated_wire_ends_01x.png",
"jeija_insulated_wire_ends_01z.png",
"jeija_insulated_wire_ends_01z.png"
"jeija_insulated_wire_ends_on.png",
"jeija_insulated_wire_sides_on.png",
"jeija_insulated_wire_sides_off.png",
"jeija_insulated_wire_ends_off.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}},
node_box = {
type = "fixed",
fixed = {
{ -16/32-0.001, -17/32, -3/32, 16/32+0.001, -13/32, 3/32 },
{ -3/32, -17/32, -16/32-0.001, 3/32, -13/32, -6/32 },
{ -3/32, -13/32, -9/32, 3/32, -6/32, -6/32 },
{ -3/32, -9/32, -9/32, 3/32, -6/32, 9/32 },
{ -3/32, -13/32, 6/32, 3/32, -6/32, 9/32 },
{ -3/32, -17/32, 6/32, 3/32, -13/32, 16/32+0.001 },
},
},
groups = {dig_immediate=3, mesecon=3, not_in_creative_inventory=1},
mesecons = {
conductor = {
@ -89,30 +68,18 @@ minetest.register_node("mesecons_extrawires:crossover_01", {
minetest.register_node("mesecons_extrawires:crossover_10", {
description = "You hacker you!",
drop = "mesecons_extrawires:crossover_off",
drawtype = "nodebox",
drawtype = "mesh",
mesh = "mesecons_extrawires_crossover.b3d",
tiles = {
"jeija_insulated_wire_crossing_tb_10.png",
"jeija_insulated_wire_crossing_tb_10.png",
"jeija_insulated_wire_ends_10x.png",
"jeija_insulated_wire_ends_10x.png",
"jeija_insulated_wire_ends_10z.png",
"jeija_insulated_wire_ends_10z.png"
"jeija_insulated_wire_ends_off.png",
"jeija_insulated_wire_sides_off.png",
"jeija_insulated_wire_sides_on.png",
"jeija_insulated_wire_ends_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}},
node_box = {
type = "fixed",
fixed = {
{ -16/32-0.001, -17/32, -3/32, 16/32+0.001, -13/32, 3/32 },
{ -3/32, -17/32, -16/32-0.001, 3/32, -13/32, -6/32 },
{ -3/32, -13/32, -9/32, 3/32, -6/32, -6/32 },
{ -3/32, -9/32, -9/32, 3/32, -6/32, 9/32 },
{ -3/32, -13/32, 6/32, 3/32, -6/32, 9/32 },
{ -3/32, -17/32, 6/32, 3/32, -13/32, 16/32+0.001 },
},
},
groups = {dig_immediate=3, mesecon=3, not_in_creative_inventory=1},
mesecons = {
conductor = {
@ -125,30 +92,18 @@ minetest.register_node("mesecons_extrawires:crossover_10", {
minetest.register_node("mesecons_extrawires:crossover_on", {
description = "You hacker you!",
drop = "mesecons_extrawires:crossover_off",
drawtype = "nodebox",
drawtype = "mesh",
mesh = "mesecons_extrawires_crossover.b3d",
tiles = {
"jeija_insulated_wire_crossing_tb_on.png",
"jeija_insulated_wire_crossing_tb_on.png",
"jeija_insulated_wire_ends_on.png",
"jeija_insulated_wire_ends_on.png",
"jeija_insulated_wire_ends_on.png",
"jeija_insulated_wire_sides_on.png",
"jeija_insulated_wire_sides_on.png",
"jeija_insulated_wire_ends_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}},
node_box = {
type = "fixed",
fixed = {
{ -16/32-0.001, -17/32, -3/32, 16/32+0.001, -13/32, 3/32 },
{ -3/32, -17/32, -16/32-0.001, 3/32, -13/32, -6/32 },
{ -3/32, -13/32, -9/32, 3/32, -6/32, -6/32 },
{ -3/32, -9/32, -9/32, 3/32, -6/32, 9/32 },
{ -3/32, -13/32, 6/32, 3/32, -6/32, 9/32 },
{ -3/32, -17/32, 6/32, 3/32, -13/32, 16/32+0.001 },
},
},
groups = {dig_immediate=3, mesecon=3, not_in_creative_inventory=1},
mesecons = {
conductor = {

Binary file not shown.

Binary file not shown.

@ -50,7 +50,7 @@ minetest.register_node("mesecons_extrawires:tjunction_on", {
minetest.register_node("mesecons_extrawires:tjunction_off", {
drawtype = "nodebox",
description = "T-junction",
description = "Insulated Mesecon T-junction",
tiles = {
"jeija_insulated_wire_tjunction_tb_off.png",
"jeija_insulated_wire_tjunction_tb_off.png^[transformR180",

@ -0,0 +1 @@
mesecons

@ -0,0 +1,5 @@
FPGAs can be used to chain multiple logic gates together in a compact manner.
They come with 4 I/O ports and 10 internal registers,
which can then be connected with eachother to form logic circuits.<br />
Supported gate types: <b>AND</b>, <b>OR</b>, <b>NOT</b>, <b>XOR</b>, <b>NAND</b>, <b>XNOR</b>, <b>Buffer</b> (=)<br />
I/O ports: <b>A B C D</b>; Registers: numbered <b>0</b> to <b>9</b>

Binary file not shown.

After

(image error) Size: 21 KiB

Binary file not shown.

After

(image error) Size: 3.1 KiB

@ -0,0 +1,3 @@
The FPGA programmer can be used to copy gate configurations from one FPGA to another.<br />
Shift+Right-Click an FPGA to read its configuration and "remember" it.
Left-click (punch) FPGAs to write the saved configuration to them.

Binary file not shown.

After

(image error) Size: 598 B

Binary file not shown.

After

(image error) Size: 1.9 KiB

375
mesecons_fpga/init.lua Normal file

@ -0,0 +1,375 @@
local plg = {}
plg.rules = {}
local lcore = dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/logic.lua")
dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/tool.lua")(plg)
plg.register_nodes = function(template)
-- each loop is for one of the 4 IO ports
for a = 0, 1 do
for b = 0, 1 do
for c = 0, 1 do
for d = 0, 1 do
local ndef = table.copy(template)
local nodename = "mesecons_fpga:fpga"
.. tostring(d) .. tostring(c) .. tostring(b) .. tostring(a)
-- build top texture string
local texture = "jeija_fpga_top.png"
if a == 1 then texture = texture .. "^jeija_microcontroller_LED_A.png" end
if b == 1 then texture = texture .. "^jeija_microcontroller_LED_B.png" end
if c == 1 then texture = texture .. "^jeija_microcontroller_LED_C.png" end
if d == 1 then texture = texture .. "^jeija_microcontroller_LED_D.png" end
ndef.tiles[1] = texture
ndef.inventory_image = texture
if (a + b + c + d) > 0 then
ndef.groups["not_in_creative_inventory"] = 1
end
-- interaction with mesecons (input / output)
local rules_out = {}
if a == 1 then table.insert(rules_out, {x = -1, y = 0, z = 0}) end
if b == 1 then table.insert(rules_out, {x = 0, y = 0, z = 1}) end
if c == 1 then table.insert(rules_out, {x = 1, y = 0, z = 0}) end
if d == 1 then table.insert(rules_out, {x = 0, y = 0, z = -1}) end
plg.rules[nodename] = rules_out
local rules_in = {}
if a == 0 then table.insert(rules_in, {x = -1, y = 0, z = 0}) end
if b == 0 then table.insert(rules_in, {x = 0, y = 0, z = 1}) end
if c == 0 then table.insert(rules_in, {x = 1, y = 0, z = 0}) end
if d == 0 then table.insert(rules_in, {x = 0, y = 0, z = -1}) end
ndef.mesecons.effector.rules = rules_in
if (a + b + c + d) > 0 then
ndef.mesecons.receptor = {
state = mesecon.state.on,
rules = rules_out,
}
end
minetest.register_node(nodename, ndef)
end
end
end
end
end
plg.register_nodes({
description = "FPGA",
drawtype = "nodebox",
tiles = {
"", -- replaced later
"jeija_microcontroller_bottom.png",
"jeija_fpga_sides.png",
"jeija_fpga_sides.png",
"jeija_fpga_sides.png",
"jeija_fpga_sides.png"
},
inventory_image = "", -- replaced later
sunlight_propagates = true,
paramtype = "light",
walkable = true,
groups = {dig_immediate = 2, mesecon = 3},
drop = "mesecons_fpga:fpga0000",
selection_box = {
type = "fixed",
fixed = { -8/16, -8/16, -8/16, 8/16, -5/16, 8/16 },
},
node_box = {
type = "fixed",
fixed = {
{ -8/16, -8/16, -8/16, 8/16, -7/16, 8/16 }, -- bottom slab
{ -5/16, -7/16, -5/16, 5/16, -6/16, 5/16 }, -- circuit board
{ -3/16, -6/16, -3/16, 3/16, -5/16, 3/16 }, -- IC
}
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local is = { {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {} }
meta:set_string("instr", lcore.serialize(is))
meta:set_int("valid", 0)
meta:set_string("formspec", plg.to_formspec_string(is))
meta:set_string("infotext", "FPGA")
end,
on_receive_fields = function(pos, formname, fields, sender)
if fields.program == nil then return end -- we only care when the user clicks "Program"
local meta = minetest.get_meta(pos)
local is = plg.from_formspec_fields(fields)
meta:set_string("instr", lcore.serialize(is))
plg.update_formspec(pos, is)
end,
sounds = default.node_sound_stone_defaults(),
mesecons = {
effector = {
rules = {}, -- replaced later
action_change = function(pos, node, rule, newstate)
plg.ports_changed(pos, rule, newstate)
plg.update(pos)
end
}
},
after_dig_node = function(pos, node)
mesecon.receptor_off(pos, plg.rules[node.name])
end,
})
plg.to_formspec_string = function(is)
local function dropdown_op(x, y, name, val)
local s = "dropdown[" .. tostring(x) .. "," .. tostring(y) .. ";"
.. "0.75,0.5;" .. name .. ";" -- the height seems to be ignored?
s = s .. " ,A,B,C,D,0,1,2,3,4,5,6,7,8,9;"
if val == nil then
s = s .. "0" -- actually selects no field at all
elseif val.type == "io" then
local mapping = {
["A"] = 1,
["B"] = 2,
["C"] = 3,
["D"] = 4,
}
s = s .. tostring(1 + mapping[val.port])
else -- "reg"
s = s .. tostring(6 + val.n)
end
return s .. "]"
end
local function dropdown_action(x, y, name, val)
local s = "dropdown[" .. tostring(x) .. "," .. tostring(y) .. ";"
.. "1.125,0.5;" .. name .. ";" -- the height seems to be ignored?
s = s .. " , AND, OR, NOT, XOR,NAND, =,XNOR;"
if val == nil then
return s .. "0]" -- actually selects no field at all
end
local mapping = {
["and"] = 1,
["or"] = 2,
["not"] = 3,
["xor"] = 4,
["nand"] = 5,
["buf"] = 6,
["xnor"] = 7,
}
return s .. tostring(1 + mapping[val]) .. "]"
end
local s = "size[9,9]"..
"label[3.4,-0.15;FPGA gate configuration]"..
"button_exit[7,7.5;2,2.5;program;Program]"..
"box[4.2,0.5;0.03,7;#ffffff]"..
"label[0.25,0.25;op. 1]"..
"label[1.0,0.25;gate type]"..
"label[2.125,0.25;op. 2]"..
"label[3.15,0.25;dest]"..
"label[4.5,0.25;op. 1]"..
"label[5.25,0.25;gate type]"..
"label[6.375,0.25;op. 2]"..
"label[7.4,0.25;dest]"
local x = 1 - 0.75
local y = 1 - 0.25
for i = 1, 14 do
local cur = is[i]
s = s .. dropdown_op (x , y, tostring(i).."op1", cur.op1)
s = s .. dropdown_action(x+0.75 , y, tostring(i).."act", cur.action)
s = s .. dropdown_op (x+1.875, y, tostring(i).."op2", cur.op2)
s = s .. "label[" .. tostring(x+2.625) .. "," .. tostring(y+0.1) .. "; ->]"
s = s .. dropdown_op (x+2.9 , y, tostring(i).."dst", cur.dst)
y = y + 1
if i == 7 then
x = 4.5
y = 1 - 0.25
end
end
return s
end
plg.from_formspec_fields = function(fields)
local function read_op(s)
if s == nil or s == " " then
return nil
elseif s == "A" or s == "B" or s == "C" or s == "D" then
return {type = "io", port = s}
else
return {type = "reg", n = tonumber(s)}
end
end
local function read_action(s)
if s == nil or s == " " then
return nil
end
local mapping = {
["AND"] = "and",
["OR"] = "or",
["NOT"] = "not",
["XOR"] = "xor",
["NAND"] = "nand",
["="] = "buf",
["XNOR"] = "xnor",
}
s = s:gsub("^%s*", "") -- remove leading spaces
return mapping[s]
end
local is = {}
for i = 1, 14 do
local cur = {}
cur.op1 = read_op(fields[tonumber(i) .. "op1"])
cur.action = read_action(fields[tonumber(i) .. "act"])
cur.op2 = read_op(fields[tonumber(i) .. "op2"])
cur.dst = read_op(fields[tonumber(i) .. "dst"])
is[#is + 1] = cur
end
return is
end
plg.update_formspec = function(pos, is)
if type(is) == "string" then -- serialized string
is = lcore.deserialize(is)
end
local meta = minetest.get_meta(pos)
local form = plg.to_formspec_string(is)
local err = lcore.validate(is)
if err == nil then
meta:set_int("valid", 1)
meta:set_string("infotext", "FPGA (functional)")
else
meta:set_int("valid", 0)
meta:set_string("infotext", "FPGA")
local fmsg = minetest.colorize("#ff0000", minetest.formspec_escape(err.msg))
form = form .. plg.red_box_around(err.i) ..
"label[0.25,8.25;The gate configuration is erroneous in the marked area:]"..
"label[0.25,8.5;" .. fmsg .. "]"
end
meta:set_string("formspec", form)
-- reset ports and run programmed logic
plg.setports(pos, false, false, false, false)
plg.update(pos)
end
plg.red_box_around = function(i)
local x, y
if i > 7 then
x = 4.5
y = 0.75 + (i - 8)
else
x = 0.25
y = 0.75 + (i - 1)
end
return string.format("box[%f,%f;3.8,0.8;#ff0000]", x-0.1, y-0.05)
end
plg.update = function(pos)
local meta = minetest.get_meta(pos)
if meta:get_int("valid") ~= 1 then
return
end
local is = lcore.deserialize(meta:get_string("instr"))
local A, B, C, D = plg.getports(pos)
A, B, C, D = lcore.interpret(is, A, B, C, D)
plg.setports(pos, A, B, C, D)
end
plg.ports_changed = function(pos, rule, newstate)
if rule == nil then return end
local meta = minetest.get_meta(pos)
local states
local s = meta:get_string("portstates")
if s == nil then
states = {false, false, false, false}
else
states = {
s:sub(1, 1) == "1",
s:sub(2, 2) == "1",
s:sub(3, 3) == "1",
s:sub(4, 4) == "1",
}
end
-- trick to transform rules (see register_node) into port number
local portno = ({4, 1, nil, 3, 2})[3 + rule.x + 2*rule.z]
states[portno] = (newstate == "on")
meta:set_string("portstates",
(states[1] and "1" or "0") .. (states[2] and "1" or "0") ..
(states[3] and "1" or "0") .. (states[4] and "1" or "0")
)
end
plg.getports = function(pos) -- gets merged states of INPUT & OUTPUT
local sin, sout
local s = minetest.get_meta(pos):get_string("portstates")
if s == nil then
sin = {false, false, false, false}
else
sin = {
s:sub(1, 1) == "1",
s:sub(2, 2) == "1",
s:sub(3, 3) == "1",
s:sub(4, 4) == "1",
}
end
local name = minetest.get_node(pos).name
assert(name:find("mesecons_fpga:fpga") == 1)
local off = #"mesecons_fpga:fpga"
sout = {
name:sub(off+4, off+4) == "1",
name:sub(off+3, off+3) == "1",
name:sub(off+2, off+2) == "1",
name:sub(off+1, off+1) == "1",
}
return unpack({
sin[1] or sout[1],
sin[2] or sout[2],
sin[3] or sout[3],
sin[4] or sout[4],
})
end
plg.setports = function(pos, A, B, C, D) -- sets states of OUTPUT
local base = "mesecons_fpga:fpga"
local name = base
.. (D and "1" or "0") .. (C and "1" or "0")
.. (B and "1" or "0") .. (A and "1" or "0")
minetest.swap_node(pos, {name = name, param2 = minetest.get_node(pos).param2})
if A ~= nil then
local ru = plg.rules[base .. "0001"]
if A then mesecon.receptor_on(pos, ru) else mesecon.receptor_off(pos, ru) end
end
if B ~= nil then
local ru = plg.rules[base .. "0010"]
if B then mesecon.receptor_on(pos, ru) else mesecon.receptor_off(pos, ru) end
end
if C ~= nil then
local ru = plg.rules[base .. "0100"]
if C then mesecon.receptor_on(pos, ru) else mesecon.receptor_off(pos, ru) end
end
if D ~= nil then
local ru = plg.rules[base .. "1000"]
if D then mesecon.receptor_on(pos, ru) else mesecon.receptor_off(pos, ru) end
end
end
minetest.register_craft({
output = "mesecons_fpga:fpga0000 2",
recipe = {
{'group:mesecon_conductor_craftable', 'group:mesecon_conductor_craftable'},
{'mesecons_materials:silicon', 'mesecons_materials:silicon'},
{'group:mesecon_conductor_craftable', 'group:mesecon_conductor_craftable'},
}
})

210
mesecons_fpga/logic.lua Normal file

@ -0,0 +1,210 @@
local lg = {}
-- (de)serialize
lg.serialize = function(t)
local function _op(t)
if t == nil then
return " "
elseif t.type == "io" then
return t.port
else -- t.type == "reg"
return tostring(t.n)
end
end
local function _action(s)
if s == nil then
return " "
end
local mapping = {
["and"] = "&",
["or"] = "|",
["not"] = "~",
["xor"] = "^",
["nand"] = "?", --dunno
["buf"] = "_",
["xnor"] = "=",
}
return mapping[s]
end
local s = ""
for i = 1, 14 do
local cur = t[i]
if next(cur) ~= nil then
s = s .. _op(cur.op1) .. _action(cur.action) .. _op(cur.op2) .. _op(cur.dst)
end
s = s .. "/"
end
return s
end
lg.deserialize = function(s)
local function _op(c)
if c == "A" or c == "B" or c == "C" or c == "D" then
return {type = "io", port = c}
elseif c == " " then
return nil
else
return {type = "reg", n = tonumber(c)}
end
end
local function _action(c)
local mapping = {
["&"] = "and",
["|"] = "or",
["~"] = "not",
["^"] = "xor",
["?"] = "nand",
["_"] = "buf",
["="] = "xnor",
[" "] = nil,
}
return mapping[c]
end
local ret = {}
for part in s:gmatch("(.-)/") do
local parsed
if part == "" then
parsed = {}
else
parsed = {
action = _action( part:sub(2,2) ),
op1 = _op( part:sub(1,1) ),
op2 = _op( part:sub(3,3) ),
dst = _op( part:sub(4,4) ),
}
end
ret[#ret + 1] = parsed
end
-- More than 14 instructions (write to all 10 regs + 4 outputs)
-- will not pass the write-once requirement of the validator
assert(#ret == 14)
return ret
end
-- validation
lg.validate_single = function(t, i)
local function is_reg_written_to(t, n, max)
for i = 1, max-1 do
if next(t[i]) ~= nil
and t[i].dst and t[i].dst.type == "reg"
and t[i].dst.n == n then
return true
end
end
return false
end
local function compare_op(t1, t2, allow_same_io)
if t1 == nil or t2 == nil then
return false
elseif t1.type ~= t2.type then
return false
end
if t1.type == "reg" and t1.n == t2.n then
return true
elseif t1.type == "io" and t1.port == t2.port then
return not allow_same_io
end
return false
end
local elem = t[i]
-- check for completeness
if elem.action == nil then
return {i = i, msg = "Gate type required"}
elseif elem.action == "not" or elem.action == "buf" then
if elem.op1 ~= nil or elem.op2 == nil or elem.dst == nil then
return {i = i, msg = "Second operand (only) and destination required"}
end
else
if elem.op1 == nil or elem.op2 == nil or elem.dst == nil then
return {i = i, msg = "Operands and destination required"}
end
end
-- check whether operands/destination are identical
if compare_op(elem.op1, elem.op2) then
return {i = i, msg = "Operands cannot be identical"}
end
if compare_op(elem.op1, elem.dst, true) or compare_op(elem.op2, elem.dst, true) then
return {i = i, msg = "Destination and operands must be different"}
end
-- check whether operands point to defined registers
if elem.op1 ~= nil and elem.op1.type == "reg"
and not is_reg_written_to(t, elem.op1.n, i) then
return {i = i, msg = "First operand is undefined register"}
end
if elem.op2.type == "reg" and not is_reg_written_to(t, elem.op2.n, i) then
return {i = i, msg = "Second operand is undefined register"}
end
-- check whether destination points to undefined register
if elem.dst.type == "reg" and is_reg_written_to(t, elem.dst.n, i) then
return {i = i, msg = "Destination is already used register"}
end
return nil
end
lg.validate = function(t)
for i = 1, 14 do
if next(t[i]) ~= nil then
local r = lg.validate_single(t, i)
if r ~= nil then
return r
end
end
end
return nil
end
-- interpreter
lg.interpret = function(t, a, b, c, d)
local function _action(s, v1, v2)
if s == "and" then
return v1 and v2
elseif s == "or" then
return v1 or v2
elseif s == "not" then
return not v2
elseif s == "xor" then
return v1 ~= v2
elseif s == "nand" then
return not (v1 and v2)
elseif s == "buf" then
return v2
else -- s == "xnor"
return v1 == v2
end
end
local function _op(t, regs, io_in)
if t.type == "reg" then
return regs[t.n]
else -- t.type == "io"
return io_in[t.port]
end
end
local io_in = {A=a, B=b, C=c, D=d}
local regs = {}
local io_out = {}
for i = 1, 14 do
local cur = t[i]
if next(cur) ~= nil then
local v1, v2
if cur.op1 ~= nil then
v1 = _op(cur.op1, regs, io_in)
end
v2 = _op(cur.op2, regs, io_in)
local result = _action(cur.action, v1, v2)
if cur.dst.type == "reg" then
regs[cur.dst.n] = result
else -- cur.dst.type == "io"
io_out[cur.dst.port] = result
end
end
end
return io_out.A, io_out.B, io_out.C, io_out.D
end
return lg

Binary file not shown.

After

(image error) Size: 311 B

Binary file not shown.

After

(image error) Size: 536 B

Binary file not shown.

After

(image error) Size: 816 B

62
mesecons_fpga/tool.lua Normal file

@ -0,0 +1,62 @@
return function(plg)
minetest.register_tool("mesecons_fpga:programmer", {
description = "FPGA Programmer",
inventory_image = "jeija_fpga_programmer.png",
stack_max = 1,
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return itemstack
end
local pos = pointed_thing.under
if minetest.get_node(pos).name:find("mesecons_fpga:fpga") ~= 1 then
return itemstack
end
local meta = minetest.get_meta(pos)
if meta:get_string("instr") == "//////////////" then
minetest.chat_send_player(placer:get_player_name(), "This FPGA is unprogrammed.")
return itemstack
end
itemstack:set_metadata(meta:get_string("instr"))
minetest.chat_send_player(placer:get_player_name(), "FPGA gate configuration was successfully copied!")
return itemstack
end,
on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= "node" then
return itemstack
end
local pos = pointed_thing.under
if minetest.get_node(pos).name:find("mesecons_fpga:fpga") ~= 1 then
return itemstack
end
local imeta = itemstack:get_metadata()
if imeta == "" then
minetest.chat_send_player(user:get_player_name(), "Use shift+right-click to copy a gate configuration first.")
return itemstack
end
local meta = minetest.get_meta(pos)
meta:set_string("instr", imeta)
plg.update_formspec(pos, imeta)
minetest.chat_send_player(user:get_player_name(), "Gate configuration was successfully written to FPGA!")
return itemstack
end
})
minetest.register_craft({
output = "mesecons_fpga:programmer",
recipe = {
{'group:mesecon_conductor_craftable'},
{'mesecons_materials:silicon'},
}
})
end

@ -54,7 +54,7 @@ local function update_gate(pos, node, link, newstate)
end
end
function register_gate(name, inputnumber, assess, recipe)
local function register_gate(name, inputnumber, assess, recipe)
local get_inputrules = inputnumber == 2 and gate_get_input_rules_twoinputs or
gate_get_input_rules_oneinput
local description = "Mesecons Logic Gate: "..name

@ -5,12 +5,12 @@
minetest.register_node("mesecons_hydroturbine:hydro_turbine_off", {
drawtype = "mesh",
mesh = "jeija_hydro_turbine.obj",
mesh = "jeija_hydro_turbine_off.obj",
tiles = {
"jeija_hydro_turbine_sides_off.png",
"jeija_hydro_turbine_top_bottom.png",
"jeija_hydro_turbine_turbine_top_bottom.png",
"jeija_hydro_turbine_turbine_misc.png"
"jeija_hydro_turbine_turbine_top_bottom_off.png",
"jeija_hydro_turbine_turbine_misc_off.png"
},
inventory_image = "jeija_hydro_turbine_inv.png",
wield_scale = {x=0.75, y=0.75, z=0.75},
@ -29,13 +29,15 @@ minetest.register_node("mesecons_hydroturbine:hydro_turbine_off", {
minetest.register_node("mesecons_hydroturbine:hydro_turbine_on", {
drawtype = "mesh",
mesh = "jeija_hydro_turbine.obj",
mesh = "jeija_hydro_turbine_on.obj",
wield_scale = {x=0.75, y=0.75, z=0.75},
tiles = {
"jeija_hydro_turbine_sides_on.png",
"jeija_hydro_turbine_top_bottom.png",
"jeija_hydro_turbine_turbine_top_bottom.png",
"jeija_hydro_turbine_turbine_misc.png"
{ name = "jeija_hydro_turbine_turbine_top_bottom_on.png",
animation = {type = "vertical_frames", aspect_w = 128, aspect_h = 16, length = 1.6} },
{ name = "jeija_hydro_turbine_turbine_misc_on.png",
animation = {type = "vertical_frames", aspect_w = 256, aspect_h = 32, length = 0.4} }
},
inventory_image = "jeija_hydro_turbine_inv.png",
drop = "mesecons_hydroturbine:hydro_turbine_off 1",
@ -53,13 +55,20 @@ minetest.register_node("mesecons_hydroturbine:hydro_turbine_on", {
})
local function is_flowing_water(pos)
local name = minetest.get_node(pos).name
local is_water = minetest.get_item_group(name, "water") > 0
local is_flowing = minetest.registered_items[name].liquidtype == "flowing"
return (is_water and is_flowing)
end
minetest.register_abm({
nodenames = {"mesecons_hydroturbine:hydro_turbine_off"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local waterpos={x=pos.x, y=pos.y+1, z=pos.z}
if minetest.get_node(waterpos).name=="default:water_flowing" then
if is_flowing_water(waterpos) then
minetest.set_node(pos, {name="mesecons_hydroturbine:hydro_turbine_on"})
nodeupdate(pos)
mesecon.receptor_on(pos)
@ -73,7 +82,7 @@ nodenames = {"mesecons_hydroturbine:hydro_turbine_on"},
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local waterpos={x=pos.x, y=pos.y+1, z=pos.z}
if minetest.get_node(waterpos).name~="default:water_flowing" then
if not is_flowing_water(waterpos) then
minetest.set_node(pos, {name="mesecons_hydroturbine:hydro_turbine_off"})
nodeupdate(pos)
mesecon.receptor_off(pos)

@ -1,21 +1,21 @@
# Blender v2.73 (sub 0) OBJ File: 'mesecons-water-turbine.blend'
# Blender v2.72 (sub 0) OBJ File: 'mesecons-water-turbine.blend'
# www.blender.org
o Cylinder.002_Cylinder.003
v 0.000000 0.500000 -0.150000
v 0.000000 0.496094 -0.150000
v 0.000000 0.562500 -0.150000
v 0.106066 0.500000 -0.106066
v 0.106066 0.496094 -0.106066
v 0.106066 0.562500 -0.106066
v 0.150000 0.500000 0.000000
v 0.150000 0.496094 0.000000
v 0.150000 0.562500 0.000000
v 0.106066 0.500000 0.106066
v 0.106066 0.496094 0.106066
v 0.106066 0.562500 0.106066
v -0.000000 0.500000 0.150000
v -0.000000 0.496094 0.150000
v -0.000000 0.562500 0.150000
v -0.106066 0.500000 0.106066
v -0.106066 0.496094 0.106066
v -0.106066 0.562500 0.106066
v -0.150000 0.500000 -0.000000
v -0.150000 0.496094 -0.000000
v -0.150000 0.562500 -0.000000
v -0.106066 0.500000 -0.106066
v -0.106066 0.496094 -0.106066
v -0.106066 0.562500 -0.106066
v 0.097545 0.625000 -0.490393
v -0.097545 0.625000 -0.490393
@ -113,38 +113,38 @@ v -0.430779 0.634645 -0.108975
v -0.180802 0.634645 -0.292266
v -0.180802 1.482640 -0.292266
v -0.430779 1.482640 -0.108975
v 0.097545 1.500000 -0.490393
v -0.097545 1.500000 -0.490393
v -0.277785 1.500000 -0.415735
v -0.415735 1.500000 -0.277785
v -0.490393 1.500000 -0.097545
v -0.490393 1.500000 0.097545
v -0.415735 1.500000 0.277785
v -0.277785 1.500000 0.415735
v -0.097545 1.500000 0.490393
v 0.097545 1.500000 0.490393
v 0.277785 1.500000 0.415735
v 0.415735 1.500000 0.277785
v 0.490393 1.500000 0.097545
v 0.490393 1.500000 -0.097545
v 0.415735 1.500000 -0.277785
v 0.277785 1.500000 -0.415735
v 0.097545 1.468750 -0.490393
v -0.097545 1.468750 -0.490393
v -0.277785 1.468750 -0.415735
v -0.415735 1.468750 -0.277785
v -0.490393 1.468750 -0.097545
v -0.490393 1.468750 0.097545
v -0.415735 1.468750 0.277785
v -0.277785 1.468750 0.415735
v -0.097545 1.468750 0.490393
v 0.097545 1.468750 0.490393
v 0.277785 1.468750 0.415735
v 0.415735 1.468750 0.277785
v 0.490393 1.468750 0.097545
v 0.490393 1.468750 -0.097545
v 0.415735 1.468750 -0.277785
v 0.277785 1.468750 -0.415735
v 0.097545 1.496094 -0.490393
v -0.097545 1.496094 -0.490393
v -0.277785 1.496094 -0.415735
v -0.415735 1.496094 -0.277785
v -0.490393 1.496094 -0.097545
v -0.490393 1.496094 0.097545
v -0.415735 1.496094 0.277785
v -0.277785 1.496094 0.415735
v -0.097545 1.496094 0.490393
v 0.097545 1.496094 0.490393
v 0.277785 1.496094 0.415735
v 0.415735 1.496094 0.277785
v 0.490393 1.496094 0.097545
v 0.490393 1.496094 -0.097545
v 0.415735 1.496094 -0.277785
v 0.277785 1.496094 -0.415735
v 0.097545 1.464844 -0.490393
v -0.097545 1.464844 -0.490393
v -0.277785 1.464844 -0.415735
v -0.415735 1.464844 -0.277785
v -0.490393 1.464844 -0.097545
v -0.490393 1.464844 0.097545
v -0.415735 1.464844 0.277785
v -0.277785 1.464844 0.415735
v -0.097545 1.464844 0.490393
v 0.097545 1.464844 0.490393
v 0.277785 1.464844 0.415735
v 0.415735 1.464844 0.277785
v 0.490393 1.464844 0.097545
v 0.490393 1.464844 -0.097545
v 0.415735 1.464844 -0.277785
v 0.277785 1.464844 -0.415735
v 0.025624 0.559630 -0.061863
v 0.025624 1.481372 -0.061863
v 0.061863 0.559630 -0.025624
@ -161,14 +161,14 @@ v -0.061863 0.559630 -0.025624
v -0.061863 1.481372 -0.025624
v -0.025624 0.559630 -0.061863
v -0.025624 1.481372 -0.061863
v 0.499775 -0.499550 -0.499775
v 0.499775 -0.499550 0.499775
v -0.499775 -0.499550 0.499775
v -0.499775 -0.499550 -0.499775
v 0.499775 0.500000 -0.499775
v 0.499775 0.500000 0.499775
v -0.499775 0.500000 0.499775
v -0.499775 0.500000 -0.499775
v 0.496094 -0.496094 -0.496094
v 0.496094 -0.496094 0.496094
v -0.496094 -0.496094 0.496094
v -0.496094 -0.496094 -0.496094
v 0.496094 0.496094 -0.496094
v 0.496094 0.496094 0.496094
v -0.496094 0.496094 0.496094
v -0.496094 0.496094 -0.496094
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
@ -314,10 +314,10 @@ vt 0.031250 0.875000
vt 0.031250 0.906250
vt 0.062500 0.906250
vn 1.000000 0.000000 0.000000
vn -0.000000 -0.000000 1.000000
vn -1.000000 -0.000000 -0.000000
vn 0.000000 0.000000 1.000000
vn -1.000000 0.000000 0.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 -1.000000 -0.000000
vn 0.000000 -1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.382700 0.000000 -0.923900
vn 0.923900 0.000000 -0.382700

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

(image error) Size: 6.8 KiB

Binary file not shown.

After

(image error) Size: 5.0 KiB

@ -1,4 +1,4 @@
function insulated_wire_get_rules(node)
local 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

Binary file not shown.

Before

(image error) Size: 305 B

Binary file not shown.

Before

(image error) Size: 270 B

Binary file not shown.

Before

(image error) Size: 293 B

Binary file not shown.

Before

(image error) Size: 209 B

Binary file not shown.

Before

(image error) Size: 246 B

Binary file not shown.

Before

(image error) Size: 252 B

Binary file not shown.

Before

(image error) Size: 238 B

Binary file not shown.

Before

(image error) Size: 261 B

@ -2,7 +2,7 @@
-- A lamp is "is an electrical device used to create artificial light" (wikipedia)
-- guess what?
mesecon_lamp_box = {
local 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},

@ -20,8 +20,6 @@
-- The Sandbox
-- The whole code of the controller runs in a sandbox,
-- a very restricted environment.
-- However, as this does not prevent you from using e.g. loops,
-- we need to check for these prohibited commands first.
-- Actually the only way to damage the server is to
-- use too much memory from the sandbox.
-- You can add more functions to the environment
@ -275,9 +273,25 @@ end
local function get_digiline_send(pos)
if not digiline then return end
return function(channel, msg)
-- Make sure channel is string, number or boolean
if (type(channel) ~= "string" and type(channel) ~= "number" and type(channel) ~= "boolean") then
return false
end
-- It is technically possible to send functions over the wire since
-- the high performance impact of stripping those from the data has
-- been decided to not be worth the added realism.
-- Make sure serialized version of the data is not insanely long to
-- prevent DoS-like attacks
local msg_ser = minetest.serialize(msg)
if #msg_ser > mesecon.setting("luacontroller_digiline_maxlen", 50000) then
return false
end
minetest.after(0, function()
digiline:receptor_send(pos, digiline.rules.default, channel, msg)
end)
return true
end
end
@ -286,6 +300,7 @@ local safe_globals = {
"assert", "error", "ipairs", "next", "pairs", "select",
"tonumber", "tostring", "type", "unpack", "_VERSION"
}
local function create_environment(pos, mem, event)
-- Gather variables for the environment
local vports = minetest.registered_nodes[minetest.get_node(pos).name].virtual_portstates
@ -508,10 +523,15 @@ local digiline = {
end
}
}
local function on_receive_fields(pos, form_name, fields)
local function on_receive_fields(pos, form_name, fields, sender)
if not fields.program then
return
end
local name = sender:get_player_name()
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
minetest.record_protection_violation(pos, name)
return
end
reset(pos)
reset_meta(pos, fields.code)
local err = run(pos, {type="program"})

@ -1,6 +1,7 @@
EEPROM_SIZE = 255
local EEPROM_SIZE = 255
local microc_rules = {}
local yc = {}
for a = 0, 1 do
for b = 0, 1 do
@ -20,6 +21,7 @@ end
if tostring(d) == "1" then
top = top.."^jeija_microcontroller_LED_D.png"
end
local groups
if tostring(d)..tostring(c)..tostring(b)..tostring(a) ~= "0000" then
groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3, overheat = 1}
else
@ -42,8 +44,8 @@ local mesecons = {effector =
{
rules = input_rules,
action_change = function (pos, node, rulename, newstate)
yc_update_real_portstates(pos, node, rulename, newstate)
update_yc(pos)
yc.update_real_portstates(pos, node, rulename, newstate)
yc.update(pos)
end
}}
if nodename ~= "mesecons_microcontroller:microcontroller0000" then
@ -127,8 +129,8 @@ minetest.register_node(nodename, {
"button[7.5,0.2;1.5,3;brsflop;RS-Flop]"..
"button_exit[3.5,1;2,3;program;Program]")
meta:set_string("infotext", "Programmed Microcontroller")
yc_reset (pos)
update_yc(pos)
yc.reset (pos)
yc.update(pos)
end,
sounds = default.node_sound_stone_defaults(),
mesecons = mesecons,
@ -151,8 +153,8 @@ minetest.register_craft({
}
})
function yc_reset(pos)
yc_action(pos, {a=false, b=false, c=false, d=false})
yc.reset = function(pos)
yc.action(pos, {a=false, b=false, c=false, d=false})
local meta = minetest.get_meta(pos)
meta:set_int("afterid", 0)
local r = ""
@ -160,7 +162,7 @@ function yc_reset(pos)
meta:set_string("eeprom", r)
end
function update_yc(pos)
yc.update = function(pos)
local meta = minetest.get_meta(pos)
if (mesecon.do_overheat(pos)) then
@ -172,10 +174,10 @@ function update_yc(pos)
end
local code = meta:get_string("code")
code = yc_code_remove_commentary(code)
code = yc.code_remove_commentary(code)
code = string.gsub(code, " ", "") --Remove all spaces
code = string.gsub(code, " ", "") --Remove all tabs
if yc_parsecode(code, pos) == nil then
if yc.parsecode(code, pos) == nil then
meta:set_string("infotext", "Code not valid!\n"..code)
else
meta:set_string("infotext", "Working Microcontroller\n"..code)
@ -184,7 +186,7 @@ end
--Code Parsing
function yc_code_remove_commentary(code)
yc.code_remove_commentary = function(code)
local is_string = false
for i = 1, #code do
if code:sub(i, i) == '"' then
@ -196,50 +198,50 @@ function yc_code_remove_commentary(code)
return code
end
function yc_parsecode(code, pos)
yc.parsecode = function(code, pos)
local meta = minetest.get_meta(pos)
local endi = 1
local Lreal = yc_get_real_portstates(pos)
local Lvirtual = yc_get_virtual_portstates(pos)
local Lreal = yc.get_real_portstates(pos)
local Lvirtual = yc.get_virtual_portstates(pos)
if Lvirtual == nil then return nil end
local c
local eeprom = meta:get_string("eeprom")
while true do
local command, params
command, endi = parse_get_command(code, endi)
command, endi = yc.parse_get_command(code, endi)
if command == nil then return nil end
if command == true then break end --end of code
if command == "if" then
local r
r, endi = yc_command_if(code, endi, yc_merge_portstates(Lreal, Lvirtual), eeprom)
r, endi = yc.command_if(code, endi, yc.merge_portstates(Lreal, Lvirtual), eeprom)
if r == nil then return nil end
if r == true then -- nothing
elseif r == false then
local endi_new = yc_skip_to_else (code, endi)
local endi_new = yc.skip_to_else (code, endi)
if endi_new == nil then --else > not found
endi = yc_skip_to_endif(code, endi)
endi = yc.skip_to_endif(code, endi)
else
endi = endi_new
end
if endi == nil then return nil end
end
else
params, endi = parse_get_params(code, endi)
params, endi = yc.parse_get_params(code, endi)
if not params then return nil end
end
if command == "on" then
L = yc_command_on (params, Lvirtual)
L = yc.command_on (params, Lvirtual)
elseif command == "off" then
L = yc_command_off(params, Lvirtual)
L = yc.command_off(params, Lvirtual)
elseif command == "print" then
local su = yc_command_print(params, eeprom, yc_merge_portstates(Lreal, Lvirtual))
local su = yc.command_print(params, eeprom, yc.merge_portstates(Lreal, Lvirtual))
if su ~= true then return nil end
elseif command == "after" then
local su = yc_command_after(params, pos)
local su = yc.command_after(params, pos)
if su == nil then return nil end
elseif command == "sbi" then
local new_eeprom
new_eeprom, Lvirtual = yc_command_sbi (params, eeprom, yc_merge_portstates(Lreal, Lvirtual), Lvirtual)
new_eeprom, Lvirtual = yc.command_sbi (params, eeprom, yc.merge_portstates(Lreal, Lvirtual), Lvirtual)
if new_eeprom == nil then return nil
else eeprom = new_eeprom end
elseif command == "if" then --nothing
@ -250,11 +252,11 @@ function yc_parsecode(code, pos)
if eeprom == nil then return nil else
minetest.get_meta(pos):set_string("eeprom", eeprom) end
end
yc_action(pos, Lvirtual)
yc.action(pos, Lvirtual)
return true
end
function parse_get_command(code, starti)
yc.parse_get_command = function(code, starti)
i = starti
local s
while s ~= "" do
@ -266,7 +268,7 @@ function parse_get_command(code, starti)
starti = starti + 1
i = starti
elseif s == ">" then
starti = yc_skip_to_endif(code, starti)
starti = yc.skip_to_endif(code, starti)
if starti == nil then return nil end
i = starti
else
@ -280,7 +282,7 @@ function parse_get_command(code, starti)
return nil, nil
end
function parse_get_params(code, starti)
yc.parse_get_params = function(code, starti)
i = starti
local s
local params = {}
@ -303,7 +305,7 @@ function parse_get_params(code, starti)
return nil, nil
end
function yc_parse_get_eeprom_param(cond, starti)
yc.parse_get_eeprom_param = function(cond, starti)
i = starti
local s
local addr
@ -319,7 +321,7 @@ function yc_parse_get_eeprom_param(cond, starti)
return nil, nil
end
function yc_skip_to_endif(code, starti)
yc.skip_to_endif = function(code, starti)
local i = starti
local s = false
local open_ifs = 1
@ -339,7 +341,7 @@ function yc_skip_to_endif(code, starti)
return nil
end
function yc_skip_to_else(code, starti)
yc.skip_to_else = function(code, starti)
local i = starti
local s = false
local open_ifs = 1
@ -360,29 +362,29 @@ function yc_skip_to_else(code, starti)
end
--Commands
function yc_command_on(params, L)
yc.command_on = function(params, L)
local rules = {}
for i, port in ipairs(params) do
L = yc_set_portstate (port, true, L)
L = yc.set_portstate (port, true, L)
end
return L
end
function yc_command_off(params, L)
yc.command_off = function(params, L)
local rules = {}
for i, port in ipairs(params) do
L = yc_set_portstate (port, false, L)
L = yc.set_portstate (port, false, L)
end
return L
end
function yc_command_print(params, eeprom, L)
yc.command_print = function(params, eeprom, L)
local s = ""
for i, param in ipairs(params) do
if param:sub(1,1) == '"' and param:sub(#param, #param) == '"' then
s = s..param:sub(2, #param-1)
else
r = yc_command_parsecondition(param, L, eeprom)
r = yc.command_parsecondition(param, L, eeprom)
if r == "1" or r == "0" then
s = s..r
else return nil end
@ -392,17 +394,17 @@ function yc_command_print(params, eeprom, L)
return true
end
function yc_command_sbi(params, eeprom, L, Lv)
yc.command_sbi = function(params, eeprom, L, Lv)
if params[1]==nil or params[2]==nil or params[3] ~=nil then return nil end
local status = yc_command_parsecondition(params[2], L, eeprom)
local status = yc.command_parsecondition(params[2], L, eeprom)
if status == nil then return nil, nil end
if string.find("ABCD", params[1])~=nil and #params[1]==1 then --is a port
if status == "1" then
Lv = yc_set_portstate (params[1], true, Lv)
Lv = yc.set_portstate (params[1], true, Lv)
else
Lv = yc_set_portstate (params[1], false, Lv)
Lv = yc.set_portstate (params[1], false, Lv)
end
return eeprom, Lv;
end
@ -420,7 +422,7 @@ function yc_command_sbi(params, eeprom, L, Lv)
end
-- after (delay)
function yc_command_after(params, pos)
yc.command_after = function(params, pos)
if params[1] == nil or params[2] == nil or params[3] ~= nil then return nil end
--get time (maximum time is 200)
@ -436,14 +438,14 @@ function yc_command_after(params, pos)
local afterid = math.random(10000)
local meta = minetest.get_meta(pos)
meta:set_int("afterid", afterid)
minetest.after(time, yc_command_after_execute, {pos = pos, code = code, afterid = afterid})
minetest.after(time, yc.command_after_execute, {pos = pos, code = code, afterid = afterid})
return true
end
function yc_command_after_execute(params)
yc.command_after_execute = function(params)
local meta = minetest.get_meta(params.pos)
if meta:get_int("afterid") == params.afterid then --make sure the node has not been changed
if yc_parsecode(params.code, params.pos) == nil then
if yc.parsecode(params.code, params.pos) == nil then
meta:set_string("infotext", "Code in after() not valid!")
else
if code ~= nil then
@ -456,21 +458,21 @@ function yc_command_after_execute(params)
end
--If
function yc_command_if(code, starti, L, eeprom)
local cond, endi = yc_command_if_getcondition(code, starti)
yc.command_if = function(code, starti, L, eeprom)
local cond, endi = yc.command_if_getcondition(code, starti)
if cond == nil then return nil end
cond = yc_command_parsecondition(cond, L, eeprom)
cond = yc.command_parsecondition(cond, L, eeprom)
local result
if cond == "0" then result = false
elseif cond == "1" then result = true end
if not result then end
return result, endi --endi from local cond, endi = yc_command_if_getcondition(code, starti)
return result, endi --endi from local cond, endi = yc.command_if_getcondition(code, starti)
end
--Condition parsing
function yc_command_if_getcondition(code, starti)
yc.command_if_getcondition = function(code, starti)
i = starti
local s
local brackets = 1 --1 Bracket to close
@ -494,7 +496,7 @@ function yc_command_if_getcondition(code, starti)
return nil, nil
end
function yc_command_parsecondition(cond, L, eeprom)
yc.command_parsecondition = function(cond, L, eeprom)
cond = string.gsub(cond, "A", tonumber(L.a and 1 or 0))
cond = string.gsub(cond, "B", tonumber(L.b and 1 or 0))
cond = string.gsub(cond, "C", tonumber(L.c and 1 or 0))
@ -506,8 +508,8 @@ function yc_command_parsecondition(cond, L, eeprom)
while i<=l do
local s = cond:sub(i,i)
if s == "#" then
local addr, endi = yc_parse_get_eeprom_param(cond, i+1)
local buf = yc_eeprom_read(tonumber(addr), eeprom)
local addr, endi = yc.parse_get_eeprom_param(cond, i+1)
local buf = yc.eeprom_read(tonumber(addr), eeprom)
if buf == nil then return nil end
local call = cond:sub(i, endi-1)
cond = string.gsub(cond, call, buf)
@ -580,14 +582,14 @@ function yc_command_parsecondition(cond, L, eeprom)
end
--Virtual-Hardware functions
function yc_eeprom_read(number, eeprom)
yc.eeprom_read = function(number, eeprom)
if not number then return end
return eeprom:sub(number, number)
end
--Real I/O functions
function yc_action(pos, L) --L-->Lvirtual
local Lv = yc_get_virtual_portstates(pos)
yc.action = function(pos, L) --L-->Lvirtual
local Lv = yc.get_virtual_portstates(pos)
local name = "mesecons_microcontroller:microcontroller"
..tonumber(L.d and 1 or 0)
..tonumber(L.c and 1 or 0)
@ -596,10 +598,10 @@ function yc_action(pos, L) --L-->Lvirtual
local node = minetest.get_node(pos)
minetest.swap_node(pos, {name = name, param2 = node.param2})
yc_action_setports(pos, L, Lv)
yc.action_setports(pos, L, Lv)
end
function yc_action_setports(pos, L, Lv)
yc.action_setports = function(pos, L, Lv)
local name = "mesecons_microcontroller:microcontroller"
local rules
if Lv.a ~= L.a then
@ -624,7 +626,7 @@ function yc_action_setports(pos, L, Lv)
end
end
function yc_set_portstate(port, state, L)
yc.set_portstate = function(port, state, L)
if port == "A" then L.a = state
elseif port == "B" then L.b = state
elseif port == "C" then L.c = state
@ -633,7 +635,7 @@ function yc_set_portstate(port, state, L)
return L
end
function yc_update_real_portstates(pos, node, rulename, newstate)
yc.update_real_portstates = function(pos, node, rulename, newstate)
local meta = minetest.get_meta(pos)
if rulename == nil then
meta:set_int("real_portstates", 1)
@ -657,7 +659,7 @@ function yc_update_real_portstates(pos, node, rulename, newstate)
meta:set_int("real_portstates", 1 + L[1] + 2*L[2] + 4*L[3] + 8*L[4])
end
function yc_get_real_portstates(pos) -- determine if ports are powered (by itself or from outside)
yc.get_real_portstates = function(pos) -- determine if ports are powered (by itself or from outside)
local meta = minetest.get_meta(pos)
local L = {}
local n = meta:get_int("real_portstates") - 1
@ -668,7 +670,7 @@ function yc_get_real_portstates(pos) -- determine if ports are powered (by itsel
return L
end
function yc_get_virtual_portstates(pos) -- portstates according to the name
yc.get_virtual_portstates = function(pos) -- portstates according to the name
local name = minetest.get_node(pos).name
local b, a = string.find(name, ":microcontroller")
if a == nil then return nil end
@ -682,7 +684,7 @@ function yc_get_virtual_portstates(pos) -- portstates according to the name
return Lvirtual
end
function yc_merge_portstates(Lreal, Lvirtual)
yc.merge_portstates = function(Lreal, Lvirtual)
local L = {a=false, b=false, c=false, d=false}
if Lvirtual.a or Lreal.a then L.a = true end
if Lvirtual.b or Lreal.b then L.b = true end

Binary file not shown.

Before

(image error) Size: 10 KiB

After

(image error) Size: 9.6 KiB

@ -26,28 +26,28 @@ function mesecon.get_movestone_direction(pos)
lpos = {x=pos.x+1, y=pos.y, z=pos.z}
for n = 1, 3 do
if mesecon.is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
if mesecon.is_power_on(lpos, rules[n]) then
return {x=0, y=0, z=-1}
end
end
lpos = {x = pos.x-1, y = pos.y, z = pos.z}
for n=4, 6 do
if mesecon.is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
if mesecon.is_power_on(lpos, rules[n]) then
return {x=0, y=0, z=1}
end
end
lpos = {x = pos.x, y = pos.y, z = pos.z+1}
for n=7, 9 do
if mesecon.is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
if mesecon.is_power_on(lpos, rules[n]) then
return {x=-1, y=0, z=0}
end
end
lpos = {x = pos.x, y = pos.y, z = pos.z-1}
for n=10, 12 do
if mesecon.is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then
if mesecon.is_power_on(lpos, rules[n]) then
return {x=1, y=0, z=0}
end
end
@ -145,7 +145,7 @@ mesecon.register_movestone("mesecons_movestones:sticky_movestone", {
}, true)
minetest.register_craft({
output = "mesecons_movestones:sticky_movestone 2",
output = "mesecons_movestones:sticky_movestone",
recipe = {
{"mesecons_materials:glue", "mesecons_movestones:movestone", "mesecons_materials:glue"},
}

@ -200,7 +200,6 @@ end
mesecon.register_on_mvps_move(function(moved_nodes)
for _, n in ipairs(moved_nodes) do
mesecon.on_placenode(n.pos, n.node)
mesecon.update_autoconnect(n.pos)
end
end)

@ -1,6 +1,6 @@
-- Get mesecon rules of pistons
piston_rules =
{{x=0, y=0, z=1}, --everything apart from z- (pusher side)
local 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},
@ -8,29 +8,32 @@ piston_rules =
{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}
}
local piston_up_rules =
{{x=0, y=0, z=-1}, --everything apart from y+ (pusher side)
local piston_up_rules = {
{x=0, y=0, z=-1}, --everything apart from y+ (pusher side)
{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=0, y=-1, z=1},
{x=0, y=-1, z=-1}}
{x=0, y=-1, z=-1}
}
local piston_down_rules =
{{x=0, y=0, z=-1}, --everything apart from y- (pusher side)
local piston_down_rules = {
{x=0, y=0, z=-1}, --everything apart from y- (pusher side)
{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=0, y=1, z=1},
{x=0, y=1, z=-1}}
{x=0, y=1, z=-1}
}
local piston_get_rules = function (node)
local function piston_get_rules(node)
local rules = piston_rules
for i = 1, node.param2 do
rules = mesecon.rotate_rules_left(rules)
@ -38,7 +41,7 @@ local piston_get_rules = function (node)
return rules
end
piston_facedir_direction = function (node)
local function piston_facedir_direction(node)
local rules = {{x = 0, y = 0, z = -1}}
for i = 1, node.param2 do
rules = mesecon.rotate_rules_left(rules)
@ -46,7 +49,7 @@ piston_facedir_direction = function (node)
return rules[1]
end
piston_get_direction = function(dir, node)
local function piston_get_direction(dir, node)
if type(dir) == "function" then
return dir(node)
else

@ -8,7 +8,7 @@ local pp_box_on = {
fixed = { -7/16, -8/16, -7/16, 7/16, -7.5/16, 7/16 },
}
pp_on_timer = function (pos, elapsed)
local function pp_on_timer(pos, elapsed)
local node = minetest.get_node(pos)
local basename = minetest.registered_nodes[node.name].pressureplate_basename

@ -9,7 +9,7 @@ minetest.register_node("mesecons_random:removestone", {
mesecons = {effector = {
action_on = function (pos, node)
minetest.remove_node(pos)
mesecon.update_autoconnect(pos)
mesecon.on_dignode(pos, node)
end
}}
})
@ -26,7 +26,7 @@ minetest.register_craft({
-- GHOSTSTONE
minetest.register_node("mesecons_random:ghoststone", {
description="ghoststone",
description="Ghoststone",
tiles = {"jeija_ghoststone.png"},
is_ground_content = true,
inventory_image = minetest.inventorycube("jeija_ghoststone_inv.png"),
@ -53,6 +53,7 @@ minetest.register_node("mesecons_random:ghoststone_active", {
diggable = false,
sunlight_propagates = true,
paramtype = "light",
drop = "mesecons_random:ghoststone",
mesecons = {conductor = {
state = mesecon.state.on,
rules = {

@ -1,10 +1,30 @@
rcvboxes = {
local rcvboxes = {
{ -3/16, -3/16, -8/16 , 3/16, 3/16 , -13/32 }, -- the smaller bump
{ -1/32, -1/32, -3/2 , 1/32, 1/32 , -1/2 }, -- the wire through the block
{ -2/32, -1/2 , -.5 , 2/32, 0 , -.5002+3/32 }, -- the vertical wire bit
{ -2/32, -1/2 , -7/16+0.002 , 2/32, -14/32, 16/32+0.001 } -- the horizontal wire
}
local down_rcvboxes = {
{-6/16, -8/16, -6/16, 6/16, -7/16, 6/16}, -- Top plate
{-2/16, -6/16, -2/16, 2/16, -7/16, 2/16}, -- Bump
{-1/16, -8/16, -1/16, 1/16, -24/16, 1/16}, -- Wire through the block
{-1/16, -8/16, 6/16, 1/16, -7/16, 8/16}, -- Plate extension (North)
{-1/16, -8/16, -6/16, 1/16, -7/16, -8/16}, -- Plate extension (South)
{-8/16, -8/16, 1/16, -6/16, -7/16, -1/16}, -- Plate extension (West)
{6/16, -8/16, 1/16, 8/16, -7/16, -1/16}, -- Plate extension (East)
}
local up_rcvboxes = {
{-6/16, -8/16, -6/16, 6/16, -7/16, 6/16}, -- Top plate
{-2/16, -6/16, -2/16, 2/16, -7/16, 2/16}, -- Bump
{-1/16, -6/16, -1/16, 1/16, 24/16, 1/16}, -- Wire through the block
{-1/16, -8/16, 6/16, 1/16, -7/16, 8/16}, -- Plate extension (North)
{-1/16, -8/16, -6/16, 1/16, -7/16, -8/16}, -- Plate extension (South)
{-8/16, -8/16, 1/16, -6/16, -7/16, -1/16}, -- Plate extension (West)
{6/16, -8/16, 1/16, 8/16, -7/16, -1/16}, -- Plate extension (East)
}
local receiver_get_rules = function (node)
local rules = { {x = 1, y = 0, z = 0},
{x = -2, y = 0, z = 0}}
@ -18,20 +38,13 @@ local receiver_get_rules = function (node)
return rules
end
minetest.register_node("mesecons_receiver:receiver_on", {
mesecon.register_node("mesecons_receiver:receiver", {
drawtype = "nodebox",
tiles = {
"receiver_top_on.png",
"receiver_bottom_on.png",
"receiver_lr_on.png",
"receiver_lr_on.png",
"receiver_fb_on.png",
"receiver_fb_on.png",
},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
walkable = false,
on_rotate = false,
selection_box = {
type = "fixed",
fixed = { -3/16, -8/16, -8/16, 3/16, 3/16, 8/16 }
@ -42,16 +55,7 @@ minetest.register_node("mesecons_receiver:receiver_on", {
},
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", {
drawtype = "nodebox",
description = "You hacker you",
}, {
tiles = {
"receiver_top_off.png",
"receiver_bottom_off.png",
@ -60,57 +64,148 @@ minetest.register_node("mesecons_receiver:receiver_off", {
"receiver_fb_off.png",
"receiver_fb_off.png",
},
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 }
},
node_box = {
type = "fixed",
fixed = rcvboxes
},
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"
}}
}, {
tiles = {
"receiver_top_on.png",
"receiver_bottom_on.png",
"receiver_lr_on.png",
"receiver_lr_on.png",
"receiver_fb_on.png",
"receiver_fb_on.png",
},
mesecons = {conductor = {
state = mesecon.state.on,
rules = receiver_get_rules,
offstate = "mesecons_receiver:receiver_off"
}}
})
mesecon.register_node("mesecons_receiver:receiver_up", {
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
walkable = false,
on_rotate = false,
selection_box = {
type = "fixed",
fixed = up_rcvboxes
},
node_box = {
type = "fixed",
fixed = up_rcvboxes
},
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
drop = "mesecons:wire_00000000_off",
}, {
tiles = {"mesecons_wire_off.png"},
mesecons = {conductor = {
state = mesecon.state.off,
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},
{x=0, y=1, z=0},
{x=0, y=2, z=0}},
onstate = "mesecons_receiver:receiver_up_on"
}}
}, {
tiles = {"mesecons_wire_on.png"},
mesecons = {conductor = {
state = mesecon.state.on,
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},
{x=0, y=1, z=0},
{x=0, y=2, z=0}},
offstate = "mesecons_receiver:receiver_up_off"
}}
})
mesecon.register_node("mesecons_receiver:receiver_down", {
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
walkable = false,
on_rotate = false,
selection_box = {
type = "fixed",
fixed = down_rcvboxes
},
node_box = {
type = "fixed",
fixed = down_rcvboxes
},
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
drop = "mesecons:wire_00000000_off",
}, {
tiles = {"mesecons_wire_off.png"},
mesecons = {conductor = {
state = mesecon.state.off,
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},
{x=0, y=-2,z=0}},
onstate = "mesecons_receiver:receiver_down_on"
}}
}, {
tiles = {"mesecons_wire_on.png"},
mesecons = {conductor = {
state = mesecon.state.on,
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},
{x=0, y=-2,z=0}},
offstate = "mesecons_receiver:receiver_down_off"
}}
})
function mesecon.receiver_get_pos_from_rcpt(pos, param2)
local rules = {{x = 2, y = 0, z = 0}}
if param2 == nil then param2 = minetest.get_node(pos).param2 end
if param2 == 2 then
local rcvtype = "mesecons_receiver:receiver_off"
local dir = minetest.facedir_to_dir(param2)
if dir.x == 1 then
-- No action needed
elseif dir.z == -1 then
rules = mesecon.rotate_rules_left(rules)
elseif param2 == 3 then
elseif dir.x == -1 then
rules = mesecon.rotate_rules_right(mesecon.rotate_rules_right(rules))
elseif param2 == 0 then
elseif dir.z == 1 then
rules = mesecon.rotate_rules_right(rules)
elseif dir.y == -1 then
rules = mesecon.rotate_rules_up(rules)
rcvtype = "mesecons_receiver:receiver_up_off"
elseif dir.y == 1 then
rules = mesecon.rotate_rules_down(rules)
rcvtype = "mesecons_receiver:receiver_down_off"
end
local np = { x = pos.x + rules[1].x,
y = pos.y + rules[1].y,
z = pos.z + rules[1].z}
return np
return np, rcvtype
end
function mesecon.receiver_place(rcpt_pos)
local node = minetest.get_node(rcpt_pos)
local pos = mesecon.receiver_get_pos_from_rcpt(rcpt_pos, node.param2)
local pos, rcvtype = mesecon.receiver_get_pos_from_rcpt(rcpt_pos, node.param2)
local nn = minetest.get_node(pos)
local param2 = minetest.dir_to_facedir(minetest.facedir_to_dir(node.param2))
if string.find(nn.name, "mesecons:wire_") ~= nil then
minetest.dig_node(pos)
if mesecon.is_power_on(rcpt_pos) then
minetest.set_node(pos, {name = "mesecons_receiver:receiver_on", param2 = node.param2})
mesecon.receptor_on(pos, receiver_get_rules(node))
else
minetest.set_node(pos, {name = "mesecons_receiver:receiver_off", param2 = node.param2})
end
mesecon.update_autoconnect(pos)
minetest.set_node(pos, {name = rcvtype, param2 = param2})
mesecon.on_placenode(pos, nn)
end
end
@ -121,7 +216,6 @@ function mesecon.receiver_remove(rcpt_pos, dugnode)
minetest.dig_node(pos)
local node = {name = "mesecons:wire_00000000_off"}
minetest.set_node(pos, node)
mesecon.update_autoconnect(pos)
mesecon.on_placenode(pos, node)
end
end
@ -139,11 +233,13 @@ minetest.register_on_dignode(function(pos, node)
end)
minetest.register_on_placenode(function (pos, node)
if string.find(node.name, "mesecons:wire_") ~=nil then
local rules = { {x = 2, y = 0, z = 0},
{x =-2, y = 0, z = 0},
{x = 0, y = 0, z = 2},
{x = 0, y = 0, z =-2}}
if string.find(node.name, "mesecons:wire_") ~= nil then
local rules = { {x = 2, y = 0, z = 0},
{x =-2, y = 0, z = 0},
{x = 0, y = 0, z = 2},
{x = 0, y = 0, z =-2},
{x = 0, y = 2, z = 0},
{x = 0, y = -2, z = 0}}
local i = 1
while rules[i] ~= nil do
local np = { x = pos.x + rules[i].x,
@ -156,3 +252,8 @@ minetest.register_on_placenode(function (pos, node)
end
end
end)
function mesecon.buttonlike_onrotate(pos, node)
minetest.after(0, mesecon.receiver_remove, pos, node)
minetest.after(0, mesecon.receiver_place, pos)
end

@ -31,6 +31,7 @@ mesecon.register_node("mesecons_walllever:wall_lever", {
"jeija_wall_lever_back_edges.png"
},
mesh="jeija_wall_lever_off.obj",
on_rotate = mesecon.buttonlike_onrotate,
mesecons = {receptor = {
rules = mesecon.rules.buttonlike_get,
state = mesecon.state.off
@ -44,6 +45,7 @@ mesecon.register_node("mesecons_walllever:wall_lever", {
"jeija_wall_lever_back_edges.png"
},
mesh="jeija_wall_lever_on.obj",
on_rotate = false,
mesecons = {receptor = {
rules = mesecon.rules.buttonlike_get,
state = mesecon.state.on

@ -0,0 +1 @@
mesecons

@ -0,0 +1 @@
Mesecons are the wires, use them to connect effectors with receptors.

Before

(image error) Size: 29 KiB

After

(image error) Size: 29 KiB

Before

(image error) Size: 3.8 KiB

After

(image error) Size: 3.8 KiB

@ -91,10 +91,7 @@ local update_on_place_dig = function (pos, node)
end
end
function mesecon.update_autoconnect(pos, node)
if (not node) then node = minetest.get_node(pos) end
update_on_place_dig(pos, node)
end
mesecon.register_autoconnect_hook("wire", update_on_place_dig)
-- ############################
-- ## Wire node registration ##
@ -143,7 +140,7 @@ nid_inc = function (nid)
return i <= 8
end
register_wires = function()
local function register_wires()
local nid = {}
while true do
-- Create group specifiction and nodeid string (see note above for details)
@ -204,7 +201,7 @@ register_wires = function()
groups_off["not_in_creative_inventory"] = 1
end
mesecon.register_node("mesecons:wire_"..nodeid, {
mesecon.register_node(":mesecons:wire_"..nodeid, {
description = "Mesecon",
drawtype = "nodebox",
inventory_image = "mesecons_wire_inv.png",