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 0c0775bbb0c0ba0c37d1b884bb106b5250e94750..0dfb25ad032429a2aea7aa441dd5fd1848a6c617 100644 --- a/net/minecraft/server/level/ChunkMap.java +++ b/net/minecraft/server/level/ChunkMap.java @@ -1350,7 +1350,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 552fd994ee30deb6e9f4228b17a2883cf26b164c..f090b8d77bd2731debfc61c263bd77550f52212b 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java @@ -167,7 +167,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) { @@ -6432,4 +6432,48 @@ public abstract class Entity // Paper end - Expose entity id counter 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 cb0a52dc3795e1cf54069bcbe82abf7877a658b8..0d743a01ae70baa789cd0e0bb9abd4c4f8310b99 100644 --- a/net/minecraft/world/entity/EntityType.java +++ b/net/minecraft/world/entity/EntityType.java @@ -1252,6 +1252,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 ce8ab4b7eee5e0715e780d189d2f6554c5a9dc3c..06c6d30f3aef605bc25c42db8a6d26bbde57f40b 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(EntityType.PLAYER, level); @@ -241,6 +260,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); @@ -1355,6 +1394,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