summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeija <jeija@mesecons.net>2014-11-22 11:37:47 +0100
committerJeija <jeija@mesecons.net>2014-11-22 11:40:58 +0100
commit194155fff8e848750dc716fd920045b3c340310d (patch)
tree5717748611bf2483e68a1eba908381fb7b064f19
parent87bfbb4de9b447eb3f69decc68a7695c070c99af (diff)
downloadmesecons-194155fff8e848750dc716fd920045b3c340310d.tar
mesecons-194155fff8e848750dc716fd920045b3c340310d.tar.gz
mesecons-194155fff8e848750dc716fd920045b3c340310d.tar.bz2
mesecons-194155fff8e848750dc716fd920045b3c340310d.tar.xz
mesecons-194155fff8e848750dc716fd920045b3c340310d.zip
Rewrite mesecon wires. This should increase the efficiency and speed of
large machines. It also makes the wires.lua code easier to understand and more maintainable. In case any other mod depends on mesecon:update_autoconnect, please update it to use mesecon.update_autoconnect. This should also fix some other minor bugs. Please report bugs if this commit creates new ones. This commit changes wire looks and removes some unneccesary textures.
-rw-r--r--mesecons/actionqueue.lua2
-rw-r--r--mesecons/internal.lua18
-rw-r--r--mesecons/services.lua7
-rw-r--r--mesecons/textures/jeija_mesecon_crossing_off.pngbin341 -> 0 bytes
-rw-r--r--mesecons/textures/jeija_mesecon_crossing_on.pngbin340 -> 0 bytes
-rw-r--r--mesecons/textures/jeija_mesecon_curved_off.pngbin307 -> 0 bytes
-rw-r--r--mesecons/textures/jeija_mesecon_curved_on.pngbin307 -> 0 bytes
-rw-r--r--mesecons/textures/jeija_mesecon_inverter_off.pngbin743 -> 0 bytes
-rw-r--r--mesecons/textures/jeija_mesecon_inverter_on.pngbin725 -> 0 bytes
-rw-r--r--mesecons/textures/jeija_mesecon_on.pngbin196 -> 0 bytes
-rw-r--r--mesecons/textures/jeija_mesecon_plug.pngbin713 -> 0 bytes
-rw-r--r--mesecons/textures/jeija_mesecon_socket_off.pngbin751 -> 0 bytes
-rw-r--r--mesecons/textures/jeija_mesecon_socket_on.pngbin737 -> 0 bytes
-rw-r--r--mesecons/textures/jeija_mesecon_t_junction_off.pngbin330 -> 0 bytes
-rw-r--r--mesecons/textures/jeija_mesecon_t_junction_on.pngbin319 -> 0 bytes
-rw-r--r--mesecons/textures/mesecons_wire_inv.png (renamed from mesecons/textures/jeija_mesecon_off.png)bin204 -> 204 bytes
-rw-r--r--mesecons/textures/mesecons_wire_off.png (renamed from mesecons/textures/wires_full_off.png)bin465 -> 465 bytes
-rw-r--r--mesecons/textures/mesecons_wire_on.png (renamed from mesecons/textures/wires_full_on.png)bin464 -> 464 bytes
-rw-r--r--mesecons/textures/wires_bump_off.pngbin347 -> 0 bytes
-rw-r--r--mesecons/textures/wires_bump_on.pngbin386 -> 0 bytes
-rw-r--r--mesecons/textures/wires_inv.pngbin167 -> 0 bytes
-rw-r--r--mesecons/textures/wires_off.pngbin454 -> 0 bytes
-rw-r--r--mesecons/textures/wires_on.pngbin492 -> 0 bytes
-rw-r--r--mesecons/textures/wires_vertical_off.pngbin373 -> 0 bytes
-rw-r--r--mesecons/textures/wires_vertical_on.pngbin396 -> 0 bytes
-rw-r--r--mesecons/util.lua17
-rw-r--r--mesecons/wires.lua477
-rw-r--r--mesecons_extrawires/vertical.lua12
-rw-r--r--mesecons_insulated/init.lua6
-rw-r--r--mesecons_microcontroller/init.lua14
-rw-r--r--mesecons_movestones/init.lua4
-rw-r--r--mesecons_mvps/init.lua9
-rw-r--r--mesecons_receiver/init.lua19
33 files changed, 276 insertions, 309 deletions
diff --git a/mesecons/actionqueue.lua b/mesecons/actionqueue.lua
index e0b8c65..e7cbc55 100644
--- a/mesecons/actionqueue.lua
+++ b/mesecons/actionqueue.lua
@@ -14,7 +14,7 @@ function mesecon.queue:add_action(pos, func, params, time, overwritecheck, prior
priority = priority or 1
local action = { pos=mesecon:tablecopy(pos),
func=func,
- params=mesecon:tablecopy(params),
+ params=mesecon:tablecopy(params or {}),
time=time,
owcheck=(overwritecheck and mesecon:tablecopy(overwritecheck)) or nil,
priority=priority}
diff --git a/mesecons/internal.lua b/mesecons/internal.lua
index d45b0bf..edf361f 100644
--- a/mesecons/internal.lua
+++ b/mesecons/internal.lua
@@ -26,10 +26,6 @@
-- mesecon:deactivate(pos, node, recdepth) --> Deactivates the effector node at the specific pos (calls nodedef.mesecons.effector.action_off), "
-- mesecon:changesignal(pos, node, rulename, newstate) --> Changes the effector node at the specific pos (calls nodedef.mesecons.effector.action_change), "
--- RULES
--- mesecon:add_rules(name, rules) | deprecated? --> Saves rules table by name
--- mesecon:get_rules(name, rules) | deprecated? --> Loads rules table with name
-
-- CONDUCTORS
-- mesecon:is_conductor(nodename) --> Returns true if nodename is a conductor
-- mesecon:is_conductor_on(node) --> Returns true if node is a conductor with state = mesecon.state.on
@@ -244,18 +240,6 @@ function mesecon:changesignal(pos, node, rulename, newstate, recdepth)
mesecon.queue:add_action(pos, "change", {rulename, newstate}, nil, rulename, 1 / recdepth)
end
--- #########
--- # Rules # "Database" for rulenames
--- #########
-
-function mesecon:add_rules(name, rules)
- mesecon.rules[name] = rules
-end
-
-function mesecon:get_rules(name)
- return mesecon.rules[name]
-end
-
-- Conductors
function mesecon:is_conductor_on(node, rulename)
@@ -548,7 +532,7 @@ function mesecon:rules_link(output, input, dug_outputrules) --output/input are p
return false
end
-function mesecon:rules_link_rule_all(output, rule) --output/input are positions (outputrules optional, used if node has been dug), second return value: affected input rules
+function mesecon:rules_link_rule_all(output, rule)
local input = mesecon:addPosRule(output, rule)
local inputnode = minetest.get_node(input)
local inputrules = mesecon:get_any_inputrules (inputnode)
diff --git a/mesecons/services.lua b/mesecons/services.lua
index d549cb0..0cf94d2 100644
--- a/mesecons/services.lua
+++ b/mesecons/services.lua
@@ -1,6 +1,8 @@
-- Dig and place services
mesecon.on_placenode = function (pos, node)
+ mesecon.update_autoconnect(pos, node)
+
-- Receptors: Send on signal when active
if mesecon:is_receptor_on(node.name) then
mesecon:receptor_on(pos, mesecon:receptor_get_rules(node))
@@ -18,7 +20,7 @@ mesecon.on_placenode = function (pos, node)
mesecon:turnon(pos, rule)
end
--mesecon:receptor_on (pos, mesecon:conductor_get_rules(node))
- elseif mesecon:is_conductor_off(node.name) then
+ elseif mesecon:is_conductor_on(node) then
minetest.swap_node(pos, {name = mesecon:get_conductor_off(node)})
end
end
@@ -41,8 +43,11 @@ mesecon.on_dignode = function (pos, 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)
+
minetest.register_on_placenode(mesecon.on_placenode)
minetest.register_on_dignode(mesecon.on_dignode)
diff --git a/mesecons/textures/jeija_mesecon_crossing_off.png b/mesecons/textures/jeija_mesecon_crossing_off.png
deleted file mode 100644
index 4e3ca03..0000000
--- a/mesecons/textures/jeija_mesecon_crossing_off.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/jeija_mesecon_crossing_on.png b/mesecons/textures/jeija_mesecon_crossing_on.png
deleted file mode 100644
index 4518fa7..0000000
--- a/mesecons/textures/jeija_mesecon_crossing_on.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/jeija_mesecon_curved_off.png b/mesecons/textures/jeija_mesecon_curved_off.png
deleted file mode 100644
index b34335f..0000000
--- a/mesecons/textures/jeija_mesecon_curved_off.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/jeija_mesecon_curved_on.png b/mesecons/textures/jeija_mesecon_curved_on.png
deleted file mode 100644
index fa882e4..0000000
--- a/mesecons/textures/jeija_mesecon_curved_on.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/jeija_mesecon_inverter_off.png b/mesecons/textures/jeija_mesecon_inverter_off.png
deleted file mode 100644
index bd4de1b..0000000
--- a/mesecons/textures/jeija_mesecon_inverter_off.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/jeija_mesecon_inverter_on.png b/mesecons/textures/jeija_mesecon_inverter_on.png
deleted file mode 100644
index be41599..0000000
--- a/mesecons/textures/jeija_mesecon_inverter_on.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/jeija_mesecon_on.png b/mesecons/textures/jeija_mesecon_on.png
deleted file mode 100644
index d7ebeec..0000000
--- a/mesecons/textures/jeija_mesecon_on.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/jeija_mesecon_plug.png b/mesecons/textures/jeija_mesecon_plug.png
deleted file mode 100644
index 8a4d281..0000000
--- a/mesecons/textures/jeija_mesecon_plug.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/jeija_mesecon_socket_off.png b/mesecons/textures/jeija_mesecon_socket_off.png
deleted file mode 100644
index ad3f601..0000000
--- a/mesecons/textures/jeija_mesecon_socket_off.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/jeija_mesecon_socket_on.png b/mesecons/textures/jeija_mesecon_socket_on.png
deleted file mode 100644
index 6a9c480..0000000
--- a/mesecons/textures/jeija_mesecon_socket_on.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/jeija_mesecon_t_junction_off.png b/mesecons/textures/jeija_mesecon_t_junction_off.png
deleted file mode 100644
index 7131846..0000000
--- a/mesecons/textures/jeija_mesecon_t_junction_off.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/jeija_mesecon_t_junction_on.png b/mesecons/textures/jeija_mesecon_t_junction_on.png
deleted file mode 100644
index a6609ee..0000000
--- a/mesecons/textures/jeija_mesecon_t_junction_on.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/jeija_mesecon_off.png b/mesecons/textures/mesecons_wire_inv.png
index a3930cb..a3930cb 100644
--- a/mesecons/textures/jeija_mesecon_off.png
+++ b/mesecons/textures/mesecons_wire_inv.png
Binary files differ
diff --git a/mesecons/textures/wires_full_off.png b/mesecons/textures/mesecons_wire_off.png
index 58164fa..58164fa 100644
--- a/mesecons/textures/wires_full_off.png
+++ b/mesecons/textures/mesecons_wire_off.png
Binary files differ
diff --git a/mesecons/textures/wires_full_on.png b/mesecons/textures/mesecons_wire_on.png
index 98a86c8..98a86c8 100644
--- a/mesecons/textures/wires_full_on.png
+++ b/mesecons/textures/mesecons_wire_on.png
Binary files differ
diff --git a/mesecons/textures/wires_bump_off.png b/mesecons/textures/wires_bump_off.png
deleted file mode 100644
index 1e0bd74..0000000
--- a/mesecons/textures/wires_bump_off.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/wires_bump_on.png b/mesecons/textures/wires_bump_on.png
deleted file mode 100644
index da9a661..0000000
--- a/mesecons/textures/wires_bump_on.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/wires_inv.png b/mesecons/textures/wires_inv.png
deleted file mode 100644
index 626f8d4..0000000
--- a/mesecons/textures/wires_inv.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/wires_off.png b/mesecons/textures/wires_off.png
deleted file mode 100644
index 757d339..0000000
--- a/mesecons/textures/wires_off.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/wires_on.png b/mesecons/textures/wires_on.png
deleted file mode 100644
index 57bb82d..0000000
--- a/mesecons/textures/wires_on.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/wires_vertical_off.png b/mesecons/textures/wires_vertical_off.png
deleted file mode 100644
index ba8d472..0000000
--- a/mesecons/textures/wires_vertical_off.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/textures/wires_vertical_on.png b/mesecons/textures/wires_vertical_on.png
deleted file mode 100644
index 172fa65..0000000
--- a/mesecons/textures/wires_vertical_on.png
+++ /dev/null
Binary files differ
diff --git a/mesecons/util.lua b/mesecons/util.lua
index 91d435a..e49e82c 100644
--- a/mesecons/util.lua
+++ b/mesecons/util.lua
@@ -193,3 +193,20 @@ function mesecon:cmpAny(t1, t2)
return true
end
+
+-- does not overwrite values
+mesecon.mergetable = function(source, dest)
+ for k, v in pairs(source) do
+ dest[k] = dest[k] or v
+ end
+end
+
+mesecon.register_node = function(name, spec_common, spec_off, spec_on)
+ spec_common.drop = spec_common.drop or name .. "_off"
+
+ mesecon.mergetable(spec_common, spec_on);
+ mesecon.mergetable(spec_common, spec_off);
+
+ minetest.register_node(name .. "_on", spec_on)
+ minetest.register_node(name .. "_off", spec_off)
+end
diff --git a/mesecons/wires.lua b/mesecons/wires.lua
index 499c781..158d436 100644
--- a/mesecons/wires.lua
+++ b/mesecons/wires.lua
@@ -1,280 +1,251 @@
--- naming scheme: wire:(xp)(zp)(xm)(zm)_on/off
--- The conditions in brackets define whether there is a mesecon at that place or not
--- 1 = there is one; 0 = there is none
--- y always means y+
-
-box_center = {-1/16, -.5, -1/16, 1/16, -.5+1/16, 1/16}
-box_bump1 = { -2/16, -8/16, -2/16, 2/16, -13/32, 2/16 }
-
-box_xp = {1/16, -.5, -1/16, 8/16, -.5+1/16, 1/16}
-box_zp = {-1/16, -.5, 1/16, 1/16, -.5+1/16, 8/16}
-box_xm = {-8/16, -.5, -1/16, -1/16, -.5+1/16, 1/16}
-box_zm = {-1/16, -.5, -8/16, 1/16, -.5+1/16, -1/16}
-
-box_xpy = {.5-1/16, -.5+1/16, -1/16, .5, .4999+1/16, 1/16}
-box_zpy = {-1/16, -.5+1/16, .5-1/16, 1/16, .4999+1/16, .5}
-box_xmy = {-.5, -.5+1/16, -1/16, -.5+1/16, .4999+1/16, 1/16}
-box_zmy = {-1/16, -.5+1/16, -.5, 1/16, .4999+1/16, -.5+1/16}
-
--- Registering the wires
-
-for xp=0, 1 do
-for zp=0, 1 do
-for xm=0, 1 do
-for zm=0, 1 do
-for xpy=0, 1 do
-for zpy=0, 1 do
-for xmy=0, 1 do
-for zmy=0, 1 do
- if (xpy == 1 and xp == 0) or (zpy == 1 and zp == 0)
- or (xmy == 1 and xm == 0) or (zmy == 1 and zm == 0) then break end
-
- local groups
- local nodeid = tostring(xp )..tostring(zp )..tostring(xm )..tostring(zm )..
- tostring(xpy)..tostring(zpy)..tostring(xmy)..tostring(zmy)
-
- if nodeid == "00000000" then
- groups = {dig_immediate = 3, mesecon_conductor_craftable=1}
- wiredesc = "Mesecon"
- else
- groups = {dig_immediate = 3, not_in_creative_inventory = 1}
- wiredesc = "Mesecons Wire (ID: "..nodeid..")"
+-- naming scheme: wire:(xp)(zp)(xm)(zm)(xpyp)(zpyp)(xmyp)(zmyp)_on/off
+-- where x= x direction, z= z direction, y= y direction, p = +1, m = -1, e.g. xpym = {x=1, y=-1, z=0}
+-- The (xp)/(zpyp)/.. statements shall be replaced by either 0 or 1
+-- Where 0 means the wire has no visual connection to that direction and
+-- 1 means that the wire visually connects to that other node.
+
+-- #######################
+-- ## Update wire looks ##
+-- #######################
+
+-- self_pos = pos of any mesecon node, from_pos = pos of conductor to getconnect for
+local wire_getconnect = function (from_pos, self_pos)
+ local node = minetest.get_node(self_pos)
+ if minetest.registered_nodes[node.name]
+ and minetest.registered_nodes[node.name].mesecons then
+ -- rules of node to possibly connect to
+ local rules = {}
+ if (minetest.registered_nodes[node.name].mesecon_wire) then
+ rules = mesecon.rules.default
+ else
+ rules = mesecon:get_any_inputrules(node) or {}
+ mesecon.mergetable(mesecon:get_any_outputrules(node) or {}, rules)
+ end
+
+ for _, r in ipairs(mesecon:flattenrules(rules)) do
+ if (mesecon:cmpPos(mesecon:addPosRule(self_pos, r), from_pos)) then
+ return true
+ end
+ end
end
+ return false
+end
- local nodebox = {}
- local adjx = false
- local adjz = false
- if xp == 1 then table.insert(nodebox, box_xp) adjx = true end
- if zp == 1 then table.insert(nodebox, box_zp) adjz = true end
- if xm == 1 then table.insert(nodebox, box_xm) adjx = true end
- if zm == 1 then table.insert(nodebox, box_zm) adjz = true end
- if xpy == 1 then table.insert(nodebox, box_xpy) end
- if zpy == 1 then table.insert(nodebox, box_zpy) end
- if xmy == 1 then table.insert(nodebox, box_xmy) end
- if zmy == 1 then table.insert(nodebox, box_zmy) end
-
- if adjx and adjz and (xp + zp + xm + zm > 2) then
- table.insert(nodebox, box_bump1)
- tiles_off = {
- "wires_bump_off.png",
- "wires_bump_off.png",
- "wires_vertical_off.png",
- "wires_vertical_off.png",
- "wires_vertical_off.png",
- "wires_vertical_off.png"
- }
- tiles_on = {
- "wires_bump_on.png",
- "wires_bump_on.png",
- "wires_vertical_on.png",
- "wires_vertical_on.png",
- "wires_vertical_on.png",
- "wires_vertical_on.png"
- }
- else
- table.insert(nodebox, box_center)
- tiles_off = {
- "wires_off.png",
- "wires_off.png",
- "wires_vertical_off.png",
- "wires_vertical_off.png",
- "wires_vertical_off.png",
- "wires_vertical_off.png"
- }
- tiles_on = {
- "wires_on.png",
- "wires_on.png",
- "wires_vertical_on.png",
- "wires_vertical_on.png",
- "wires_vertical_on.png",
- "wires_vertical_on.png"
- }
+-- Update this node
+local wire_updateconnect = function (pos)
+ local connections = {}
+
+ for _, r in ipairs(mesecon.rules.default) do
+ if wire_getconnect(pos, mesecon:addPosRule(pos, r)) then
+ table.insert(connections, r)
+ end
end
- if nodeid == "00000000" then
- nodebox = {-8/16, -.5, -1/16, 8/16, -.5+1/16, 1/16}
+ local nid = {}
+ for _, vec in ipairs(connections) do
+ -- flat component
+ if vec.x == 1 then nid[0] = "1" end
+ if vec.z == 1 then nid[1] = "1" end
+ if vec.x == -1 then nid[2] = "1" end
+ if vec.z == -1 then nid[3] = "1" end
+
+ -- slopy component
+ if vec.y == 1 then
+ if vec.x == 1 then nid[4] = "1" end
+ if vec.z == 1 then nid[5] = "1" end
+ if vec.x == -1 then nid[6] = "1" end
+ if vec.z == -1 then nid[7] = "1" end
+ end
end
- minetest.register_node("mesecons:wire_"..nodeid.."_off", {
- description = wiredesc,
- drawtype = "nodebox",
- tiles = tiles_off,
--- inventory_image = "wires_inv.png",
--- wield_image = "wires_inv.png",
- inventory_image = "jeija_mesecon_off.png",
- wield_image = "jeija_mesecon_off.png",
- paramtype = "light",
- paramtype2 = "facedir",
- sunlight_propagates = true,
- selection_box = {
- type = "fixed",
- fixed = {-.5, -.5, -.5, .5, -.5+4/16, .5}
- },
- node_box = {
- type = "fixed",
- fixed = nodebox
- },
- groups = groups,
- walkable = false,
- stack_max = 99,
- drop = "mesecons:wire_00000000_off",
- mesecons = {conductor={
- state = mesecon.state.off,
- onstate = "mesecons:wire_"..nodeid.."_on"
- }}
- })
-
- minetest.register_node("mesecons:wire_"..nodeid.."_on", {
- description = "Wire ID:"..nodeid,
- drawtype = "nodebox",
- tiles = tiles_on,
--- inventory_image = "wires_inv.png",
--- wield_image = "wires_inv.png",
- inventory_image = "jeija_mesecon_off.png",
- wield_image = "jeija_mesecon_off.png",
- paramtype = "light",
- paramtype2 = "facedir",
- sunlight_propagates = true,
- selection_box = {
- type = "fixed",
- fixed = {-.5, -.5, -.5, .5, -.5+4/16, .5}
- },
- node_box = {
- type = "fixed",
- fixed = nodebox
- },
- groups = {dig_immediate = 3, mesecon = 2, not_in_creative_inventory = 1},
- walkable = false,
- stack_max = 99,
- drop = "mesecons:wire_00000000_off",
- mesecons = {conductor={
- state = mesecon.state.on,
- offstate = "mesecons:wire_"..nodeid.."_off"
- }}
- })
-end
-end
-end
-end
-end
-end
-end
-end
+ local nodeid = (nid[0] or "0")..(nid[1] or "0")..(nid[2] or "0")..(nid[3] or "0")
+ ..(nid[4] or "0")..(nid[5] or "0")..(nid[6] or "0")..(nid[7] or "0")
--- Updating the wires:
--- Place the right connection wire
+ local state_suffix = string.find(minetest.get_node(pos).name, "_off") and "_off" or "_on"
+ minetest.set_node(pos, {name = "mesecons:wire_"..nodeid..state_suffix})
+end
local update_on_place_dig = function (pos, node)
- if minetest.registered_nodes[node.name]
- and minetest.registered_nodes[node.name].mesecons then
- mesecon:update_autoconnect(pos)
+ -- Update placed node (get_node again as it may have been dug)
+ local nn = minetest.get_node(pos)
+ if (minetest.registered_nodes[nn.name])
+ and (minetest.registered_nodes[nn.name].mesecon_wire) then
+ wire_updateconnect(pos)
end
-end
-minetest.register_on_placenode(update_on_place_dig)
-minetest.register_on_dignode(update_on_place_dig)
-
-function mesecon:update_autoconnect(pos, secondcall, replace_old)
- local xppos = {x=pos.x+1, y=pos.y, z=pos.z}
- local zppos = {x=pos.x, y=pos.y, z=pos.z+1}
- local xmpos = {x=pos.x-1, y=pos.y, z=pos.z}
- local zmpos = {x=pos.x, y=pos.y, z=pos.z-1}
-
- local xpympos = {x=pos.x+1, y=pos.y-1, z=pos.z}
- local zpympos = {x=pos.x, y=pos.y-1, z=pos.z+1}
- local xmympos = {x=pos.x-1, y=pos.y-1, z=pos.z}
- local zmympos = {x=pos.x, y=pos.y-1, z=pos.z-1}
-
- local xpypos = {x=pos.x+1, y=pos.y+1, z=pos.z}
- local zpypos = {x=pos.x, y=pos.y+1, z=pos.z+1}
- local xmypos = {x=pos.x-1, y=pos.y+1, z=pos.z}
- local zmypos = {x=pos.x, y=pos.y+1, z=pos.z-1}
-
- if secondcall == nil then
- mesecon:update_autoconnect(xppos, true)
- mesecon:update_autoconnect(zppos, true)
- mesecon:update_autoconnect(xmpos, true)
- mesecon:update_autoconnect(zmpos, true)
-
- mesecon:update_autoconnect(xpypos, true)
- mesecon:update_autoconnect(zpypos, true)
- mesecon:update_autoconnect(xmypos, true)
- mesecon:update_autoconnect(zmypos, true)
-
- mesecon:update_autoconnect(xpympos, true)
- mesecon:update_autoconnect(zpympos, true)
- mesecon:update_autoconnect(xmympos, true)
- mesecon:update_autoconnect(zmympos, true)
+ -- Update nodes around it
+ local rules = {}
+ if minetest.registered_nodes[node.name]
+ and minetest.registered_nodes[node.name].mesecon_wire then
+ rules = mesecon.rules.default
+ else
+ rules = mesecon:get_any_inputrules(node) or {}
+ mesecon.mergetable(mesecon:get_any_outputrules(node) or {}, rules)
+ end
+ if (not rules) then return end
+
+ for _, r in ipairs(mesecon:flattenrules(rules)) do
+ local np = mesecon:addPosRule(pos, r)
+ if minetest.registered_nodes[minetest.get_node(np).name]
+ and minetest.registered_nodes[minetest.get_node(np).name].mesecon_wire then
+ wire_updateconnect(np)
+ end
end
+end
- nodename = minetest.get_node(pos).name
- if string.find(nodename, "mesecons:wire_") == nil and not replace_old then return nil end
+function mesecon.update_autoconnect(pos, node)
+ if (not node) then node = minetest.get_node(pos) end
+ update_on_place_dig(pos, node)
+end
- if mesecon:rules_link_anydir(pos, xppos) then xp = 1 else xp = 0 end
- if mesecon:rules_link_anydir(pos, xmpos) then xm = 1 else xm = 0 end
- if mesecon:rules_link_anydir(pos, zppos) then zp = 1 else zp = 0 end
- if mesecon:rules_link_anydir(pos, zmpos) then zm = 1 else zm = 0 end
+-- ############################
+-- ## Wire node registration ##
+-- ############################
+-- Nodeboxes:
+local box_center = {-1/16, -.5, -1/16, 1/16, -.5+1/16, 1/16}
+local box_bump1 = { -2/16, -8/16, -2/16, 2/16, -13/32, 2/16 }
+
+local nbox_nid =
+{
+ [0] = {1/16, -.5, -1/16, 8/16, -.5+1/16, 1/16}, -- x positive
+ [1] = {-1/16, -.5, 1/16, 1/16, -.5+1/16, 8/16}, -- z positive
+ [2] = {-8/16, -.5, -1/16, -1/16, -.5+1/16, 1/16}, -- x negative
+ [3] = {-1/16, -.5, -8/16, 1/16, -.5+1/16, -1/16}, -- z negative
+
+ [4] = {.5-1/16, -.5+1/16, -1/16, .5, .4999+1/16, 1/16}, -- x positive up
+ [5] = {-1/16, -.5+1/16, .5-1/16, 1/16, .4999+1/16, .5}, -- z positive up
+ [6] = {-.5, -.5+1/16, -1/16, -.5+1/16, .4999+1/16, 1/16}, -- x negative up
+ [7] = {-1/16, -.5+1/16, -.5, 1/16, .4999+1/16, -.5+1/16} -- z negative up
+}
+
+local tiles_off = { "mesecons_wire_off.png" }
+local tiles_on = { "mesecons_wire_on.png" }
+
+local selectionbox =
+{
+ type = "fixed",
+ fixed = {-.5, -.5, -.5, .5, -.5+4/16, .5}
+}
+
+-- go to the next nodeid (ex.: 01000011 --> 01000100)
+local nid_inc = function() end
+nid_inc = function (nid)
+ local i = 0
+ while nid[i-1] ~= 1 do
+ nid[i] = (nid[i] ~= 1) and 1 or 0
+ i = i + 1
+ end
- if mesecon:rules_link_anydir(pos, xpympos) then xp = 1 end
- if mesecon:rules_link_anydir(pos, xmympos) then xm = 1 end
- if mesecon:rules_link_anydir(pos, zpympos) then zp = 1 end
- if mesecon:rules_link_anydir(pos, zmympos) then zm = 1 end
+ -- BUT: Skip impossible nodeids:
+ if ((nid[0] == 0 and nid[4] == 1) or (nid[1] == 0 and nid[5] == 1)
+ or (nid[2] == 0 and nid[6] == 1) or (nid[3] == 0 and nid[7] == 1)) then
+ return nid_inc(nid)
+ end
- if mesecon:rules_link_anydir(pos, xpypos) then xpy = 1 else xpy = 0 end
- if mesecon:rules_link_anydir(pos, zpypos) then zpy = 1 else zpy = 0 end
- if mesecon:rules_link_anydir(pos, xmypos) then xmy = 1 else xmy = 0 end
- if mesecon:rules_link_anydir(pos, zmypos) then zmy = 1 else zmy = 0 end
+ return i <= 8
+end
- if xpy == 1 then xp = 1 end
- if zpy == 1 then zp = 1 end
- if xmy == 1 then xm = 1 end
- if zmy == 1 then zm = 1 end
+register_wires = function()
+ local nid = {}
+ while true do
+ -- Create group specifiction and nodeid string (see note above for details)
+ local nodeid = (nid[0] or "0")..(nid[1] or "0")..(nid[2] or "0")..(nid[3] or "0")
+ ..(nid[4] or "0")..(nid[5] or "0")..(nid[6] or "0")..(nid[7] or "0")
+
+ -- Calculate nodebox
+ local nodebox = {type = "fixed", fixed={box_center}}
+ for i=0,7 do
+ if nid[i] == 1 then
+ table.insert(nodebox.fixed, nbox_nid[i])
+ end
+ end
+
+ -- Add bump to nodebox if curved
+ if (nid[0] == 1 and nid[1] == 1) or (nid[1] == 1 and nid[2] == 1)
+ or (nid[2] == 1 and nid[3] == 1) or (nid[3] == 1 and nid[0] == 1) then
+ table.insert(nodebox.fixed, box_bump1)
+ end
+
+ -- If nothing to connect to, still make a nodebox of a straight wire
+ if nodeid == "00000000" then
+ nodebox.fixed = {-8/16, -.5, -1/16, 8/16, -.5+1/16, 1/16}
+ end
+
+ local rules = {}
+ if (nid[0] == 1) then table.insert(rules, vector.new( 1, 0, 0)) end
+ if (nid[1] == 1) then table.insert(rules, vector.new( 0, 0, 1)) end
+ if (nid[2] == 1) then table.insert(rules, vector.new(-1, 0, 0)) end
+ if (nid[3] == 1) then table.insert(rules, vector.new( 0, 0, -1)) end
+
+ if (nid[0] == 1) then table.insert(rules, vector.new( 1, -1, 0)) end
+ if (nid[1] == 1) then table.insert(rules, vector.new( 0, -1, 1)) end
+ if (nid[2] == 1) then table.insert(rules, vector.new(-1, -1, 0)) end
+ if (nid[3] == 1) then table.insert(rules, vector.new( 0, -1, -1)) end
+
+ if (nid[4] == 1) then table.insert(rules, vector.new( 1, 1, 0)) end
+ if (nid[5] == 1) then table.insert(rules, vector.new( 0, 1, 1)) end
+ if (nid[6] == 1) then table.insert(rules, vector.new(-1, 1, 0)) end
+ if (nid[7] == 1) then table.insert(rules, vector.new( 0, 1, -1)) end
+
+ local meseconspec_off = { conductor = {
+ rules = rules,
+ state = mesecon.state.off,
+ onstate = "mesecons:wire_"..nodeid.."_on"
+ }}
- local nodeid = tostring(xp )..tostring(zp )..tostring(xm )..tostring(zm )..
- tostring(xpy)..tostring(zpy)..tostring(xmy)..tostring(zmy)
+ local meseconspec_on = { conductor = {
+ rules = rules,
+ state = mesecon.state.on,
+ offstate = "mesecons:wire_"..nodeid.."_off"
+ }}
-
- if string.find(nodename, "_off") ~= nil then
- minetest.set_node(pos, {name = "mesecons:wire_"..nodeid.."_off"})
- else
- minetest.set_node(pos, {name = "mesecons:wire_"..nodeid.."_on" })
+ local groups_on = {dig_immediate = 3, not_in_creative_inventory = 1}
+ local groups_off = {dig_immediate = 3}
+ if nodeid ~= "00000000" then
+ groups_off["not_in_creative_inventory"] = 1
+ end
+
+ mesecon.register_node("mesecons:wire_"..nodeid, {
+ description = "Mesecon",
+ drawtype = "nodebox",
+ inventory_image = "mesecons_wire_inv.png",
+ wield_image = "mesecons_wire_inv.png",
+ paramtype = "light",
+ paramtype2 = "facedir",
+ sunlight_propagates = true,
+ selection_box = selectionbox,
+ node_box = nodebox,
+ walkable = false,
+ drop = "mesecons:wire_00000000_off",
+ mesecon_wire = true
+ }, {tiles = tiles_off, mesecons = meseconspec_off, groups = groups_off},
+ {tiles = tiles_on, mesecons = meseconspec_on, groups = groups_on})
+
+ if (nid_inc(nid) == false) then return end
end
end
+register_wires()
-if not minetest.registered_nodes["default:stone_with_mese"] then --before MESE update, use old recipes
- minetest.register_craft({
- output = "mesecons:wire_00000000_off 18",
- recipe = {
- {"default:mese"},
- }
- })
-else
-
- minetest.register_craft({
- type = "cooking",
- output = "mesecons:wire_00000000_off 2",
- recipe = "default:mese_crystal_fragment",
- cooktime = 3,
- })
-
- minetest.register_craft({
- type = "cooking",
- output = "mesecons:wire_00000000_off 18",
- recipe = "default:mese_crystal",
- cooktime = 15,
- })
-
- minetest.register_craft({
- type = "cooking",
- output = "mesecons:wire_00000000_off 162",
- recipe = "default:mese",
- cooktime = 30,
- })
-
-end
+-- ##############
+-- ## Crafting ##
+-- ##############
+minetest.register_craft({
+ type = "cooking",
+ output = "mesecons:wire_00000000_off 2",
+ recipe = "default:mese_crystal_fragment",
+ cooktime = 3,
+})
minetest.register_craft({
type = "cooking",
- output = "mesecons:wire_00000000_off 16",
+ output = "mesecons:wire_00000000_off 18",
recipe = "default:mese_crystal",
+ cooktime = 15,
+})
+
+minetest.register_craft({
+ type = "cooking",
+ output = "mesecons:wire_00000000_off 162",
+ recipe = "default:mese",
+ cooktime = 30,
})
diff --git a/mesecons_extrawires/vertical.lua b/mesecons_extrawires/vertical.lua
index 16de55e..24e36e1 100644
--- a/mesecons_extrawires/vertical.lua
+++ b/mesecons_extrawires/vertical.lua
@@ -69,7 +69,7 @@ end
minetest.register_node("mesecons_extrawires:vertical_on", {
description = "Vertical mesecon",
drawtype = "nodebox",
- tiles = {"wires_vertical_on.png"},
+ tiles = {"mesecons_wire_on.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
@@ -91,7 +91,7 @@ minetest.register_node("mesecons_extrawires:vertical_on", {
minetest.register_node("mesecons_extrawires:vertical_off", {
description = "Vertical mesecon",
drawtype = "nodebox",
- tiles = {"wires_vertical_off.png"},
+ tiles = {"mesecons_wire_off.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
@@ -113,7 +113,7 @@ minetest.register_node("mesecons_extrawires:vertical_off", {
minetest.register_node("mesecons_extrawires:vertical_top_on", {
description = "Vertical mesecon",
drawtype = "nodebox",
- tiles = {"wires_full_on.png","wires_full_on.png","wires_vertical_on.png"},
+ tiles = {"mesecons_wire_on.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
@@ -135,7 +135,7 @@ minetest.register_node("mesecons_extrawires:vertical_top_on", {
minetest.register_node("mesecons_extrawires:vertical_top_off", {
description = "Vertical mesecon",
drawtype = "nodebox",
- tiles = {"wires_full_off.png","wires_full_off.png","wires_vertical_off.png"},
+ tiles = {"mesecons_wire_off.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
@@ -158,7 +158,7 @@ minetest.register_node("mesecons_extrawires:vertical_top_off", {
minetest.register_node("mesecons_extrawires:vertical_bottom_on", {
description = "Vertical mesecon",
drawtype = "nodebox",
- tiles = {"wires_full_on.png","wires_full_on.png","wires_vertical_on.png"},
+ tiles = {"mesecons_wire_on.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
@@ -179,7 +179,7 @@ minetest.register_node("mesecons_extrawires:vertical_bottom_on", {
minetest.register_node("mesecons_extrawires:vertical_bottom_off", {
description = "Vertical mesecon",
drawtype = "nodebox",
- tiles = {"wires_full_off.png","wires_full_off.png","wires_vertical_off.png"},
+ tiles = {"mesecons_wire_off.png"},
walkable = false,
paramtype = "light",
sunlight_propagates = true,
diff --git a/mesecons_insulated/init.lua b/mesecons_insulated/init.lua
index 9fdf494..26e3efb 100644
--- a/mesecons_insulated/init.lua
+++ b/mesecons_insulated/init.lua
@@ -41,7 +41,7 @@ minetest.register_node("mesecons_insulated:insulated_on", {
minetest.register_node("mesecons_insulated:insulated_off", {
drawtype = "nodebox",
- description = "insulated mesecons",
+ description = "Insulated Mesecon",
tiles = {
"jeija_insulated_wire_sides_off.png",
"jeija_insulated_wire_sides_off.png",
@@ -78,7 +78,3 @@ minetest.register_craft({
{"mesecons_materials:fiber", "mesecons_materials:fiber", "mesecons_materials:fiber"},
}
})
-
-mesecon:add_rules("insulated", {
-{x = 1, y = 0, z = 0},
-{x =-1, y = 0, z = 0}})
diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua
index 8c9f3b8..9883b85 100644
--- a/mesecons_microcontroller/init.lua
+++ b/mesecons_microcontroller/init.lua
@@ -1,5 +1,7 @@
EEPROM_SIZE = 255
+local microc_rules = {}
+
for a = 0, 1 do
for b = 0, 1 do
for c = 0, 1 do
@@ -34,7 +36,7 @@ if (a == 0) then table.insert(input_rules, {x = -1, y = 0, z = 0, name = "A"})
if (b == 0) then table.insert(input_rules, {x = 0, y = 0, z = 1, name = "B"}) end
if (c == 0) then table.insert(input_rules, {x = 1, y = 0, z = 0, name = "C"}) end
if (d == 0) then table.insert(input_rules, {x = 0, y = 0, z = -1, name = "D"}) end
-mesecon:add_rules(nodename, rules)
+microc_rules[nodename] = rules
local mesecons = {effector =
{
@@ -131,7 +133,7 @@ minetest.register_node(nodename, {
sounds = default.node_sound_stone_defaults(),
mesecons = mesecons,
after_dig_node = function (pos, node)
- rules = mesecon:get_rules(node.name)
+ rules = microc_rules[node.name]
mesecon:receptor_off(pos, rules)
end,
})
@@ -600,22 +602,22 @@ function yc_action_setports(pos, L, Lv)
local name = "mesecons_microcontroller:microcontroller"
local rules
if Lv.a ~= L.a then
- rules = mesecon:get_rules(name.."0001")
+ rules = microc_rules[name.."0001"]
if L.a == true then mesecon:receptor_on(pos, rules)
else mesecon:receptor_off(pos, rules) end
end
if Lv.b ~= L.b then
- rules = mesecon:get_rules(name.."0010")
+ rules = microc_rules[name.."0010"]
if L.b == true then mesecon:receptor_on(pos, rules)
else mesecon:receptor_off(pos, rules) end
end
if Lv.c ~= L.c then
- rules = mesecon:get_rules(name.."0100")
+ rules = microc_rules[name.."0100"]
if L.c == true then mesecon:receptor_on(pos, rules)
else mesecon:receptor_off(pos, rules) end
end
if Lv.d ~= L.d then
- rules = mesecon:get_rules(name.."1000")
+ rules = microc_rules[name.."1000"]
if L.d == true then mesecon:receptor_on(pos, rules)
else mesecon:receptor_off(pos, rules) end
end
diff --git a/mesecons_movestones/init.lua b/mesecons_movestones/init.lua
index e31f2d2..e8c52cb 100644
--- a/mesecons_movestones/init.lua
+++ b/mesecons_movestones/init.lua
@@ -67,7 +67,7 @@ minetest.register_node("mesecons_movestones:movestone", {
local direction=mesecon:get_movestone_direction(pos)
if not direction then return end
minetest.remove_node(pos)
- mesecon:update_autoconnect(pos)
+ mesecon.update_autoconnect(pos)
minetest.add_entity(pos, "mesecons_movestones:movestone_entity")
end
}}
@@ -146,7 +146,7 @@ minetest.register_node("mesecons_movestones:sticky_movestone", {
local direction=mesecon:get_movestone_direction(pos)
if not direction then return end
minetest.remove_node(pos)
- mesecon:update_autoconnect(pos)
+ mesecon.update_autoconnect(pos)
minetest.add_entity(pos, "mesecons_movestones:sticky_movestone_entity")
end
}}
diff --git a/mesecons_mvps/init.lua b/mesecons_mvps/init.lua
index 0079f1a..a9c0da8 100644
--- a/mesecons_mvps/init.lua
+++ b/mesecons_mvps/init.lua
@@ -42,9 +42,7 @@ end
function mesecon:mvps_process_stack(stack)
-- update mesecons for placed nodes ( has to be done after all nodes have been added )
for _, n in ipairs(stack) do
- nodeupdate(n.pos)
mesecon.on_placenode(n.pos, minetest.get_node(n.pos))
- mesecon:update_autoconnect(n.pos)
end
end
@@ -92,7 +90,6 @@ function mesecon:mvps_push(pos, dir, maximum) -- pos: pos of mvps; dir: directio
-- update mesecons for removed nodes ( has to be done after all nodes have been removed )
for _, n in ipairs(nodes) do
mesecon.on_dignode(n.pos, n.node)
- mesecon:update_autoconnect(n.pos)
end
-- add nodes
@@ -121,7 +118,7 @@ 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)
+ mesecon.update_autoconnect(n.pos)
end
end)
@@ -140,7 +137,7 @@ function mesecon:mvps_pull_single(pos, dir) -- pos: pos of mvps; direction: dire
nodeupdate(np)
nodeupdate(pos)
mesecon.on_dignode(np, nn)
- mesecon:update_autoconnect(np)
+ mesecon.update_autoconnect(np)
on_mvps_move({{pos = pos, oldpos = np, node = nn, meta = meta}})
end
return {{pos = np, node = {param2 = 0, name = "air"}}, {pos = pos, node = nn}}
@@ -188,7 +185,7 @@ function mesecon:mvps_pull_all(pos, direction) -- pos: pos of mvps; direction: d
and minetest.registered_nodes[lnode.name].liquidtype ~= "none")
minetest.remove_node(oldpos)
mesecon.on_dignode(oldpos, lnode2)
- mesecon:update_autoconnect(oldpos)
+ mesecon.update_autoconnect(oldpos)
on_mvps_move(moved_nodes)
end
diff --git a/mesecons_receiver/init.lua b/mesecons_receiver/init.lua
index 3b1108e..b368f24 100644
--- a/mesecons_receiver/init.lua
+++ b/mesecons_receiver/init.lua
@@ -81,16 +81,8 @@ minetest.register_node("mesecons_receiver:receiver_off", {
}}
})
-mesecon:add_rules("receiver_pos", {{x = 2, y = 0, z = 0}})
-
-mesecon:add_rules("receiver_pos_all", {
-{x = 2, y = 0, z = 0},
-{x =-2, y = 0, z = 0},
-{x = 0, y = 0, z = 2},
-{x = 0, y = 0, z =-2}})
-
function mesecon:receiver_get_pos_from_rcpt(pos, param2)
- local rules = mesecon:get_rules("receiver_pos")
+ local rules = {{x = 2, y = 0, z = 0}}
if param2 == nil then param2 = minetest.get_node(pos).param2 end
if param2 == 2 then
rules = mesecon:rotate_rules_left(rules)
@@ -119,7 +111,7 @@ function mesecon:receiver_place(rcpt_pos)
else
minetest.add_node(pos, {name = "mesecons_receiver:receiver_off", param2 = node.param2})
end
- mesecon:update_autoconnect(pos)
+ mesecon.update_autoconnect(pos)
end
end
@@ -130,7 +122,7 @@ function mesecon:receiver_remove(rcpt_pos, dugnode)
minetest.dig_node(pos)
local node = {name = "mesecons:wire_00000000_off"}
minetest.add_node(pos, node)
- mesecon:update_autoconnect(pos)
+ mesecon.update_autoconnect(pos)
mesecon.on_placenode(pos, node)
end
end
@@ -149,7 +141,10 @@ end)
minetest.register_on_placenode(function (pos, node)
if string.find(node.name, "mesecons:wire_") ~=nil then
- rules = mesecon:get_rules("receiver_pos_all")
+ 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}}
local i = 1
while rules[i] ~= nil do
np = {