Skip to content

Commit 9ed8c4d

Browse files
committed
[EntityCulling] Optimize far away culled entities check
1 parent 2d7db5f commit 9ed8c4d

File tree

1 file changed

+3
-1
lines changed
  • bukkit/src/main/kotlin/io/github/rothes/esu/bukkit/module/networkthrottle/entityculling

1 file changed

+3
-1
lines changed

bukkit/src/main/kotlin/io/github/rothes/esu/bukkit/module/networkthrottle/entityculling/UserCullData.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import io.github.rothes.esu.bukkit.util.scheduler.Scheduler
77
import io.github.rothes.esu.bukkit.util.version.Versioned
88
import io.github.rothes.esu.bukkit.util.version.adapter.PlayerAdapter.Companion.connected
99
import io.github.rothes.esu.bukkit.util.version.adapter.TickThreadAdapter.Companion.checkTickThread
10+
import io.github.rothes.esu.core.util.extension.math.square
1011
import it.unimi.dsi.fastutil.Hash
1112
import it.unimi.dsi.fastutil.ints.Int2ReferenceOpenHashMap
1213
import it.unimi.dsi.fastutil.ints.IntArrayList
@@ -89,7 +90,8 @@ class UserCullData(
8990
for (entry in iterator) {
9091
val entity = entry.value
9192
var flag = !raytraceHandler.isValid(entity)
92-
if (entity.world != player.world || entity.location.distanceSquared(playerLoc) > 1024 * 1024) {
93+
val loc = entity.location
94+
if (loc.world != playerLoc.world || (playerLoc.x - loc.x).square() + (playerLoc.z - loc.z).square() > 1024 * 1024) {
9395
playerEntityVisibilityHandler.forceShowEntity(player, entity)
9496
flag = true
9597
}

0 commit comments

Comments
 (0)