From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: MrHua269 Date: Wed, 5 Feb 2025 15:22:19 +0800 Subject: [PATCH] Add config to enable raytracing tracker diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java index e9307ef10502856378d7831fb7800dd77230130c..6bca982627cf6a865820df75be2814a7289f98dc 100644 --- a/net/minecraft/server/level/ChunkMap.java +++ b/net/minecraft/server/level/ChunkMap.java @@ -1375,7 +1375,7 @@ public class ChunkMap extends SimpleRegionStorage implements ChunkHolder.PlayerP double distanceSquared = deltaToPlayerX * deltaToPlayerX + deltaToPlayerZ * deltaToPlayerZ; // Paper double rangeSquared = visibleRange * visibleRange; // Paper start - Configurable entity tracking range by Y - boolean visibleToPlayer = distanceSquared <= rangeSquared; + boolean visibleToPlayer = distanceSquared <= rangeSquared && !entity.isCulled(); // Luminol - Ray tracing entity tracker if (visibleToPlayer && level.paperConfig().entities.trackingRangeY.enabled) { double rangeY = level.paperConfig().entities.trackingRangeY.get(this.entity, -1); if (rangeY != -1) { diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java index 0868c067c5a455d1984d59b22426c2f019b25c9f..b9f9dd85d259306db9eb9daf0a9ec36f27dfddb7 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java @@ -164,7 +164,7 @@ public abstract class Entity ItemOwner, SlotProvider, DebugValueSource, - TypedInstance>, ca.spottedleaf.moonrise.patches.chunk_system.entity.ChunkSystemEntity, ca.spottedleaf.moonrise.patches.entity_tracker.EntityTrackerEntity { // Paper - rewrite chunk system // Paper - optimise entity tracker + TypedInstance>, ca.spottedleaf.moonrise.patches.chunk_system.entity.ChunkSystemEntity, ca.spottedleaf.moonrise.patches.entity_tracker.EntityTrackerEntity, dev.tr7zw.entityculling.versionless.access.Cullable { // Paper - rewrite chunk system // Paper - optimise entity tracker // Luminol - Ray tracing entity tracker // CraftBukkit start private static final int CURRENT_LEVEL = 2; static boolean isLevelAtLeast(ValueInput input, int level) { @@ -6586,4 +6586,48 @@ public abstract class Entity // Paper end public boolean shouldTickHot() { return this.tickCount > 20 * 10 && this.isAlive(); } // KioCG + // Lophine start - Add config to enable raytracing tracker + + private long lasttime = 0; + private boolean culled = false; + private boolean outOfCamera = false; + + @Override + public void setTimeout() { + this.lasttime = System.currentTimeMillis() + 1000; + } + + @Override + public boolean isForcedVisible() { + return this.lasttime > System.currentTimeMillis(); + } + + @Override + public void setCulled(boolean value) { + this.culled = value; + if (!value) { + setTimeout(); + } + } + + @Override + public boolean isCulled() { + if (!fun.bm.lophine.config.modules.experiment.RayTrackingEntityTrackerConfig.enabled) + return false; + return this.culled; + } + + @Override + public void setOutOfCamera(boolean value) { + this.outOfCamera = value; + } + + @Override + public boolean isOutOfCamera() { + if (!fun.bm.lophine.config.modules.experiment.RayTrackingEntityTrackerConfig.enabled) + return false; + return this.outOfCamera; + } + + // Lophine end - Add config to enable raytracing tracker } diff --git a/net/minecraft/world/entity/EntityType.java b/net/minecraft/world/entity/EntityType.java index 31619890f1bd4f458b6f9a31fac8cefaafe09e8e..50643bd0b546a1ff70031ea39e2610f219ef8a79 100644 --- a/net/minecraft/world/entity/EntityType.java +++ b/net/minecraft/world/entity/EntityType.java @@ -85,6 +85,11 @@ public class EntityType implements EntityTypeTest, public final int passengerTickTimerId; public final int passengerInactiveTickTimerId; // Folia end - profiler + // Lophine start - Add config to enable raytracing tracker + // Luminol - Raytracing entity tracker + public boolean skipRaytracningCheck = false; + // Luminol end + // Lophine end - Add config to enable raytracing tracker public EntityType( final EntityType.EntityFactory factory, diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java index e7b6c83a4e7bd83f6c5a1d772c42c51bf1d1bed1..449a2904fb1190f68de72bc47eb8220f50002577 100644 --- a/net/minecraft/world/entity/player/Player.java +++ b/net/minecraft/world/entity/player/Player.java @@ -186,6 +186,25 @@ public abstract class Player extends Avatar implements ContainerUser { return (org.bukkit.craftbukkit.entity.CraftHumanEntity) super.getBukkitEntity(); } // CraftBukkit end + // Luminol start - Raytracing entity tracker + public dev.tr7zw.entityculling.CullTask cullTask; + { + if (!fun.bm.lophine.config.modules.experiment.RayTrackingEntityTrackerConfig.enabled) { + this.cullTask = null; + }else { + final com.logisticscraft.occlusionculling.OcclusionCullingInstance culling = new com.logisticscraft.occlusionculling.OcclusionCullingInstance( + fun.bm.lophine.config.modules.experiment.RayTrackingEntityTrackerConfig.tracingDistance, + new dev.tr7zw.entityculling.DefaultChunkDataProvider(this.level()) + ); + + this.cullTask = new dev.tr7zw.entityculling.CullTask( + culling, this, + fun.bm.lophine.config.modules.experiment.RayTrackingEntityTrackerConfig.hitboxLimit, + fun.bm.lophine.config.modules.experiment.RayTrackingEntityTrackerConfig.checkIntervalMs + ); + } + } + // Luminol end public Player(final Level level, final GameProfile gameProfile) { super(EntityTypes.PLAYER, level); @@ -245,6 +264,26 @@ public abstract class Player extends Avatar implements ContainerUser { @Override public void tick() { + // Luminol start - Ray tracing entity tracker + if (!fun.bm.lophine.config.modules.experiment.RayTrackingEntityTrackerConfig.enabled) { + if (this.cullTask != null) this.cullTask.signalStop(); + this.cullTask = null; + }else { + final com.logisticscraft.occlusionculling.OcclusionCullingInstance culling = new com.logisticscraft.occlusionculling.OcclusionCullingInstance( + fun.bm.lophine.config.modules.experiment.RayTrackingEntityTrackerConfig.tracingDistance, + new dev.tr7zw.entityculling.DefaultChunkDataProvider(this.level()) + ); + + this.cullTask = new dev.tr7zw.entityculling.CullTask( + culling, this, + fun.bm.lophine.config.modules.experiment.RayTrackingEntityTrackerConfig.hitboxLimit, + fun.bm.lophine.config.modules.experiment.RayTrackingEntityTrackerConfig.checkIntervalMs + ); + } + if (this.cullTask != null) this.cullTask.setup(); + if (this.cullTask != null) this.cullTask.requestCullSignal(); // Luminol - Ray tracing entity tracker + // Luminol end + this.noPhysics = this.isSpectator(); if (this.isSpectator() || this.isPassenger()) { this.setOnGround(false); @@ -1378,6 +1417,7 @@ public abstract class Player extends Avatar implements ContainerUser { if (this.hasContainerOpen()) { this.doCloseContainer(); } + if (this.cullTask != null) this.cullTask.signalStop(); // Luminol - Ray tracing entity tracker } @Override