summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md28
-rw-r--r--mesecons/init.lua47
-rw-r--r--mesecons/internal.lua109
-rw-r--r--mesecons/services.lua15
-rw-r--r--mesecons/settings.lua2
-rw-r--r--mesecons/wires.lua3
-rw-r--r--mesecons_extrawires/depends.txt1
-rw-r--r--mesecons_extrawires/vertical.lua32
-rw-r--r--mesecons_gates/init.lua6
-rw-r--r--mesecons_luacontroller/init.lua70
-rw-r--r--mesecons_microcontroller/init.lua21
-rw-r--r--mesecons_movestones/init.lua8
-rw-r--r--mesecons_mvps/init.lua43
-rw-r--r--mesecons_pistons/init.lua31
-rw-r--r--mesecons_pistons/sounds/piston_extend.oggbin0 -> 7060 bytes
-rw-r--r--mesecons_pistons/sounds/piston_retract.oggbin0 -> 7092 bytes
16 files changed, 310 insertions, 106 deletions
diff --git a/README.md b/README.md
index 37b6c22..32b4a12 100644
--- a/README.md
+++ b/README.md
@@ -51,19 +51,21 @@ Who wrote it anyways?
---------------------
These awesome people made Mesecons possible!
-| Contributor | Contribution |
-| --------------- | ---------------------------------- |
-| Jat15 | Various tweaks. |
-| Jeija | **Main developer! Everything.** |
-| Jordach | Noteblock sounds. |
-| khonkhortistan | Coding, recipes, textures. |
-| Kotolegokot | Nodeboxes for items. |
-| minerd247 | Textures. |
-| RealBadAngel | Fixes, improvements. |
-| sfan5 | Coding, recipes, textures. |
-| Uberi/Temperest | Coding, textures, documentation. |
-| VanessaE | Coding, recipes, textures, design. |
-| Whiskers75 | Logic gates implementation. |
+| Contributor | Contribution |
+| --------------- | -------------------------------- |
+| Jat15 | Various tweaks. |
+| Jeija | **Main developer! Everything.** |
+| Jordach | Noteblock sounds. |
+| khonkhortistan | Code, recipes, textures. |
+| Kotolegokot | Nodeboxes for items. |
+| minerd247 | Textures. |
+| Nore/Novatux | Code. |
+| RealBadAngel | Fixes, improvements. |
+| sfan5 | Code, recipes, textures. |
+| suzenako | Piston sounds. |
+| Uberi/Temperest | Code, textures, documentation. |
+| VanessaE | Code, recipes, textures, design. |
+| Whiskers75 | Logic gates implementation. |
There are also a whole bunch of other people helping with everything from code to testing and feedback. Mesecons would also not be possible without their help!
diff --git a/mesecons/init.lua b/mesecons/init.lua
index 587937a..612a823 100644
--- a/mesecons/init.lua
+++ b/mesecons/init.lua
@@ -49,6 +49,31 @@ mesecon.receptors={} -- saves all information about receptors | DEPRECATED
mesecon.effectors={} -- saves all information about effectors | DEPRECATED
mesecon.conductors={} -- saves all information about conductors | DEPRECATED
+
+local wpath = minetest.get_worldpath()
+local function read_file(fn)
+ local f = io.open(fn, "r")
+ if f==nil then return {} end
+ local t = f:read("*all")
+ f:close()
+ if t=="" or t==nil then return {} end
+ return minetest.deserialize(t)
+end
+
+local function write_file(fn, tbl)
+ local f = io.open(fn, "w")
+ f:write(minetest.serialize(tbl))
+ f:close()
+end
+
+mesecon.to_update = read_file(wpath.."/mesecon_to_update")
+mesecon.r_to_update = read_file(wpath.."/mesecon_r_to_update")
+
+minetest.register_on_shutdown(function()
+ write_file(wpath.."/mesecon_to_update",mesecon.to_update)
+ write_file(wpath.."/mesecon_r_to_update",mesecon.r_to_update)
+end)
+
-- Settings
dofile(minetest.get_modpath("mesecons").."/settings.lua")
@@ -76,7 +101,7 @@ dofile(minetest.get_modpath("mesecons").."/legacy.lua");
-- API
-- these are the only functions you need to remember
-function mesecon:receptor_on(pos, rules)
+function mesecon:receptor_on_i(pos, rules)
rules = rules or mesecon.rules.default
for _, rule in ipairs(mesecon:flattenrules(rules)) do
@@ -88,7 +113,16 @@ function mesecon:receptor_on(pos, rules)
end
end
-function mesecon:receptor_off(pos, rules)
+function mesecon:receptor_on(pos, rules)
+ if MESECONS_GLOBALSTEP then
+ rules = rules or mesecon.rules.default
+ mesecon.r_to_update[#mesecon.r_to_update+1]={pos=pos, rules=rules, action="on"}
+ else
+ mesecon:receptor_on_i(pos, rules)
+ end
+end
+
+function mesecon:receptor_off_i(pos, rules)
rules = rules or mesecon.rules.default
for _, rule in ipairs(mesecon:flattenrules(rules)) do
@@ -104,6 +138,15 @@ function mesecon:receptor_off(pos, rules)
end
end
+function mesecon:receptor_off(pos, rules)
+ if MESECONS_GLOBALSTEP then
+ rules = rules or mesecon.rules.default
+ mesecon.r_to_update[#mesecon.r_to_update+1]={pos=pos, rules=rules, action="off"}
+ else
+ mesecon:receptor_off_i(pos, rules)
+ end
+end
+
print("[OK] Mesecons")
diff --git a/mesecons/internal.lua b/mesecons/internal.lua
index 8ab0bf6..ad0fef1 100644
--- a/mesecons/internal.lua
+++ b/mesecons/internal.lua
@@ -180,24 +180,115 @@ end
--Signals
function mesecon:activate(pos, node, rulename)
- local effector = mesecon:get_effector(node.name)
- if effector and effector.action_on then
- effector.action_on (pos, node, rulename)
+ if MESECONS_GLOBALSTEP then
+ if rulename == nil then
+ for _,rule in ipairs(mesecon:effector_get_rules(node)) do
+ mesecon:activate(pos, node, rule)
+ end
+ return
+ end
+ add_action(pos, "on", rulename)
+ else
+ local effector = mesecon:get_effector(node.name)
+ if effector and effector.action_on then
+ effector.action_on (pos, node, rulename)
+ end
end
end
function mesecon:deactivate(pos, node, rulename)
- local effector = mesecon:get_effector(node.name)
- if effector and effector.action_off then
- effector.action_off (pos, node, rulename)
+ if MESECONS_GLOBALSTEP then
+ if rulename == nil then
+ for _,rule in ipairs(mesecon:effector_get_rules(node)) do
+ mesecon:deactivate(pos, node, rule)
+ end
+ return
+ end
+ add_action(pos, "off", rulename)
+ else
+ local effector = mesecon:get_effector(node.name)
+ if effector and effector.action_off then
+ effector.action_off (pos, node, rulename)
+ end
end
end
function mesecon:changesignal(pos, node, rulename, newstate)
- local effector = mesecon:get_effector(node.name)
- if effector and effector.action_change then
- effector.action_change (pos, node, rulename, newstate)
+
+ newstate = newstate or "on"
+ --rulename = rulename or mesecon.rules.default
+ if MESECONS_GLOBALSTEP then
+ if rulename == nil then
+ for _,rule in ipairs(mesecon:effector_get_rules(node)) do
+ mesecon:changesignal(pos, node, rule, newstate)
+ end
+ return
+ end
+ add_action(pos, "c"..newstate, rulename)
+ else
+ local effector = mesecon:get_effector(node.name)
+ if effector and effector.action_change then
+ effector.action_change (pos, node, rulename, newstate)
+ end
+ end
+end
+
+function execute_actions(dtime)
+ local nactions = mesecon.to_update
+ mesecon.to_update = {}
+ for _,i in ipairs(nactions) do
+ node = minetest.env:get_node(i.pos)
+ if node.name=="ignore" then
+ add_action(i.pos, i.action, i.rname)
+ else
+ effector = mesecon:get_effector(node.name)
+ if i.action == "on" then
+ if effector and effector.action_on then
+ effector.action_on(i.pos, node, i.rname)
+ end
+ elseif i.action == "off" then
+ if effector and effector.action_off then
+ effector.action_off(i.pos, node, i.rname)
+ end
+ elseif i.action == "con" then
+ if effector and effector.action_change then
+ effector.action_change(i.pos, node, i.rname, "on")
+ end
+ elseif i.action == "coff" then
+ if effector and effector.action_change then
+ effector.action_change(i.pos, node, i.rname, "off")
+ end
+ end
+ end
+ end
+ local nactions = mesecon.r_to_update
+ mesecon.r_to_update = {}
+ for _,i in ipairs(nactions) do
+ if i.action == "on" then
+ mesecon:receptor_on_i(i.pos, i.rules)
+ else
+ mesecon:receptor_off_i(i.pos,i.rules)
+ end
+ end
+end
+
+minetest.register_globalstep(execute_actions)
+
+function add_action(pos, action, rname)
+ for _,i in ipairs(mesecon.to_update) do
+ if i.pos.x == pos.x and i.pos.y == pos.y and i.pos.z == pos.z and i.rname.x == rname.x and i.rname.y == rname.y and i.rname.z == rname.z then
+ if (i.action == "on" and action == "on") or (i.action == "off" and action == "off") then
+ --nothing
+ elseif i.action == "coff" and action == "on" then i.action = "on"
+ elseif i.action == "con" and action == "off" then i.action = "off"
+ else
+ if action == "on" or action == "con" then i.action = "con" end
+ if action == "off" or action == "coff" then i.action = "coff" end
+ end
+ break
+ end
end
+ mesecon.to_update[#mesecon.to_update+1] = {pos = pos, action = action, rname = rname}
end
--Rules
diff --git a/mesecons/services.lua b/mesecons/services.lua
index 4260a2e..a47b5ec 100644
--- a/mesecons/services.lua
+++ b/mesecons/services.lua
@@ -1,5 +1,4 @@
-mesecon.on_placenode = function (pos)
- local node = minetest.env:get_node(pos)
+mesecon.on_placenode = function (pos, node)
if mesecon:is_receptor_on(node.name) then
mesecon:receptor_on(pos, mesecon:receptor_get_rules(node))
elseif mesecon:is_powered(pos) then
@@ -7,7 +6,7 @@ mesecon.on_placenode = function (pos)
mesecon:turnon (pos)
--mesecon:receptor_on (pos, mesecon:conductor_get_rules(node))
else
- mesecon:changesignal(pos, node)
+ mesecon:changesignal(pos, node, mesecon:effector_get_rules(node), "on")
mesecon:activate(pos, node)
end
elseif mesecon:is_conductor_on(node.name) then
@@ -25,5 +24,15 @@ mesecon.on_dignode = function (pos, node)
end
end
+minetest.register_abm({
+ nodenames = {"group:overheat"},
+ interval = 1.0,
+ chance = 1,
+ action = function(pos, node, active_object_count, active_object_count_wider)
+ local meta = minetest.env:get_meta(pos)
+ meta:set_int("heat",0)
+ end,
+})
+
minetest.register_on_placenode(mesecon.on_placenode)
minetest.register_on_dignode(mesecon.on_dignode)
diff --git a/mesecons/settings.lua b/mesecons/settings.lua
index eaed9de..e35bb1e 100644
--- a/mesecons/settings.lua
+++ b/mesecons/settings.lua
@@ -5,3 +5,5 @@ PRESSURE_PLATE_INTERVAL = 0.1
OBJECT_DETECTOR_RADIUS = 6
PISTON_MAXIMUM_PUSH = 15
MOVESTONE_MAXIMUM_PUSH = 100
+MESECONS_GLOBALSTEP = true -- true = receptors/effectors won't be updated
+ -- until next globalstep, decreases server load
diff --git a/mesecons/wires.lua b/mesecons/wires.lua
index 50052b5..88199e7 100644
--- a/mesecons/wires.lua
+++ b/mesecons/wires.lua
@@ -241,8 +241,7 @@ function mesecon:update_autoconnect(pos, secondcall, replace_old)
end
end
-if minetest.registered_nodes["default:stone_with_mese"] == nil then
-
+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 = {
diff --git a/mesecons_extrawires/depends.txt b/mesecons_extrawires/depends.txt
index acaa924..aca967d 100644
--- a/mesecons_extrawires/depends.txt
+++ b/mesecons_extrawires/depends.txt
@@ -1 +1,2 @@
+default
mesecons
diff --git a/mesecons_extrawires/vertical.lua b/mesecons_extrawires/vertical.lua
index 39b5417..3274c1a 100644
--- a/mesecons_extrawires/vertical.lua
+++ b/mesecons_extrawires/vertical.lua
@@ -34,31 +34,23 @@ local brules =
local vertical_updatepos = function (pos)
local node = minetest.env:get_node(pos)
- if minetest.registered_nodes[node.name].is_vertical_conductor then
+ if minetest.registered_nodes[node.name]
+ and minetest.registered_nodes[node.name].is_vertical_conductor then
local node_above = minetest.env:get_node(mesecon:addPosRule(pos, vrules[1]))
local node_below = minetest.env:get_node(mesecon:addPosRule(pos, vrules[2]))
local namestate = minetest.registered_nodes[node.name].vertical_conductor_state
- -- above and below: vertical mesecon
- if minetest.registered_nodes[node_above.name].is_vertical_conductor
- and minetest.registered_nodes[node_below.name].is_vertical_conductor then
- minetest.env:add_node (pos,
- {name = "mesecons_extrawires:vertical_"..namestate})
-
- -- above only: bottom
- elseif minetest.registered_nodes[node_above.name].is_vertical_conductor
- and not minetest.registered_nodes[node_below.name].is_vertical_conductor then
- minetest.env:add_node (pos,
- {name = "mesecons_extrawires:vertical_bottom_"..namestate})
-
- -- below only: top
- elseif not minetest.registered_nodes[node_above.name].is_vertical_conductor
- and minetest.registered_nodes[node_below.name].is_vertical_conductor then
- minetest.env:add_node (pos,
- {name = "mesecons_extrawires:vertical_top_"..namestate})
+ local above = minetest.registered_nodes[node_above.name] and minetest.registered_nodes[node_above.name].is_vertical_conductor
+ local below = minetest.registered_nodes[node_below.name] and minetest.registered_nodes[node_below.name].is_vertical_conductor
+
+ if above and below then -- above and below: vertical mesecon
+ minetest.env:add_node(pos, {name = "mesecons_extrawires:vertical_"..namestate})
+ elseif above and not below then -- above only: bottom
+ minetest.env:add_node(pos, {name = "mesecons_extrawires:vertical_bottom_"..namestate})
+ elseif not above and below then -- below only: top
+ minetest.env:add_node(pos, {name = "mesecons_extrawires:vertical_top_"..namestate})
else -- no vertical wire above, no vertical wire below: use default wire
- minetest.env:add_node (pos,
- {name = "mesecons_extrawires:vertical_"..namestate})
+ minetest.env:add_node (pos, {name = "mesecons_extrawires:vertical_"..namestate})
end
end
end
diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua
index 162c7d8..37b046f 100644
--- a/mesecons_gates/init.lua
+++ b/mesecons_gates/init.lua
@@ -47,7 +47,7 @@ function set_gate(pos, on)
local meta = minetest.env:get_meta(pos)
if on ~= gate_state(pos) then
yc_heat(meta)
- minetest.after(0.5, yc_cool, meta)
+ --minetest.after(0.5, yc_cool, meta)
if yc_overheat(meta) then
pop_gate(pos)
else
@@ -112,13 +112,13 @@ for _, gate in ipairs(gates) do
drop = nodename.."_off"
nodename = nodename.."_"..onoff
description = "You hacker you!"
- groups = {dig_immediate=2, not_in_creative_inventory=1}
+ groups = {dig_immediate=2, not_in_creative_inventory=1, overheat = 1}
else
onoff = "off"
drop = nil
nodename = nodename.."_"..onoff
description = gate.name.." Gate"
- groups = {dig_immediate=2}
+ groups = {dig_immediate=2, overheat = 1}
end
tiles = "jeija_microcontroller_bottom.png^"..
diff --git a/mesecons_luacontroller/init.lua b/mesecons_luacontroller/init.lua
index 3016014..0884244 100644
--- a/mesecons_luacontroller/init.lua
+++ b/mesecons_luacontroller/init.lua
@@ -100,17 +100,17 @@ local heat = function (meta) -- warm up
end
end
-local cool = function (meta) -- cool down after a while
- h = meta:get_int("heat")
- if h ~= nil then
- meta:set_int("heat", h - 1)
- end
-end
+--local cool = function (meta) -- cool down after a while
+-- h = meta:get_int("heat")
+-- if h ~= nil then
+-- meta:set_int("heat", h - 1)
+-- end
+--end
local overheat = function (meta) -- determine if too hot
h = meta:get_int("heat")
if h == nil then return true end -- if nil then overheat
- if h > 20 then
+ if h > 40 then
return true
else
return false
@@ -127,7 +127,7 @@ end
local code_prohibited = function(code)
-- Clean code
- local prohibited = {"while", "for", "repeat", "until", "function"}
+ local prohibited = {"while", "for", "repeat", "until", "function", "goto"}
for _, p in ipairs(prohibited) do
if string.find(code, p) then
return "Prohibited command: "..p
@@ -135,10 +135,34 @@ local code_prohibited = function(code)
end
end
-local safeprint = function(param)
+local safe_print = function(param)
print(dump(param))
end
+deep_copy = function(original, visited) --deep copy that removes functions
+ visited = visited or {}
+ if visited[original] ~= nil then --already visited this node
+ return visited[original]
+ end
+ if type(original) == 'table' then --nested table
+ local copy = {}
+ visited[original] = copy
+ for key, value in next, original, nil do
+ copy[deep_copy(key, visited)] = deep_copy(value, visited)
+ end
+ setmetatable(copy, deep_copy(getmetatable(original), visited))
+ return copy
+ elseif type(original) == 'function' then --ignore functions
+ return nil
+ else --by-value type
+ return original
+ end
+end
+
+local safe_serialize = function(value)
+ return minetest.serialize(deep_copy(value))
+end
+
local interrupt = function(params)
lc_update(params.pos, {type="interrupt", iid = params.iid})
end
@@ -150,15 +174,16 @@ local getinterrupt = function(pos)
local meta = minetest.env:get_meta(pos)
local interrupts = minetest.deserialize(meta:get_string("lc_interrupts")) or {}
local found = false
+ local search = safe_serialize(iid)
for _, i in ipairs(interrupts) do
- if minetest.serialize(i) == minetest.serialize(iid) then
+ if safe_serialize(i) == search then
found = true
break
end
end
if not found then
table.insert(interrupts, iid)
- meta:set_string("lc_interrupts", minetest.serialize(interrupts))
+ meta:set_string("lc_interrupts", safe_serialize(interrupts))
end
minetest.after(time, interrupt, {pos=pos, iid = iid})
end
@@ -181,7 +206,7 @@ local create_environment = function(pos, mem, event)
local rports = get_real_portstates(pos)
return {
- print = safeprint,
+ print = safe_print,
pin = merge_portstates(vports, rports),
port = vports,
interrupt = getinterrupt(pos),
@@ -258,7 +283,7 @@ end
local do_overheat = function (pos, meta)
-- Overheat protection
heat(meta)
- minetest.after(0.5, cool, meta)
+ --minetest.after(0.5, cool, meta)
if overheat(meta) then
mesecon:swap_node(pos, BASENAME.."_burnt")
minetest.env:get_meta(pos):set_string("lc_interrupts", "")
@@ -272,15 +297,16 @@ local load_memory = function(meta)
end
local save_memory = function(meta, mem)
- meta:set_string("lc_memory", minetest.serialize(mem))
+ meta:set_string("lc_memory", safe_serialize(mem))
end
local interrupt_allow = function (meta, event)
if event.type ~= "interrupt" then return true end
local interrupts = minetest.deserialize(meta:get_string("lc_interrupts")) or {}
+ local search = safe_serialize(event.iid)
for _, i in ipairs(interrupts) do
- if minetest.serialize(i) == minetest.serialize(event.iid) then
+ if safe_serialize(i) == search then
return true
end
end
@@ -354,10 +380,12 @@ end
-- ______
-- |
--- | | |
--- |___| | __ ___ _ __ _ _
--- | | | | |\ | | |_| | | | | |_ |_|
--- | |______ |__| | \| | | \ |__| |_ |_ |_ |\
+-- |
+-- | __ ___ _ __ _ _
+-- | | | | | |\ | | |_| | | | | |_ |_|
+-- |___| |______ |__| | \| | | \ |__| |_ |_ |_ |\
+-- |
+-- |
--
-----------------------
@@ -412,9 +440,9 @@ if d == 1 then
end
if a + b + c + d ~= 0 then
- groups = {dig_immediate=2, not_in_creative_inventory=1}
+ groups = {dig_immediate=2, not_in_creative_inventory=1, overheat = 1}
else
- groups = {dig_immediate=2}
+ groups = {dig_immediate=2, overheat = 1}
end
output_rules[cid] = {}
diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua
index 99ccb8a..e61c2a0 100644
--- a/mesecons_microcontroller/init.lua
+++ b/mesecons_microcontroller/init.lua
@@ -19,9 +19,9 @@ if tostring(d) == "1" then
top = top.."^jeija_microcontroller_LED_D.png"
end
if tostring(d)..tostring(c)..tostring(b)..tostring(a) ~= "0000" then
- groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3}
+ groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3, overheat = 1}
else
- groups = {dig_immediate=2, mesecon = 3}
+ groups = {dig_immediate=2, mesecon = 3, overheat = 1}
end
local rules={}
if (a == 1) then table.insert(rules, {x = -1, y = 0, z = 0}) end
@@ -162,7 +162,7 @@ end
function update_yc(pos)
local meta = minetest.env:get_meta(pos)
yc_heat(meta)
- minetest.after(0.5, yc_cool, meta)
+ --minetest.after(0.5, yc_cool, meta)
if (yc_overheat(meta)) then
minetest.env:remove_node(pos)
minetest.after(0.2, yc_overheat_off, pos) --wait for pending parsings
@@ -682,17 +682,18 @@ function yc_heat(meta)
end
end
-function yc_cool(meta)
- h = meta:get_int("heat")
- if h ~= nil then
- meta:set_int("heat", h - 1)
- end
-end
+--function yc_cool(meta)
+-- h = meta:get_int("heat")
+-- if h ~= nil then
+-- meta:set_int("heat", h - 1)
+-- end
+--end
function yc_overheat(meta)
+ if MESECONS_GLOBALSTEP then return false end
h = meta:get_int("heat")
if h == nil then return true end -- if nil the overheat
- if h>30 then
+ if h>60 then
return true
else
return false
diff --git a/mesecons_movestones/init.lua b/mesecons_movestones/init.lua
index 14d828b..4bf6dc5 100644
--- a/mesecons_movestones/init.lua
+++ b/mesecons_movestones/init.lua
@@ -92,9 +92,11 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
local direction = mesecon:get_movestone_direction(pos)
if not direction then -- no mesecon power
+ --push only solid nodes
local name = minetest.env:get_node(pos).name
if name ~= "air" and name ~= "ignore"
- and minetest.registered_nodes[name].liquidtype == "none" then
+ and ((not minetest.registered_nodes[name])
+ or minetest.registered_nodes[name].liquidtype == "none") then
mesecon:mvps_push(pos, self.lastdir, MOVESTONE_MAXIMUM_PUSH)
end
minetest.env:add_node(pos, {name="mesecons_movestones:movestone"})
@@ -176,9 +178,11 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
local direction = mesecon:get_movestone_direction(pos)
if not direction then -- no mesecon power
+ --push only solid nodes
local name = minetest.env:get_node(pos).name
if name ~= "air" and name ~= "ignore"
- and minetest.registered_nodes[name].liquidtype == "none" then
+ and ((not minetest.registered_nodes[name])
+ or minetest.registered_nodes[name].liquidtype == "none") then
mesecon:mvps_push(pos, self.lastdir, MOVESTONE_MAXIMUM_PUSH)
--STICKY
mesecon:mvps_pull_all(pos, self.lastdir)
diff --git a/mesecons_mvps/init.lua b/mesecons_mvps/init.lua
index 91fb345..c572cb3 100644
--- a/mesecons_mvps/init.lua
+++ b/mesecons_mvps/init.lua
@@ -48,7 +48,8 @@ function mesecon:mvps_get_stack(pos, dir, maximum)
end
if nn.name == "air"
- or minetest.registered_nodes[nn.name].liquidtype ~= "none" then --is liquid
+ or (minetest.registered_nodes[nn.name]
+ and minetest.registered_nodes[nn.name].liquidtype ~= "none") then --is liquid
break
end
@@ -106,8 +107,9 @@ function mesecon:mvps_pull_single(pos, dir) -- pos: pos of mvps; direction: dire
np = mesecon:addPosRule(pos, dir)
nn = minetest.env:get_node(np)
- if minetest.registered_nodes[nn.name].liquidtype == "none"
- and not mesecon:is_mvps_stopper(nn, {x = -dir.x, y = -dir.y, z = -dir.z}, {{pos = np, node = nn}}, 1) then
+ if ((not minetest.registered_nodes[nn.name]) --unregistered node
+ or minetest.registered_nodes[nn.name].liquidtype == "none") --non-liquid node
+ and not mesecon:is_mvps_stopper(nn, {x = -dir.x, y = -dir.y, z = -dir.z}, {{pos = np, node = nn}}, 1) then --non-stopper node
local meta = minetest.env:get_meta(np):to_table()
minetest.env:remove_node(np)
minetest.env:add_node(pos, nn)
@@ -129,10 +131,23 @@ function mesecon:mvps_pull_all(pos, direction) -- pos: pos of mvps; direction: d
local lpos2 = {x=pos.x-direction.x*2, y=pos.y-direction.y*2, z=pos.z-direction.z*2} -- 2 away
local lnode2 = minetest.env:get_node(lpos2)
- if lnode.name ~= "ignore" and lnode.name ~= "air" and minetest.registered_nodes[lnode.name].liquidtype == "none" then return end
- if lnode2.name == "ignore" or lnode2.name == "air" or not(minetest.registered_nodes[lnode2.name].liquidtype == "none") then return end
+ --avoid pulling solid nodes
+ if lnode.name ~= "ignore"
+ and lnode.name ~= "air"
+ and ((not minetest.registered_nodes[lnode.name])
+ or minetest.registered_nodes[lnode.name].liquidtype == "none") then
+ return
+ end
+
+ --avoid pulling empty or liquid nodes
+ if lnode2.name == "ignore"
+ or lnode2.name == "air"
+ or (minetest.registered_nodes[lnode2.name]
+ and minetest.registered_nodes[lnode2.name].liquidtype ~= "none") then
+ return
+ end
- local oldpos = {x=lpos2.x+direction.x, y=lpos2.y+direction.y, z=lpos2.z+direction.z}
+ local oldpos = {x=lpos2.x + direction.x, y=lpos2.y + direction.y, z=lpos2.z + direction.z}
repeat
lnode2 = minetest.env:get_node(lpos2)
minetest.env:add_node(oldpos, {name=lnode2.name})
@@ -142,7 +157,10 @@ function mesecon:mvps_pull_all(pos, direction) -- pos: pos of mvps; direction: d
lpos2.y = lpos2.y-direction.y
lpos2.z = lpos2.z-direction.z
lnode = minetest.env:get_node(lpos2)
- until lnode.name=="air" or lnode.name=="ignore" or not(minetest.registered_nodes[lnode2.name].liquidtype == "none")
+ until lnode.name == "air"
+ or lnode.name == "ignore"
+ or (minetest.registered_nodes[lnode2.name]
+ and minetest.registered_nodes[lnode2.name].liquidtype ~= "none")
minetest.env:remove_node(oldpos)
end
@@ -151,9 +169,9 @@ function mesecon:mvps_move_objects(pos, dir, nodestack)
-- Move object at tip of stack
local pushpos = mesecon:addPosRule(pos, -- get pos at tip of stack
- {x = dir.x * (#nodestack),
- y = dir.y * (#nodestack),
- z = dir.z * (#nodestack)})
+ {x = dir.x * #nodestack,
+ y = dir.y * #nodestack,
+ z = dir.z * #nodestack})
local objects = minetest.env:get_objects_inside_radius(pushpos, 1)
@@ -177,8 +195,11 @@ function mesecon:mvps_move_objects(pos, dir, nodestack)
local entity = obj:get_luaentity()
if not entity or not mesecon:is_mvps_unmov(entity.name) then
local np = mesecon:addPosRule(obj:getpos(), dir)
+
+ --move only if destination is not solid
local nn = minetest.env:get_node(np)
- if not minetest.registered_nodes[nn.name].walkable then
+ if not ((not minetest.registered_nodes[nn.name])
+ or minetest.registered_nodes[nn.name].walkable) then
obj:setpos(np)
end
end
diff --git a/mesecons_pistons/init.lua b/mesecons_pistons/init.lua
index 26f2040..1284eb7 100644
--- a/mesecons_pistons/init.lua
+++ b/mesecons_pistons/init.lua
@@ -46,7 +46,7 @@ piston_facedir_direction = function (node)
return rules[1]
end
-piston_get_direction = function (dir, node)
+piston_get_direction = function(dir, node)
if type(dir) == "function" then
return dir(node)
else
@@ -54,20 +54,26 @@ piston_get_direction = function (dir, node)
end
end
-local piston_remove_pusher = function (pos, node)
+local piston_remove_pusher = function(pos, node)
pistonspec = minetest.registered_nodes[node.name].mesecons_piston
+ if pushername == pistonspec.pusher then --make sure there actually is a pusher (for compatibility reasons mainly)
+ return
+ end
dir = piston_get_direction(pistonspec.dir, node)
local pusherpos = mesecon:addPosRule(pos, dir)
local pushername = minetest.env:get_node(pusherpos).name
- if pushername == pistonspec.pusher then --make sure there actually is a pusher (for compatibility reasons mainly)
- minetest.env:remove_node(pusherpos)
- nodeupdate(pusherpos)
- end
+ minetest.env:remove_node(pusherpos)
+ minetest.sound_play("piston_retract", {
+ pos = pos,
+ max_hear_distance = 20,
+ gain = 0.3,
+ })
+ nodeupdate(pusherpos)
end
-local piston_on = function (pos, node)
+local piston_on = function(pos, node)
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
local dir = piston_get_direction(pistonspec.dir, node)
@@ -76,15 +82,20 @@ local piston_on = function (pos, node)
if success then
minetest.env:add_node(pos, {param2 = node.param2, name = pistonspec.onname})
minetest.env:add_node(np, {param2 = node.param2, name = pistonspec.pusher})
+ minetest.sound_play("piston_extend", {
+ pos = pos,
+ max_hear_distance = 20,
+ gain = 0.3,
+ })
mesecon:mvps_process_stack (stack)
mesecon:mvps_move_objects (np, dir, oldstack)
end
end
-local piston_off = function (pos, node)
+local piston_off = function(pos, node)
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
minetest.env:add_node(pos, {param2 = node.param2, name = pistonspec.offname})
- piston_remove_pusher (pos, node)
+ piston_remove_pusher(pos, node)
if pistonspec.sticky then
dir = piston_get_direction(pistonspec.dir, node)
@@ -94,7 +105,7 @@ local piston_off = function (pos, node)
end
end
-local piston_orientate = function (pos, placer)
+local piston_orientate = function(pos, placer)
-- not placed by player
if not placer then return end
diff --git a/mesecons_pistons/sounds/piston_extend.ogg b/mesecons_pistons/sounds/piston_extend.ogg
new file mode 100644
index 0000000..e234ad9
--- /dev/null
+++ b/mesecons_pistons/sounds/piston_extend.ogg
Binary files differ
diff --git a/mesecons_pistons/sounds/piston_retract.ogg b/mesecons_pistons/sounds/piston_retract.ogg
new file mode 100644
index 0000000..feb9f04
--- /dev/null
+++ b/mesecons_pistons/sounds/piston_retract.ogg
Binary files differ