mirror of
https://github.com/minetest/minetest.git
synced 2024-10-02 07:53:09 +02:00
Add (failing) unit test for raycasts w.r.t. entities
This commit is contained in:
parent
9def45aa80
commit
d4e8da1041
@ -130,3 +130,27 @@ local function test_entity_attach(player, pos)
|
||||
obj:remove()
|
||||
end
|
||||
unittests.register("test_entity_attach", test_entity_attach, {player=true, map=true})
|
||||
|
||||
core.register_entity("unittests:raycastable", {
|
||||
initial_properties = {
|
||||
hp_max = 1,
|
||||
visual = "upright_sprite",
|
||||
textures = { "no_texture.png" },
|
||||
static_save = false,
|
||||
},
|
||||
})
|
||||
|
||||
local function test_entity_raycast(_, pos)
|
||||
local obj1 = core.add_entity(pos, "unittests:raycastable")
|
||||
local obj2 = core.add_entity(pos:offset(1, 0, 0), "unittests:raycastable")
|
||||
local raycast = core.raycast(pos:offset(-1, 0, 0), pos:offset(2, 0, 0), true, false)
|
||||
for pt in raycast do
|
||||
if pt.type == "object" then
|
||||
assert(pt.ref == obj1)
|
||||
obj2:remove()
|
||||
obj1 = nil -- object should be hit exactly one
|
||||
end
|
||||
end
|
||||
assert(obj1 == nil)
|
||||
end
|
||||
unittests.register("test_entity_raycast", test_entity_raycast, {map=true})
|
||||
|
Loading…
Reference in New Issue
Block a user