Files
KaiijuMC/patches/server/0009-Purpur-Network-Send-Null-Entity-Packets.patch
Sofiane H. Djerbi dbbc862af3 Polyglot server
2023-03-05 19:49:45 +02:00

57 lines
2.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: "Sofiane H. Djerbi" <46628754+kugge@users.noreply.github.com>
Date: Thu, 16 Feb 2023 01:49:54 +0200
Subject: [PATCH] Purpur Network Send Null Entity Packets
diff --git a/src/main/java/dev/kaiijumc/kaiiju/KaiijuConfig.java b/src/main/java/dev/kaiijumc/kaiiju/KaiijuConfig.java
index 2791fe6cc78cc13d969a903134c08e992a6ecdca..276c0e2936dfd3ca752deb65c80565c477f65e7f 100644
--- a/src/main/java/dev/kaiijumc/kaiiju/KaiijuConfig.java
+++ b/src/main/java/dev/kaiijumc/kaiiju/KaiijuConfig.java
@@ -193,6 +193,8 @@ public class KaiijuConfig {
return builder.build();
}
+ public static boolean sendNullEntityPackets = true;
private static void networkSettings() {
+ sendNullEntityPackets = getBoolean("network.send-null-entity-packets", sendNullEntityPackets);
}
}
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
index 0f9a3a6c05fee59c29764f0c0d7a6cb8a2a861b1..9d0a52bf600583ecbf80c2233a01ff43e609266f 100644
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
@@ -186,6 +186,11 @@ public class ServerEntity {
this.teleportDelay = 0;
packet1 = new ClientboundTeleportEntityPacket(this.entity);
}
+ // Kaiiju start - Don't send null move entity packets
+ if (!dev.kaiijumc.kaiiju.KaiijuConfig.sendNullEntityPackets && isNullMovePacket(packet1)) {
+ packet1 = null;
+ }
+ // Kaiiju end
}
if ((this.trackDelta || this.entity.hasImpulse || this.entity instanceof LivingEntity && ((LivingEntity) this.entity).isFallFlying()) && this.tickCount > 0) {
@@ -252,6 +257,20 @@ public class ServerEntity {
}
+ // Kaiiju start - Don't send null move entity packets
+ private boolean isNullMovePacket(Packet<?> packet) {
+ if (packet instanceof ClientboundMoveEntityPacket move) {
+ if (packet instanceof ClientboundMoveEntityPacket.Pos)
+ return move.getXa() == 0 && move.getYa() == 0 && move.getZa() == 0;
+ if (packet instanceof ClientboundMoveEntityPacket.PosRot)
+ return move.getXa() == 0 && move.getYa() == 0 && move.getZa() == 0 && move.getyRot() == 0 && move.getxRot() == 0;
+ if (packet instanceof ClientboundMoveEntityPacket.Rot)
+ return move.getyRot() == 0 && move.getxRot() == 0;
+ }
+ return false;
+ }
+ // Kaiiju end
+
public void removePairing(ServerPlayer player) {
this.entity.stopSeenByPlayer(player);
player.connection.send(new ClientboundRemoveEntitiesPacket(new int[]{this.entity.getId()}));