@@ -334,26 +334,35 @@ object RaytraceHandlerImpl: RaytraceHandler<RaytraceHandlerImpl.RaytraceConfig,
334334 fun raytrace (player : ServerPlayer , predPlayer : Vec3 ? , aabb : AABB , level : ServerLevel ): Boolean {
335335 val from = player.eyePosition
336336
337- val isXMin = abs(from.x - aabb.minX) < abs(from.x - aabb.maxX)
338- val isYMin = abs(from.y - aabb.minY) < abs(from.y - aabb.maxY)
339- val isZMin = abs(from.z - aabb.minZ) < abs(from.z - aabb.maxZ)
340-
341- val nearestX = if (isXMin) aabb.minX else aabb.maxX
342- val nearestY = if (isYMin) aabb.minY else aabb.maxY
343- val nearestZ = if (isZMin) aabb.minZ else aabb.maxZ
344- val farthestX = if (isXMin) aabb.maxX else aabb.minX
345- val farthestY = if (isYMin) aabb.maxY else aabb.minY
346- val farthestZ = if (isZMin) aabb.maxZ else aabb.minZ
347-
348- // Find visible vertices
349- // If the player is very close to the entity, then they may only see 1 face(4 vertices) or 2 face (6 vertices)
350- // But we don't consider it because it's too rare and raytrace of that should be easy.
351- val vertices = listOf (
352- Vec3 (nearestX, nearestY, nearestZ), Vec3 (farthestX, nearestY, nearestZ),
353- Vec3 (nearestX, farthestY, nearestZ), Vec3 (nearestX, nearestY, farthestZ),
354- Vec3 (farthestX, farthestY, nearestZ), Vec3 (farthestX, nearestY, farthestZ),
355- Vec3 (nearestX, farthestY, farthestZ)
356- )
337+ val vertices = if (aabb.xsize <= 0.25 && aabb.ysize <= 0.25 && aabb.zsize <= 0.25 ) {
338+ // If it's small boundingBox, only consider center pos.
339+ // Mostly item, projectile entities.
340+ listOf (aabb.center)
341+ } else {
342+ val isXMin = abs(from.x - aabb.minX) < abs(from.x - aabb.maxX)
343+ val isYMin = abs(from.y - aabb.minY) < abs(from.y - aabb.maxY)
344+ val isZMin = abs(from.z - aabb.minZ) < abs(from.z - aabb.maxZ)
345+
346+ val nearestX = if (isXMin) aabb.minX else aabb.maxX
347+ val nearestY = if (isYMin) aabb.minY else aabb.maxY
348+ val nearestZ = if (isZMin) aabb.minZ else aabb.maxZ
349+ val farthestX = if (isXMin) aabb.maxX else aabb.minX
350+ val farthestY = if (isYMin) aabb.maxY else aabb.minY
351+ val farthestZ = if (isZMin) aabb.maxZ else aabb.minZ
352+
353+ // Find visible vertices
354+ // If the player is very close to the entity, then they may only see 1 face(4 vertices) or 2 face (6 vertices)
355+ // But we don't consider it because it's too rare and raytrace of that should be easy.
356+ listOf (
357+ Vec3 (nearestX, nearestY, nearestZ),
358+ Vec3 (farthestX, nearestY, nearestZ),
359+ Vec3 (nearestX, farthestY, nearestZ),
360+ Vec3 (nearestX, nearestY, farthestZ),
361+ Vec3 (farthestX, farthestY, nearestZ),
362+ Vec3 (farthestX, nearestY, farthestZ),
363+ Vec3 (nearestX, farthestY, farthestZ)
364+ )
365+ }
357366
358367 for (vec3 in vertices) {
359368 if (! raytracer.raytrace(from, vec3, level)) {
0 commit comments