This commit is contained in:
Vitaliy 2024-01-04 02:13:25 -08:00 committed by GitHub
commit 722f820946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 5 deletions

View File

@ -80,8 +80,11 @@ local function piston_after_dig(pos, node)
piston_remove_pusher(pos, node, true)
end
local piston_on = function(pos, node)
local function piston_on(pos, node)
local pistonspec = get_pistonspec(node.name, "offname")
if not pistonspec then -- it may be called asynchronously now, dont crash if something goes wrong
return
end
local dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1)
local pusher_pos = vector.add(pos, dir)
local meta = minetest.get_meta(pos)
@ -100,6 +103,9 @@ end
local function piston_off(pos, node)
local pistonspec = get_pistonspec(node.name, "onname")
if not pistonspec then
return
end
minetest.swap_node(pos, {param2 = node.param2, name = pistonspec.offname})
piston_remove_pusher(pos, node, not pistonspec.sticky) -- allow that even in protected area
@ -115,6 +121,29 @@ local function piston_off(pos, node)
end
end
-- not on/off as power state may change faster than the piston state
mesecon.queue:add_function("piston_switch", function(pos)
local node = mesecon.get_node_force(pos)
if mesecon.is_powered(pos) then
piston_on(pos, node)
else
piston_off(pos, node)
end
end)
local piston_on_delayed, piston_off_delayed
local delay = mesecon.setting("piston_delay", 0.15)
if delay >= 0 then
local function piston_switch_delayed(pos, node)
mesecon.queue:add_action(pos, "piston_switch", {}, delay, "piston_switch")
end
piston_on_delayed = piston_switch_delayed
piston_off_delayed = piston_switch_delayed
else
piston_on_delayed = piston_on
piston_off_delayed = piston_off
end
local orientations = {
[0] = { 4, 8},
{13, 17},
@ -282,7 +311,7 @@ minetest.register_node("mesecons_pistons:piston_normal_off", {
after_place_node = piston_orientate,
sounds = mesecon.node_sound.wood,
mesecons = {effector={
action_on = piston_on,
action_on = piston_on_delayed,
rules = piston_get_rules,
}},
on_punch = piston_punch,
@ -312,7 +341,7 @@ minetest.register_node("mesecons_pistons:piston_normal_on", {
selection_box = piston_on_box,
sounds = mesecon.node_sound.wood,
mesecons = {effector={
action_off = piston_off,
action_off = piston_off_delayed,
rules = piston_get_rules,
}},
on_rotate = piston_rotate_on,
@ -361,7 +390,7 @@ minetest.register_node("mesecons_pistons:piston_sticky_off", {
after_place_node = piston_orientate,
sounds = mesecon.node_sound.wood,
mesecons = {effector={
action_on = piston_on,
action_on = piston_on_delayed,
rules = piston_get_rules,
}},
on_punch = piston_punch,
@ -391,7 +420,7 @@ minetest.register_node("mesecons_pistons:piston_sticky_on", {
selection_box = piston_on_box,
sounds = mesecon.node_sound.wood,
mesecons = {effector={
action_off = piston_off,
action_off = piston_off_delayed,
rules = piston_get_rules,
}},
on_rotate = piston_rotate_on,

View File

@ -56,6 +56,11 @@ mesecon.movestone_max_pull (Max pull) int 50 1 100
mesecon.piston_max_push (Max push) int 15 1 100
mesecon.piston_max_pull (Max pull) int 15 1 100
# Delay between piston power on/off and actual push/pull.
# Zero means minimal possible delay. Negative value means
# synchronous action (old behavior).
mesecon.piston_delay (Delay) float 0.15 -1 3.0
[mesecons_pressureplates]