mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-22 00:09:20 +00:00
Begin backporting to 1.18.2
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Samsuik <40902469+Samsuik@users.noreply.github.com>
|
||||
Date: Thu, 30 Nov 2023 15:54:49 +0000
|
||||
Subject: [PATCH] Reduce entity tracker player updates
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||||
index 759ac36b32eaddcc0cff4c2308030b692d6fc7f4..ee7871ddd36b20206ef66372b04861d100601341 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
||||
@@ -2040,6 +2040,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
||||
try {
|
||||
for (TrackedEntity tracker : this.entityMap.values()) {
|
||||
// update tracker entry
|
||||
+ if (!tracker.shouldLookForPlayers()) continue; // Sakura - delay entities looking for nearby players
|
||||
tracker.updatePlayers(tracker.entity.getPlayersInTrackRange());
|
||||
}
|
||||
} finally {
|
||||
@@ -2232,14 +2233,34 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
||||
private final int range;
|
||||
SectionPos lastSectionPos;
|
||||
public final Set<ServerPlayerConnection> seenBy = new ReferenceOpenHashSet<>(); // Paper - optimise map impl
|
||||
+ private final int playerSearchInterval; // Sakura - reduce entity tracker player updates
|
||||
+ private Vec3 entityPosition; // Sakura - reduce entity tracker player updates
|
||||
|
||||
public TrackedEntity(Entity entity, int i, int j, boolean flag) {
|
||||
this.serverEntity = new ServerEntity(ChunkMap.this.level, entity, j, flag, this::broadcast, this.seenBy); // CraftBukkit
|
||||
this.entity = entity;
|
||||
this.range = i;
|
||||
this.lastSectionPos = SectionPos.of(entity);
|
||||
+ // Sakura start - reduce entities looking for nearby players
|
||||
+ // Use a maximum of 20 ticks because stationary entities use Integer.MAX_VALUE
|
||||
+ // which causes them to turn invisible after untracking.
|
||||
+ this.playerSearchInterval = Math.min(j, 20);
|
||||
+ this.entityPosition = entity.position();
|
||||
}
|
||||
|
||||
+ final boolean shouldLookForPlayers() {
|
||||
+ // We have to always update players otherwise they can turn invisible on teleports (why?)
|
||||
+ if (entity instanceof net.minecraft.world.entity.player.Player || entity.tickCount % playerSearchInterval == 0) {
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ Vec3 lastPosition = entityPosition;
|
||||
+ entityPosition = entity.position();
|
||||
+
|
||||
+ return entity.position().distanceToSqr(lastPosition) >= (double) range / 2.0;
|
||||
+ }
|
||||
+ // Sakura end - reduce entities looking for nearby players
|
||||
+
|
||||
// Paper start - use distance map to optimise tracker
|
||||
com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> lastTrackerCandidates;
|
||||
|
||||
Reference in New Issue
Block a user