1
0
Fork 0

Update trapdoor climbable behavior

This commit is contained in:
Dehydrate6684 2023-09-16 13:16:49 +08:00
parent b4c693bb20
commit a960bf2e8e
Signed by untrusted user: Dehydrate6684
GPG Key ID: 5926A2FA9B7653EF
2 changed files with 93 additions and 5 deletions

View File

@ -33,7 +33,14 @@ minetest.register_node("mcl_core:ladder", {
wall_side = { -0.5, -0.5, -0.5, -7/16, 0.5, 0.5 }, wall_side = { -0.5, -0.5, -0.5, -7/16, 0.5, 0.5 },
}, },
stack_max = 64, stack_max = 64,
groups = {handy=1,axey=1, attached_node=1, deco_block=1, dig_by_piston=1}, groups = {
handy = 1,
axey = 1,
attached_node = 1,
deco_block = 1,
dig_by_piston = 1,
ladder = 1
},
sounds = mcl_sounds.node_sound_wood_defaults(), sounds = mcl_sounds.node_sound_wood_defaults(),
node_placement_prediction = "", node_placement_prediction = "",
-- Restrict placement of ladders -- Restrict placement of ladders
@ -80,7 +87,46 @@ minetest.register_node("mcl_core:ladder", {
end end
return itemstack return itemstack
end, end,
after_destruct = function(pos, oldnode)
local pos_above = vector.add(pos, {x = 0, y = 1, z = 0 })
local node_above = minetest.get_node_or_nil(pos_above)
if node_above then
local is_trapdoor = minetest.get_item_group(node_above.name, "trapdoor")
-- If node above is an opened trapdoor
if is_trapdoor == 2 then
local above_def = minetest.registered_nodes[node_above.name]
if above_def._other then
minetest.swap_node(pos_above, {
name = above_def._other,
param1 = node_above.param1,
param2 = node_above.param2,
})
end
end
end
end,
after_place_node = function(pos, oldnode)
local pos_above = vector.add(pos, {x = 0, y = 1, z = 0 })
local node_above = minetest.get_node_or_nil(pos_above)
if node_above then
local is_trapdoor = minetest.get_item_group(node_above.name, "trapdoor")
-- If node above is an opened trapdoor
if is_trapdoor == 2 then
local above_def = minetest.registered_nodes[node_above.name]
if above_def._other then
minetest.swap_node(pos_above, {
name = above_def._other,
param1 = node_above.param1,
param2 = node_above.param2,
})
end
end
end
end,
_mcl_blast_resistance = 0.4, _mcl_blast_resistance = 0.4,
_mcl_hardness = 0.4, _mcl_hardness = 0.4,
on_rotate = rotate_climbable, on_rotate = rotate_climbable,

View File

@ -72,7 +72,21 @@ function mcl_doors:register_trapdoor(name, def)
-- Open -- Open
else else
minetest.sound_play(def.sound_open, {pos = pos, gain = 0.3, max_hear_distance = 16}, true) minetest.sound_play(def.sound_open, {pos = pos, gain = 0.3, max_hear_distance = 16}, true)
tmp_node = {name=name.."_open", param1=me.param1, param2=me.param2}
local bottom_node = minetest.get_node_or_nil(vector.subtract(pos, { x = 0, y = 1, z = 0 }))
local name_end = "_open"
-- Checking if there is something underneath the trapdoor
if bottom_node then
local bottom_def = minetest.registered_nodes[bottom_node.name]
local trapdoor = minetest.get_item_group(bottom_node.name, "trapdoor")
-- Changing trapdoor into a ladder if bottom node is climbable and not a trapdoor
if trapdoor ~= 2 and bottom_def.climbable then
name_end = "_ladder"
end
end
tmp_node = {name=name..name_end, param1=me.param1, param2=me.param2}
end end
minetest.set_node(pos, tmp_node) minetest.set_node(pos, tmp_node)
end end
@ -193,6 +207,7 @@ function mcl_doors:register_trapdoor(name, def)
groups_open.trapdoor = 2 groups_open.trapdoor = 2
groups_open.not_in_creative_inventory = 1 groups_open.not_in_creative_inventory = 1
-- Non-climbable opened
minetest.register_node(name.."_open", { minetest.register_node(name.."_open", {
drawtype = "nodebox", drawtype = "nodebox",
tiles = tiles_open, tiles = tiles_open,
@ -200,9 +215,35 @@ function mcl_doors:register_trapdoor(name, def)
is_ground_content = false, is_ground_content = false,
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
-- TODO: Implement Minecraft behaviour: Climbable if directly above sunlight_propagates = true,
-- ladder w/ matching orientation. pointable = true,
-- Current behavour: Always climbable groups = groups_open,
_mcl_hardness = def._mcl_hardness,
_mcl_blast_resistance = def._mcl_blast_resistance,
sounds = def.sounds,
drop = name,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, 5/16, 0.5, 0.5, 0.5}
},
on_rightclick = on_rightclick,
mesecons = {effector = {
action_off = (function(pos, node)
punch(pos)
end),
}},
on_rotate = on_rotate,
_other = name .. "_ladder"
})
-- Climbable opened
minetest.register_node(name.."_ladder", {
drawtype = "nodebox",
tiles = tiles_open,
use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true,
is_ground_content = false,
paramtype = "light",
paramtype2 = "facedir",
climbable = true, climbable = true,
sunlight_propagates = true, sunlight_propagates = true,
pointable = true, pointable = true,
@ -222,6 +263,7 @@ function mcl_doors:register_trapdoor(name, def)
end), end),
}}, }},
on_rotate = on_rotate, on_rotate = on_rotate,
_other = name .. "_open"
}) })
if minetest.get_modpath("doc") then if minetest.get_modpath("doc") then