@@ -46,10 +46,12 @@ import org.bukkit.event.Listener
4646import org.bukkit.event.entity.EntitySpawnEvent
4747import org.bukkit.event.world.ChunkLoadEvent
4848import org.incendo.cloud.annotations.Command
49- import org.spigotmc.TrackingRange
5049import java.util.concurrent.Executors
5150import java.util.concurrent.atomic.AtomicInteger
52- import kotlin.math.*
51+ import kotlin.math.abs
52+ import kotlin.math.floor
53+ import kotlin.math.sign
54+ import kotlin.math.sqrt
5355import kotlin.time.Duration.Companion.seconds
5456
5557class RaytraceHandlerImpl : RaytraceHandler <RaytraceHandlerImpl .RaytraceConfig , EmptyConfiguration >() {
@@ -273,7 +275,8 @@ class RaytraceHandlerImpl: RaytraceHandler<RaytraceHandlerImpl.RaytraceConfig, E
273275 fun tickPlayer (player : ServerPlayer , bukkit : Player , userCullData : UserCullData , level : ServerLevel , entities : Iterable <Entity >) {
274276 val viewDistanceSquared = (bukkit.viewDistance + 1 ).square() shl 8
275277
276- val predicatedPlayerPos = if (userCullData.shouldCull && config.predicatePlayerPositon) {
278+ val shouldCull = userCullData.shouldCull
279+ val predicatedPlayerPos = if (shouldCull && config.predicatePlayerPositon) {
277280 val velocity = playerVelocityGetter.getPlayerMoveVelocity(player)
278281 if (velocity.lengthSqr() >= 0.06 ) { // Threshold for sprinting
279282 var x = player.x
@@ -303,17 +306,13 @@ class RaytraceHandlerImpl: RaytraceHandler<RaytraceHandlerImpl.RaytraceConfig, E
303306 // Get regions from entityLookup, then loop over each chunk to collect entities is 2x slower.
304307 for (entity in entities) {
305308 if (entity == = player) continue
306-
307- // Get tracking range for this entity type, adding extra 1 chunk to it.
308- val typeRange = (TrackingRange .getEntityTrackingRange(entity, entity.type.clientTrackingRange() shl 4 ) + 16 ).square()
309- val finalRange = min(typeRange, viewDistanceSquared)
310309 val dist = (player.x - entity.x).square() + (player.z - entity.z).square()
311- if (dist > finalRange ) continue
310+ if (dist > viewDistanceSquared ) continue
312311
313312 tickedEntities++
314313
315314 if (
316- ! userCullData. shouldCull
315+ ! shouldCull
317316 || entity.isCurrentlyGlowing
318317 || config.visibleEntityTypes.contains(entity.type)
319318 || dist + (player.y - entity.y).square() <= forceVisibleDistanceSquared
0 commit comments