Fix the placement check of ladder

The old code takes the first return val of `minetest.item_place_node'
which is `itemstack'. Therefore, the variable `success' in the old code
is always true. The new code takes the second val which will be nil if
an invalid node placement occured.

This check is necessary since the ladder may be placed in the front of
pointed block while there is a node with hole (slabs, fences etc.) at
the same place resulting an invalid placement and sound played when
it shouldn't be played.
This commit is contained in:
William Goodspeed 2024-08-16 22:52:58 +00:00 committed by William Goodspeed
parent 9657c9d8bb
commit c03f9abd18

View file

@ -104,9 +104,10 @@ minetest.register_node("mcl_core:ladder", {
return itemstack
end
local idef = itemstack:get_definition()
local success = minetest.item_place_node(itemstack, placer, pointed_thing)
local itemstack, pos = minetest.item_place_node(itemstack, placer, pointed_thing)
if success then
-- A non-nil pos indicates the node was placed in a valid position.
if pos then
if idef.sounds and idef.sounds.place then
minetest.sound_play(idef.sounds.place, { pos = above, gain = 1 }, true)
end