Files
Lophine/lophine-server/minecraft-patches/features/0003-Add-config-to-enable-raytracing-tracker.patch
T
Helvetica Volubi e5cc20ba9b Update Luminol
2026-02-23 21:23:49 +08:00

159 lines
7.8 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] Add config to enable raytracing tracker
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
index bca2c5410aa543d2bb421e53893e9163508b3568..fdccb06c918d387e46c29ede7337159db8c5d9ca 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 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 040c0f8d26554ba583ecf370e2df3690d8f48dd6..22e68cabb4554c3e21e6f4ef316186f60ec77511 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -152,7 +152,7 @@ import org.jetbrains.annotations.Contract;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
-public abstract class Entity implements SyncedDataHolder, DebugValueSource, Nameable, ItemOwner, SlotProvider, 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, SlotProvider, 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 // Luminol - Ray tracing entity tracker
// CraftBukkit start
private static final int CURRENT_LEVEL = 2;
static boolean isLevelAtLeast(ValueInput input, int level) {
@@ -6442,4 +6442,46 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
// 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 (!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;
+ }
+
}
diff --git a/net/minecraft/world/entity/EntityType.java b/net/minecraft/world/entity/EntityType.java
index 0590d5723854a03a59fe9471710802f4e64e50b8..4f8ff2c024d6f2e67c5fa38fe2e660ba39e35499 100644
--- a/net/minecraft/world/entity/EntityType.java
+++ b/net/minecraft/world/entity/EntityType.java
@@ -1254,6 +1254,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 67c0f4027a1e8b364694b5ed8b71965f2fe9b359..0f6e1428cc71c370af45db3e2a4f47c66e5d8628 100644
--- a/net/minecraft/world/entity/player/Player.java
+++ b/net/minecraft/world/entity/player/Player.java
@@ -189,6 +189,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(Level level, GameProfile gameProfile) {
super(EntityType.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);
@@ -1353,6 +1392,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