From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> Date: Thu, 10 Jul 2025 04:51:08 +0300 Subject: [PATCH] Raytrace Entity Tracker Original project: https://github.com/tr7zw/EntityCulling Original license: Custom License Original project: https://github.com/LogisticsCraft/OcclusionCulling Original license: MIT diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java index 56483d9e770e29526a36d4c8c5565092acb227c7..9db43874a94770d49ea5ff48a46c4657e4819e98 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java @@ -147,7 +147,7 @@ import net.minecraft.world.waypoints.WaypointTransmitter; import org.jetbrains.annotations.Contract; import org.slf4j.Logger; -public abstract class Entity implements SyncedDataHolder, DebugValueSource, Nameable, ItemOwner, EntityAccess, ScoreHolder, DataComponentGetter, ca.spottedleaf.moonrise.patches.chunk_system.entity.ChunkSystemEntity, ca.spottedleaf.moonrise.patches.entity_tracker.EntityTrackerEntity { // Paper - rewrite chunk system // Paper - optimise entity tracker +public abstract class Entity implements SyncedDataHolder, DebugValueSource, Nameable, ItemOwner, EntityAccess, ScoreHolder, DataComponentGetter, 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 // DivineMC - Raytrace Entity Tracker public static javax.script.ScriptEngine scriptEngine = new javax.script.ScriptEngineManager().getEngineByName("rhino"); // Purpur - Configurable entity base attributes // CraftBukkit start private static final int CURRENT_LEVEL = 2; @@ -5531,4 +5531,47 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name return false; } // Purpur end - Ridables + + // DivineMC start - Raytrace Entity 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 (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.retEnabled) return false; + + return this.culled; + } + + @Override + public void setOutOfCamera(boolean value) { + this.outOfCamera = value; + } + + @Override + public boolean isOutOfCamera() { + if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.retEnabled) return false; + + return this.outOfCamera; + } + // DivineMC end - Raytrace Entity Tracker } diff --git a/net/minecraft/world/entity/EntityType.java b/net/minecraft/world/entity/EntityType.java index d9d45a3e7436d5a211e3f2b6810f76e0a22766e8..4c6ca2979a370346008b981e045625668269e380 100644 --- a/net/minecraft/world/entity/EntityType.java +++ b/net/minecraft/world/entity/EntityType.java @@ -1202,6 +1202,7 @@ public class EntityType implements FeatureElement, EntityTypeT private final float spawnDimensionsScale; private final FeatureFlagSet requiredFeatures; private final boolean allowedInPeaceful; + public boolean skipRaytracingCheck = false; // DivineMC - Raytrace Entity Tracker private static EntityType register(ResourceKey> key, EntityType.Builder builder) { return Registry.register(BuiltInRegistries.ENTITY_TYPE, key, builder.build(key)); diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java index 68942a2d15cfeddf1928a3ad270b1ce29685f8f0..149332116ff211c122b1dbf9b8010610174451db 100644 --- a/net/minecraft/world/entity/player/Player.java +++ b/net/minecraft/world/entity/player/Player.java @@ -184,6 +184,25 @@ public abstract class Player extends Avatar implements ContainerUser { public int burpDelay = 0; // Purpur - Burp delay public boolean canPortalInstant = false; // Purpur - Add portal permission bypass public int sixRowEnderchestSlotCount = -1; // Purpur - Barrels and enderchests 6 rows + // DivineMC start - Raytrace Entity Tracker + public dev.tr7zw.entityculling.CullTask cullTask; + { + if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.retEnabled) { + this.cullTask = null; + } else { + final com.logisticscraft.occlusionculling.OcclusionCullingInstance culling = new com.logisticscraft.occlusionculling.OcclusionCullingInstance( + org.bxteam.divinemc.config.DivineConfig.MiscCategory.retTracingDistance, + new dev.tr7zw.entityculling.DefaultChunkDataProvider(this.level()) + ); + + this.cullTask = new dev.tr7zw.entityculling.CullTask( + culling, this, + org.bxteam.divinemc.config.DivineConfig.MiscCategory.retHitboxLimit, + org.bxteam.divinemc.config.DivineConfig.MiscCategory.retCheckIntervalMs + ); + } + } + // DivineMC end - Raytrace Entity Tracker // CraftBukkit start public boolean fauxSleeping; @@ -270,6 +289,25 @@ public abstract class Player extends Avatar implements ContainerUser { @Override public void tick() { + // DivineMC start - Raytrace Entity Tracker + if (!org.bxteam.divinemc.config.DivineConfig.MiscCategory.retEnabled) { + if (this.cullTask != null) this.cullTask.signalStop(); + this.cullTask = null; + } else { + final com.logisticscraft.occlusionculling.OcclusionCullingInstance culling = new com.logisticscraft.occlusionculling.OcclusionCullingInstance( + org.bxteam.divinemc.config.DivineConfig.MiscCategory.retTracingDistance, + new dev.tr7zw.entityculling.DefaultChunkDataProvider(this.level()) + ); + + this.cullTask = new dev.tr7zw.entityculling.CullTask( + culling, this, + org.bxteam.divinemc.config.DivineConfig.MiscCategory.retHitboxLimit, + org.bxteam.divinemc.config.DivineConfig.MiscCategory.retCheckIntervalMs + ); + } + if (this.cullTask != null) this.cullTask.setup(); + if (this.cullTask != null) this.cullTask.requestCullSignal(); + // DivineMC end - Raytrace Entity Tracker // Purpur start - Burp delay if (this.burpDelay > 0 && --this.burpDelay == 0) { this.level().playSound(null, getX(), getY(), getZ(), SoundEvents.PLAYER_BURP, SoundSource.PLAYERS, 1.0F, this.level().random.nextFloat() * 0.1F + 0.9F); @@ -1315,6 +1353,7 @@ public abstract class Player extends Avatar implements ContainerUser { if (this.hasContainerOpen()) { this.doCloseContainer(); } + if (this.cullTask != null) this.cullTask.signalStop(); // DivineMC - Raytrace Entity Tracker } @Override