9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-19 14:59:25 +00:00
Files
DivineMC/divinemc-server/minecraft-patches/features/0061-Raytrace-Entity-Tracker.patch
2025-10-11 16:20:06 +03:00

149 lines
7.2 KiB
Diff

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 2bf4f7c612318c6cb3f21f111811cc28766298e0..ee33af29c7f98df04f687dde627413e186c42221 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;
@@ -5535,4 +5535,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 e680780a0e46e9e5f9126bd11a20b918e8c36066..3a50f4d2e434e9766656a7e2a1da8c1ed483c97d 100644
--- a/net/minecraft/world/entity/EntityType.java
+++ b/net/minecraft/world/entity/EntityType.java
@@ -1201,6 +1201,7 @@ public class EntityType<T extends Entity> 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 <T extends Entity> EntityType<T> register(ResourceKey<EntityType<?>> key, EntityType.Builder<T> 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 9a6355328ca25ae7c183b68e890106776d82204e..6a8e50598da5e08ce6694c226012a44f88483f71 100644
--- a/net/minecraft/world/entity/player/Player.java
+++ b/net/minecraft/world/entity/player/Player.java
@@ -183,6 +183,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;
@@ -269,6 +288,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);
@@ -1314,6 +1352,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