Files
LuminolMC/luminol-server/minecraft-patches/features/0040-Raytracing-tracker-experiment.patch

160 lines
7.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <wangxyper@163.com>
Date: Wed, 5 Feb 2025 15:22:19 +0800
Subject: [PATCH] Raytracing tracker experiment
Based on the framework of EntityCulling(((((((
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
index 7eff847790394aecd058e7a61905da86163b4c6e..9099457f55a2829297ac1db8a69a98ff717d9a86 100644
--- a/net/minecraft/server/level/ChunkMap.java
+++ b/net/minecraft/server/level/ChunkMap.java
@@ -1208,7 +1208,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
double d1 = vec3_dx * vec3_dx + vec3_dz * vec3_dz; // Paper
double d2 = d * d;
// Paper start - Configurable entity tracking range by Y
- boolean flag = d1 <= d2;
+ boolean flag = d1 <= d2 && !entity.isCulled(); // Luminol - Ray tracing entity tracker
if (flag && 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 f26cdc00180f72bea271877b9ef814daf9850916..647510b9fae49b5a4113a35be9909babf54acfcf 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -135,7 +135,7 @@ import net.minecraft.world.scores.ScoreHolder;
import net.minecraft.world.scores.Team;
import org.slf4j.Logger;
-public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess, ScoreHolder, 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, Nameable, EntityAccess, ScoreHolder, 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;
@@ -6055,4 +6055,46 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
// Paper end - Expose entity id counter
public boolean shouldTickHot() { return this.tickCount > 20 * 10 && this.isAlive(); } // KioCG
+
+ 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 (!me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.enabled)
+ return false;
+ return this.culled;
+ }
+
+ @Override
+ public void setOutOfCamera(boolean value) {
+ this.outOfCamera = value;
+ }
+
+ @Override
+ public boolean isOutOfCamera() {
+ if (!me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.enabled)
+ return false;
+ return this.outOfCamera;
+ }
+
}
diff --git a/net/minecraft/world/entity/EntityType.java b/net/minecraft/world/entity/EntityType.java
index d9cc1d7e56c37d5ce92544edc10e89dbc89dd15d..39e7689be243b9c99b507d665f6591359115287b 100644
--- a/net/minecraft/world/entity/EntityType.java
+++ b/net/minecraft/world/entity/EntityType.java
@@ -1097,6 +1097,9 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
public final int passengerTickTimerId;
public final int passengerInactiveTickTimerId;
// Folia end - profiler
+ // Luminol - Raytracing entity tracker
+ public boolean skipRaytracningCheck = false;
+ // Luminol end
public EntityType(
EntityType.EntityFactory<T> factory,
diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java
index ae049c5c3593525b991d865fec695c00ad408a59..ad34d0e1ab16fb269b3cec2842bfc2f2c29b452e 100644
--- a/net/minecraft/world/entity/player/Player.java
+++ b/net/minecraft/world/entity/player/Player.java
@@ -210,6 +210,25 @@ public abstract class Player extends LivingEntity {
return (org.bukkit.craftbukkit.entity.CraftHumanEntity) super.getBukkitEntity();
}
// CraftBukkit end
+ // Luminol start - Raytracing entity tracker
+ public dev.tr7zw.entityculling.CullTask cullTask;
+ {
+ if (!me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.enabled) {
+ this.cullTask = null;
+ }else {
+ final com.logisticscraft.occlusionculling.OcclusionCullingInstance culling = new com.logisticscraft.occlusionculling.OcclusionCullingInstance(
+ me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.tracingDistance,
+ new dev.tr7zw.entityculling.DefaultChunkDataProvider(this.level())
+ );
+
+ this.cullTask = new dev.tr7zw.entityculling.CullTask(
+ culling, this,
+ me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.hitboxLimit,
+ me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.checkIntervalMs
+ );
+ }
+ }
+ // Luminol end
public Player(Level level, BlockPos pos, float yRot, GameProfile gameProfile) {
super(EntityType.PLAYER, level);
@@ -262,6 +281,26 @@ public abstract class Player extends LivingEntity {
@Override
public void tick() {
+ // Luminol start - Ray tracing entity tracker
+ if (!me.earthme.luminol.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(
+ me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.tracingDistance,
+ new dev.tr7zw.entityculling.DefaultChunkDataProvider(this.level())
+ );
+
+ this.cullTask = new dev.tr7zw.entityculling.CullTask(
+ culling, this,
+ me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.hitboxLimit,
+ me.earthme.luminol.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);
@@ -1504,6 +1543,7 @@ public abstract class Player extends LivingEntity {
if (this.containerMenu != null && this.hasContainerOpen()) {
this.doCloseContainer();
}
+ if (this.cullTask != null) this.cullTask.signalStop(); // Luminol - Ray tracing entity tracker
}
// Folia start - region threading