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/EntityTrackerEntry.java b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
index 2402c18e6a18221a43bea9fc68278da9d19eede4..e51b6bd0698593867e6821326d223770766d717f 100644
--- a/src/main/java/net/minecraft/server/EntityTrackerEntry.java
+++ b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
@@ -172,6 +172,7 @@ public class EntityTrackerEntry {
                         this.o = 0;
                         packet1 = new PacketPlayOutEntityTeleport(this.tracker);
                     }
+                    if (net.pl3x.purpur.PurpurConfig.dontSendUselessEntityPackets && isUselessPacket(packet1)) packet1 = null; // Purpur
                 }
 
                 if ((this.e || this.tracker.impulse || this.tracker instanceof EntityLiving && ((EntityLiving) this.tracker).isGliding()) && this.tickCounter > 0) {
@@ -258,6 +259,22 @@ public class EntityTrackerEntry {
 
     }
 
+    // Purpur start
+    private boolean isUselessPacket(Packet<?> possibleUselessPacket) {
+        if (possibleUselessPacket instanceof PacketPlayOutEntity) {
+            PacketPlayOutEntity packet = (PacketPlayOutEntity) possibleUselessPacket;
+            if (possibleUselessPacket instanceof PacketPlayOutEntity.PacketPlayOutRelEntityMove) {
+                return packet.getX() == 0 && packet.getY() == 0 && packet.getZ() == 0;
+            } else if (possibleUselessPacket instanceof PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook) {
+                return packet.getX() == 0 && packet.getY() == 0 && packet.getZ() == 0 && packet.getYaw() == 0 && packet.getPitch() == 0;
+            } else if (possibleUselessPacket instanceof PacketPlayOutEntity.PacketPlayOutEntityLook) {
+                return packet.getYaw() == 0 && packet.getPitch() == 0;
+            }
+        }
+        return false;
+    }
+    // Purpur end
+
     public void a(EntityPlayer entityplayer) {
         this.tracker.c(entityplayer);
         entityplayer.c(this.tracker);
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutEntity.java b/src/main/java/net/minecraft/server/PacketPlayOutEntity.java
index 8e48407fd405ac4c3eece7762b8155c5d0f00fa0..91c4e658230bb8bbce9d0f56db0768a7c09f0095 100644
--- a/src/main/java/net/minecraft/server/PacketPlayOutEntity.java
+++ b/src/main/java/net/minecraft/server/PacketPlayOutEntity.java
@@ -5,11 +5,11 @@ import java.io.IOException;
 public class PacketPlayOutEntity implements Packet<PacketListenerPlayOut> {
 
     protected int a;
-    protected short b;
-    protected short c;
-    protected short d;
-    protected byte e;
-    protected byte f;
+    protected short b; public short getX() { return b; } // Purpur - OBFHELPER
+    protected short c; public short getY() { return c; } // Purpur - OBFHELPER
+    protected short d; public short getZ() { return d; } // Purpur - OBFHELPER
+    protected byte e; public byte getYaw() { return e; } // Purpur - OBFHELPER
+    protected byte f; public byte getPitch() { return f; } // Purpur - OBFHELPER
     protected boolean g;
     protected boolean h;
     protected boolean i;
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
index ec8efc913f8f0bf6ff559a3a5b439a3d24f3a9b6..a2f3c5c81d93814f89a778c8c58d36b416ea1efc 100644
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
@@ -179,6 +179,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() {
