Make sticky piston stick falling things as well (#436)

This commit is contained in:
Vitaliy 2018-12-21 22:02:57 +03:00 committed by GitHub
parent 9d239cbfff
commit 6e767a6c76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -55,7 +55,7 @@ local function piston_get_rules(node)
return rules return rules
end end
local function piston_remove_pusher(pos, node) local function piston_remove_pusher(pos, node, check_falling)
local pistonspec = get_pistonspec(node.name, "onname") local pistonspec = get_pistonspec(node.name, "onname")
local dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1) local dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1)
local pusherpos = vector.add(pos, dir) local pusherpos = vector.add(pos, dir)
@ -72,8 +72,15 @@ local function piston_remove_pusher(pos, node)
max_hear_distance = 20, max_hear_distance = 20,
gain = 0.3, gain = 0.3,
}) })
if check_falling then
minetest.check_for_falling(pusherpos) minetest.check_for_falling(pusherpos)
end end
end
local function piston_after_dig(pos, node)
piston_remove_pusher(pos, node, true)
end
local piston_on = function(pos, node) local piston_on = function(pos, node)
local pistonspec = get_pistonspec(node.name, "offname") local pistonspec = get_pistonspec(node.name, "offname")
@ -97,7 +104,7 @@ end
local function piston_off(pos, node) local function piston_off(pos, node)
local pistonspec = get_pistonspec(node.name, "onname") local pistonspec = get_pistonspec(node.name, "onname")
minetest.set_node(pos, {param2 = node.param2, name = pistonspec.offname}) minetest.set_node(pos, {param2 = node.param2, name = pistonspec.offname})
piston_remove_pusher(pos, node) piston_remove_pusher(pos, node, not pistonspec.sticky)
if not pistonspec.sticky then if not pistonspec.sticky then
return return
@ -293,7 +300,7 @@ minetest.register_node("mesecons_pistons:piston_normal_on", {
paramtype2 = "facedir", paramtype2 = "facedir",
is_ground_content = false, is_ground_content = false,
drop = "mesecons_pistons:piston_normal_off", drop = "mesecons_pistons:piston_normal_off",
after_dig_node = piston_remove_pusher, after_dig_node = piston_after_dig,
node_box = piston_on_box, node_box = piston_on_box,
selection_box = piston_on_box, selection_box = piston_on_box,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
@ -371,7 +378,7 @@ minetest.register_node("mesecons_pistons:piston_sticky_on", {
paramtype2 = "facedir", paramtype2 = "facedir",
is_ground_content = false, is_ground_content = false,
drop = "mesecons_pistons:piston_sticky_off", drop = "mesecons_pistons:piston_sticky_off",
after_dig_node = piston_remove_pusher, after_dig_node = piston_after_dig,
node_box = piston_on_box, node_box = piston_on_box,
selection_box = piston_on_box, selection_box = piston_on_box,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),