diff options
| author | Wuzzy <Wuzzy@disroot.org> | 2022-11-24 23:56:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-24 17:56:07 -0500 |
| commit | 3c7f26d93721d8d86ca5d9e894e8652b1e2a8672 (patch) | |
| tree | 7f5713d792f48edc51332c90798f17647624c98a /builtin | |
| parent | 1c10988d6a19b06ac9c64e83675a76dea29cad2e (diff) | |
| download | minetest-3c7f26d93721d8d86ca5d9e894e8652b1e2a8672.tar.xz | |
Add support for attached facedir/4dir nodes (#11432)
Diffstat (limited to 'builtin')
| -rw-r--r-- | builtin/game/falling.lua | 41 | ||||
| -rw-r--r-- | builtin/game/item.lua | 5 |
2 files changed, 36 insertions, 10 deletions
diff --git a/builtin/game/falling.lua b/builtin/game/falling.lua index 01a7d60b8..f9d71c90a 100644 --- a/builtin/game/falling.lua +++ b/builtin/game/falling.lua @@ -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 diff --git a/builtin/game/item.lua b/builtin/game/item.lua index 1d1d52860..71126b0a7 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -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 |
