From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Sat, 6 Jul 2019 17:00:04 -0500
Subject: [PATCH] Dont send useless entity packets


diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
index 7eb6614c126d03435689a92c0064baffd446ec5e..61c4d3ec612195f31bcce7e5d46d012767c5e231 100644
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
@@ -190,6 +190,7 @@ public class ServerEntity {
                         this.teleportDelay = 0;
                         packet1 = new ClientboundTeleportEntityPacket(this.entity);
                     }
+                    if (net.pl3x.purpur.PurpurConfig.dontSendUselessEntityPackets && isUselessPacket(packet1)) packet1 = null; // Purpur
                 }
 
                 if ((this.trackDelta || this.entity.hasImpulse || this.entity instanceof LivingEntity && ((LivingEntity) this.entity).isFallFlying()) && this.tickCount > 0) {
@@ -258,6 +259,22 @@ public class ServerEntity {
 
     }
 
+    // Purpur start
+    private boolean isUselessPacket(Packet<?> possibleUselessPacket) {
+        if (possibleUselessPacket instanceof ClientboundMoveEntityPacket) {
+            ClientboundMoveEntityPacket packet = (ClientboundMoveEntityPacket) possibleUselessPacket;
+            if (possibleUselessPacket instanceof ClientboundMoveEntityPacket.Pos) {
+                return packet.getXa() == 0 && packet.getYa() == 0 && packet.getZa() == 0;
+            } else if (possibleUselessPacket instanceof ClientboundMoveEntityPacket.PosRot) {
+                return packet.getXa() == 0 && packet.getYa() == 0 && packet.getZa() == 0 && packet.getyRot() == 0 && packet.getxRot() == 0;
+            } else if (possibleUselessPacket instanceof ClientboundMoveEntityPacket.Rot) {
+                return packet.getyRot() == 0 && packet.getxRot() == 0;
+            }
+        }
+        return false;
+    }
+    // Purpur end
+
     public void removePairing(ServerPlayer player) {
         this.entity.stopSeenByPlayer(player);
         player.connection.send(new ClientboundRemoveEntitiesPacket(new int[]{this.entity.getId()}));
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
index ce0648631f5a63d4872e04f6615ca097be5f3d17..cc1b102949e9236b8b7960e76f712348c9e02022 100644
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
@@ -217,6 +217,11 @@ public class PurpurConfig {
         enderChestPermissionRows = getBoolean("settings.blocks.ender_chest.use-permissions-for-rows", enderChestPermissionRows);
     }
 
+    public static boolean dontSendUselessEntityPackets = false;
+    private static void dontSendUselessEntityPackets() {
+        dontSendUselessEntityPackets = getBoolean("settings.dont-send-useless-entity-packets", dontSendUselessEntityPackets);
+    }
+
     public static boolean loggerSuppressInitLegacyMaterialError = false;
     public static boolean loggerSuppressIgnoredAdvancementWarnings = false;
     private static void loggerSettings() {
