1
0
mirror of https://github.com/minetest/minetest.git synced 2025-06-30 23:20:22 +02:00

Add support for attached facedir/4dir nodes (#11432)

This commit is contained in:
Wuzzy
2022-11-24 23:56:07 +01:00
committed by GitHub
parent 1c10988d6a
commit 3c7f26d937
13 changed files with 177 additions and 27 deletions

View File

@ -466,15 +466,39 @@ local function drop_attached_node(p)
end
end
function builtin_shared.check_attached_node(p, n)
function builtin_shared.check_attached_node(p, n, group_rating)
local def = core.registered_nodes[n.name]
local d = vector.zero()
if def.paramtype2 == "wallmounted" or
if group_rating == 3 then
-- always attach to floor
d.y = -1
elseif group_rating == 4 then
-- always attach to ceiling
d.y = 1
elseif group_rating == 2 then
-- attach to facedir or 4dir direction
if (def.paramtype2 == "facedir" or
def.paramtype2 == "colorfacedir") then
-- Attach to whatever facedir is "mounted to".
-- For facedir, this is where tile no. 5 point at.
-- The fallback vector here is in case 'facedir to dir' is nil due
-- to voxelmanip placing a wallmounted node without resetting a
-- pre-existing param2 value that is out-of-range for facedir.
-- The fallback vector corresponds to param2 = 0.
d = core.facedir_to_dir(n.param2) or vector.new(0, 0, 1)
elseif (def.paramtype2 == "4dir" or
def.paramtype2 == "color4dir") then
-- Similar to facedir handling
d = core.fourdir_to_dir(n.param2) or vector.new(0, 0, 1)
end
elseif def.paramtype2 == "wallmounted" or
def.paramtype2 == "colorwallmounted" then
-- The fallback vector here is in case 'wallmounted to dir' is nil due
-- to voxelmanip placing a wallmounted node without resetting a
-- pre-existing param2 value that is out-of-range for wallmounted.
-- The fallback vector corresponds to param2 = 0.
-- Attach to whatever this node is "mounted to".
-- This where tile no. 2 points at.
-- The fallback vector here is used for the same reason as
-- for facedir nodes.
d = core.wallmounted_to_dir(n.param2) or vector.new(0, 1, 0)
else
d.y = -1
@ -519,8 +543,9 @@ function core.check_single_for_falling(p)
end
end
if core.get_item_group(n.name, "attached_node") ~= 0 then
if not builtin_shared.check_attached_node(p, n) then
local an = core.get_item_group(n.name, "attached_node")
if an ~= 0 then
if not builtin_shared.check_attached_node(p, n, an) then
drop_attached_node(p)
return true
end

View File

@ -240,8 +240,9 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
end
-- Check if the node is attached and if it can be placed there
if core.get_item_group(def.name, "attached_node") ~= 0 and
not builtin_shared.check_attached_node(place_to, newnode) then
local an = core.get_item_group(def.name, "attached_node")
if an ~= 0 and
not builtin_shared.check_attached_node(place_to, newnode, an) then
log("action", "attached node " .. def.name ..
" cannot be placed at " .. core.pos_to_string(place_to))
return itemstack, nil