Stop animals from trying to jump over fences

This commit is contained in:
Wuzzy 2024-04-06 18:44:54 +02:00
parent b2f1b18e88
commit f9f82b1ae6
2 changed files with 13 additions and 3 deletions

View File

@ -179,7 +179,7 @@ Unlike `attached_node`, they also work if the node is not `walkable`. Use these
* `door_wood`: Wooden door
* `door_state`: Door segment, internal state (1 or 2) (see `rp_door` mod)
* `door_position`: Door segment, position (1 = bottom, 2 = top)
* `fence`: Fence
* `fence`: Fence. Fence nodes MUST have a collisionbox height of 1.5
* `sign`: Sign
* `bed`: Bed segment
* `torch`: Torch

View File

@ -568,18 +568,28 @@ local can_clear_jump = function(mob, jump_clear_height)
end
dir = vector.multiply(dir, 0.5)
local pos_front = vector.add(pos, dir)
local node_top_walkable
local h = -1
while h <= jump_clear_height do
h = h + 1
local node_front = minetest.get_node(pos_front)
local def_front = minetest.registered_nodes[node_front.name]
if def_front and not def_front.walkable then
if def_front then
if def_front.walkable then
node_top_walkable = node_front
else
break
end
end
pos_front.y = pos_front.y + 1
end
-- Add 0.5 to height if top node is a fence due to the overhigh collisionbox
if node_top_walkable and minetest.get_item_group(node_top_walkable.name, "fence") ~= 0 then
h = h + 0.5
end
if h <= jump_clear_height then
return true
end