mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-30 12:29:13 +00:00
33 lines
1.9 KiB
Diff
33 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/net/minecraft/server/level/ServerEntity.java b/net/minecraft/server/level/ServerEntity.java
|
|
index bcbc25c6dc5a2063b1ad410194a25b0d5ff7c8d8..936429fd17d8649329e6258a4e10c9e6bf62f6de 100644
|
|
--- a/net/minecraft/server/level/ServerEntity.java
|
|
+++ b/net/minecraft/server/level/ServerEntity.java
|
|
@@ -206,6 +206,7 @@ public class ServerEntity {
|
|
|
|
if (this.entity.hasImpulse || this.trackDelta || this.entity instanceof LivingEntity && ((LivingEntity)this.entity).isFallFlying()) {
|
|
Vec3 deltaMovement = this.entity.getDeltaMovement();
|
|
+ if (deltaMovement != this.lastSentMovement) { // SparklyPaper start - skip distanceToSqr call in ServerEntity#sendChanges if the delta movement hasn't changed
|
|
double d = deltaMovement.distanceToSqr(this.lastSentMovement);
|
|
if (d > 1.0E-7 || d > 0.0 && deltaMovement.lengthSqr() == 0.0) {
|
|
this.lastSentMovement = deltaMovement;
|
|
@@ -223,6 +224,7 @@ public class ServerEntity {
|
|
this.broadcast.accept(new ClientboundSetEntityMotionPacket(this.entity.getId(), this.lastSentMovement));
|
|
}
|
|
}
|
|
+ } // SparklyPaper end
|
|
}
|
|
|
|
if (packet != null) {
|