aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0926-Reduce-allocation-of-Vec3D-by-entity-tracker.patch
diff options
context:
space:
mode:
authorNewwind <[email protected]>2024-08-31 19:29:50 +0100
committerGitHub <[email protected]>2024-08-31 20:29:50 +0200
commit509ea2fd17fa03ce04f86046098607733b8767ba (patch)
tree3f7c9a29481fafbb6ad9f846839ec8f4863d2363 /patches/server/0926-Reduce-allocation-of-Vec3D-by-entity-tracker.patch
parente01ddf46279fbb68d157749a906b7a2ecc60da1a (diff)
downloadPaper-509ea2fd17fa03ce04f86046098607733b8767ba.tar.gz
Paper-509ea2fd17fa03ce04f86046098607733b8767ba.zip
Fix horse armor desync (#11341)
Diffstat (limited to 'patches/server/0926-Reduce-allocation-of-Vec3D-by-entity-tracker.patch')
-rw-r--r--patches/server/0926-Reduce-allocation-of-Vec3D-by-entity-tracker.patch59
1 files changed, 59 insertions, 0 deletions
diff --git a/patches/server/0926-Reduce-allocation-of-Vec3D-by-entity-tracker.patch b/patches/server/0926-Reduce-allocation-of-Vec3D-by-entity-tracker.patch
new file mode 100644
index 0000000000..a6036eeb42
--- /dev/null
+++ b/patches/server/0926-Reduce-allocation-of-Vec3D-by-entity-tracker.patch
@@ -0,0 +1,59 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Spottedleaf <[email protected]>
+Date: Mon, 27 Apr 2020 00:04:16 -0700
+Subject: [PATCH] Reduce allocation of Vec3D by entity tracker
+
+
+diff --git a/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java b/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java
+index a043ac10834562d357ef0b5aded2e916e2a0d056..74276c368016fcc4dbf9579b2ecbadc9614baf15 100644
+--- a/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java
++++ b/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java
+@@ -5,7 +5,7 @@ import org.jetbrains.annotations.VisibleForTesting;
+
+ public class VecDeltaCodec {
+ private static final double TRUNCATION_STEPS = 4096.0;
+- private Vec3 base = Vec3.ZERO;
++ public Vec3 base = Vec3.ZERO; // Paper
+
+ @VisibleForTesting
+ static long encode(double value) {
+diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
+index babe11e3c76ebb725ff62d1c77744101ba9b4dec..6e084fd84c76c32319c6a321650ca2bb8332c704 100644
+--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
++++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
+@@ -1519,10 +1519,14 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
+ public void updatePlayer(ServerPlayer player) {
+ org.spigotmc.AsyncCatcher.catchOp("player tracker update"); // Spigot
+ if (player != this.entity) {
+- Vec3 vec3d = player.position().subtract(this.entity.position());
++ // Paper start - remove allocation of Vec3D here
++ // Vec3 vec3d = player.position().subtract(this.entity.position());
++ double vec3d_dx = player.getX() - this.entity.getX();
++ double vec3d_dz = player.getZ() - this.entity.getZ();
++ // Paper end - remove allocation of Vec3D here
+ int i = ChunkMap.this.getPlayerViewDistance(player);
+ double d0 = (double) Math.min(this.getEffectiveRange(), i * 16);
+- double d1 = vec3d.x * vec3d.x + vec3d.z * vec3d.z;
++ double d1 = vec3d_dx * vec3d_dx + vec3d_dz * vec3d_dz; // Paper
+ double d2 = d0 * d0;
+ boolean flag = d1 <= d2 && this.entity.broadcastToPlayer(player) && ChunkMap.this.isChunkTracked(player, this.entity.chunkPosition().x, this.entity.chunkPosition().z);
+ // Paper start - Configurable entity tracking range by Y
+diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
+index a2fbbbd7a66d4e7b1063638f8467e8887a417282..0e7ace92522fbd4cef7b2c2b8a0f8b86c2cce192 100644
+--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
++++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
+@@ -163,7 +163,13 @@ public class ServerEntity {
+ i = Mth.floor(this.entity.getYRot() * 256.0F / 360.0F);
+ j = Mth.floor(this.entity.getXRot() * 256.0F / 360.0F);
+ Vec3 vec3d = this.entity.trackingPosition();
+- boolean flag1 = this.positionCodec.delta(vec3d).lengthSqr() >= 7.62939453125E-6D;
++ // Paper start - reduce allocation of Vec3D here
++ Vec3 base = this.positionCodec.base;
++ double vec3d_dx = vec3d.x - base.x;
++ double vec3d_dy = vec3d.y - base.y;
++ double vec3d_dz = vec3d.z - base.z;
++ boolean flag1 = (vec3d_dx * vec3d_dx + vec3d_dy * vec3d_dy + vec3d_dz * vec3d_dz) >= 7.62939453125E-6D;
++ // Paper end - reduce allocation of Vec3D here
+ Packet<?> packet1 = null;
+ boolean flag2 = flag1 || this.tickCount % 60 == 0;
+ boolean flag3 = Math.abs(i - this.lastSentYRot) >= 1 || Math.abs(j - this.lastSentXRot) >= 1;