Skip to content

Commit 9a61ddb

Browse files
committed
Slight optimization to raytrace tickPlayer
1 parent 0b49bdd commit 9a61ddb

File tree

1 file changed

+7
-4
lines changed
  • bukkit/version/v1_18/src/main/kotlin/io/github/rothes/esu/bukkit/module/networkthrottle/entityculling/v1_18

1 file changed

+7
-4
lines changed

bukkit/version/v1_18/src/main/kotlin/io/github/rothes/esu/bukkit/module/networkthrottle/entityculling/v1_18/RaytraceHandlerImpl.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import net.minecraft.world.level.block.state.BlockBehaviour
3939
import net.minecraft.world.level.block.state.BlockState
4040
import net.minecraft.world.level.chunk.LevelChunkSection
4141
import net.minecraft.world.level.chunk.PalettedContainer
42+
import net.minecraft.world.phys.AABB
4243
import net.minecraft.world.phys.Vec3
4344
import org.bukkit.Bukkit
4445
import org.bukkit.Location
@@ -276,6 +277,9 @@ object RaytraceHandlerImpl: RaytraceHandler<RaytraceHandlerImpl.RaytraceConfig,
276277
val playerY = player.y
277278
val playerZ = player.z
278279

280+
val playerGridX = playerX.floorI() shr 8
281+
val playerGridZ = playerZ.floorI() shr 8
282+
279283
val shouldCull = userCullData.shouldCull
280284
val predicatedPlayerPos = if (shouldCull && config.predicatePlayerPositon) {
281285
val velocity = playerVelocityGetter.getPlayerMoveVelocity(player)
@@ -315,24 +319,23 @@ object RaytraceHandlerImpl: RaytraceHandler<RaytraceHandlerImpl.RaytraceConfig,
315319

316320
if (
317321
!shouldCull
322+
|| dist + (playerY - pos.y).square() <= forceVisibleDistanceSquared
318323
|| entity.isCurrentlyGlowing
319324
|| config.visibleEntityTypes.contains(entity.type)
320-
|| dist + (playerY - pos.y).square() <= forceVisibleDistanceSquared
321325
) {
322326
userCullData.setCulled(entity.bukkitEntity, entity.id, false)
323327
continue
324328
}
325329

326-
userCullData.setCulled(entity.bukkitEntity, entity.id, raytrace(player, predicatedPlayerPos, entity, level))
330+
userCullData.setCulled(entity.bukkitEntity, entity.id, raytrace(player, predicatedPlayerPos, entity.boundingBox, level))
327331
}
328332
}
329333
userCullData.shouldCull = tickedEntities >= config.cullThreshold
330334
userCullData.tick()
331335
}
332336

333-
fun raytrace(player: ServerPlayer, predPlayer: Vec3?, entity: Entity, level: ServerLevel): Boolean {
337+
fun raytrace(player: ServerPlayer, predPlayer: Vec3?, aabb: AABB, level: ServerLevel): Boolean {
334338
val from = player.eyePosition
335-
val aabb = entity.boundingBox
336339

337340
val isXMin = abs(from.x - aabb.minX) < abs(from.x - aabb.maxX)
338341
val isYMin = abs(from.y - aabb.minY) < abs(from.y - aabb.maxY)

0 commit comments

Comments
 (0)