mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-23 17:09:29 +00:00
32 lines
1.9 KiB
Diff
32 lines
1.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
|
Date: Wed, 15 Nov 2023 23:39:36 -0300
|
|
Subject: [PATCH] SparklyPaper: Skip "distanceToSqr" call in
|
|
"ServerEntity#sendChanges" if the delta movement hasn't changed
|
|
|
|
Original project: https://github.com/SparklyPower/SparklyPaper
|
|
|
|
The "distanceToSqr" call is a bit expensive, so avoiding it is pretty nice, around ~15% calls are skipped with this check
|
|
|
|
We could also check if the x,y,z coordinates are equal, but for now, let's just keep the identity check, which also helps us since Minecraft's code does reuse the original delta movement Vec3 object
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
index fb93f3400ac693f28fb25e5d370d0f6dae8e120a..5a17ccd4a620f17c6434f457244ae2b790e2f34e 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
@@ -230,12 +230,14 @@ public class ServerEntity {
|
|
|
|
if ((this.trackDelta || this.entity.hasImpulse || this.entity instanceof LivingEntity && ((LivingEntity) this.entity).isFallFlying()) && this.tickCount > 0) {
|
|
Vec3 vec3d1 = this.entity.getDeltaMovement();
|
|
+ if (vec3d1 != this.ap) { // SparklyPaper start - skip distanceToSqr call in ServerEntity#sendChanges if the delta movement hasn't changed
|
|
double d0 = vec3d1.distanceToSqr(this.ap);
|
|
|
|
if (d0 > 1.0E-7D || d0 > 0.0D && vec3d1.lengthSqr() == 0.0D) {
|
|
this.ap = vec3d1;
|
|
this.broadcast.accept(new ClientboundSetEntityMotionPacket(this.entity.getId(), this.ap));
|
|
}
|
|
+ } // SparklyPaper end
|
|
}
|
|
|
|
if (packet1 != null) {
|