2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Spottedleaf <spottedleaf@spottedleaf.dev>
|
|
|
|
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/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
2021-11-26 23:58:39 +01:00
|
|
|
index 0d4d400b6f0b0d939dac7887da793c21ac6bfb1b..f4fddfcb33ae463c6a86e7282d069279258bc4ff 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
2021-11-26 23:58:39 +01:00
|
|
|
@@ -1861,9 +1861,13 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
2021-06-11 14:02:28 +02:00
|
|
|
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()); // MC-155077, SPIGOT-5113
|
|
|
|
+ // Paper start - remove allocation of Vec3D here
|
2021-11-24 12:38:00 +01:00
|
|
|
+ //Vec3 vec3d = player.position().subtract(this.entity.position()); // MC-155077, SPIGOT-5113
|
2021-06-11 14:02:28 +02:00
|
|
|
+ double vec3d_dx = player.getX() - this.entity.getX();
|
|
|
|
+ double vec3d_dz = player.getZ() - this.entity.getZ();
|
|
|
|
+ // Paper end - remove allocation of Vec3D here
|
2021-11-24 12:38:00 +01:00
|
|
|
double d0 = (double) Math.min(this.getEffectiveRange(), (ChunkMap.this.viewDistance - 1) * 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);
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
2021-11-24 12:38:00 +01:00
|
|
|
index ceba19ea3bb9664899b83f82f28af06476b7ff56..f6b6ac1ab31c364646151866c54c9e46dee12516 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
2021-11-24 12:38:00 +01:00
|
|
|
@@ -143,8 +143,12 @@ public class ServerEntity {
|
2021-06-11 14:02:28 +02:00
|
|
|
++this.teleportDelay;
|
2021-06-14 07:32:56 +02:00
|
|
|
i = Mth.floor(this.entity.getYRot() * 256.0F / 360.0F);
|
|
|
|
j = Mth.floor(this.entity.getXRot() * 256.0F / 360.0F);
|
2021-06-11 14:02:28 +02:00
|
|
|
- Vec3 vec3d = this.entity.position().subtract(ClientboundMoveEntityPacket.packetToEntity(this.xp, this.yp, this.zp));
|
|
|
|
- boolean flag1 = vec3d.lengthSqr() >= 7.62939453125E-6D;
|
|
|
|
+ // Paper start - reduce allocation of Vec3D here
|
|
|
|
+ double vec3d_dx = this.entity.getX() - 2.44140625E-4D*(this.xp);
|
|
|
|
+ double vec3d_dy = this.entity.getY() - 2.44140625E-4D*(this.yp);
|
|
|
|
+ double vec3d_dz = this.entity.getZ() - 2.44140625E-4D*(this.zp);
|
|
|
|
+ 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.yRotp) >= 1 || Math.abs(j - this.xRotp) >= 1;
|
2021-11-24 12:38:00 +01:00
|
|
|
@@ -161,9 +165,11 @@ public class ServerEntity {
|
2021-06-11 14:02:28 +02:00
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
if (this.tickCount > 0 || this.entity instanceof AbstractArrow) {
|
|
|
|
- long k = ClientboundMoveEntityPacket.entityToPacket(vec3d.x);
|
|
|
|
- long l = ClientboundMoveEntityPacket.entityToPacket(vec3d.y);
|
|
|
|
- long i1 = ClientboundMoveEntityPacket.entityToPacket(vec3d.z);
|
|
|
|
+ // Paper start - remove allocation of Vec3D here
|
|
|
|
+ long k = ClientboundMoveEntityPacket.entityToPacket(vec3d_dx);
|
|
|
|
+ long l = ClientboundMoveEntityPacket.entityToPacket(vec3d_dy);
|
|
|
|
+ long i1 = ClientboundMoveEntityPacket.entityToPacket(vec3d_dz);
|
|
|
|
+ // Paper end - remove allocation of Vec3D here
|
|
|
|
boolean flag4 = k < -32768L || k > 32767L || l < -32768L || l > 32767L || i1 < -32768L || i1 > 32767L;
|
|
|
|
|
|
|
|
if (!flag4 && this.teleportDelay <= 400 && !this.wasRiding && this.wasOnGround == this.entity.isOnGround()) {
|