From 202da9777d02a1cf9a01719720319c46b6f3cf31 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Sun, 11 Jun 2017 12:20:18 +1000
Subject: [PATCH] SPIGOT-3324: Best effort fix for shoulder Parrots + cancelled
 damage event

---
 nms-patches/EntityHuman.patch | 46 +++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 18 deletions(-)

diff --git a/nms-patches/EntityHuman.patch b/nms-patches/EntityHuman.patch
index deaef2bba5..a8169999ba 100644
--- a/nms-patches/EntityHuman.patch
+++ b/nms-patches/EntityHuman.patch
@@ -131,8 +131,12 @@
  
      }
  
-@@ -685,7 +743,7 @@
-                 this.releaseShoulderEntities();
+@@ -682,10 +740,10 @@
+                     this.a(true, true, false);
+                 }
+ 
+-                this.releaseShoulderEntities();
++                // this.releaseShoulderEntities(); // CraftBukkit - moved down
                  if (damagesource.r()) {
                      if (this.world.getDifficulty() == EnumDifficulty.PEACEFUL) {
 -                        f = 0.0F;
@@ -140,16 +144,22 @@
                      }
  
                      if (this.world.getDifficulty() == EnumDifficulty.EASY) {
-@@ -697,7 +755,7 @@
+@@ -697,7 +755,13 @@
                      }
                  }
  
 -                return f == 0.0F ? false : super.damageEntity(damagesource, f);
-+                return super.damageEntity(damagesource, f); // CraftBukkit - Don't filter out 0 damage
++                // CraftBukkit start - Don't filter out 0 damage
++                boolean damaged = super.damageEntity(damagesource, f);
++                if (damaged) {
++                    this.releaseShoulderEntities();
++                }
++                return damaged;
++                // CraftBukkit end
              }
          }
      }
-@@ -711,10 +769,29 @@
+@@ -711,10 +775,29 @@
      }
  
      public boolean a(EntityHuman entityhuman) {
@@ -182,7 +192,7 @@
      }
  
      protected void damageArmor(float f) {
-@@ -757,7 +834,12 @@
+@@ -757,7 +840,12 @@
          return (float) i / (float) this.inventory.armor.size();
      }
  
@@ -196,7 +206,7 @@
          if (!this.isInvulnerable(damagesource)) {
              f = this.applyArmorModifier(damagesource, f);
              f = this.applyMagicModifier(damagesource, f);
-@@ -777,6 +859,7 @@
+@@ -777,6 +865,7 @@
  
              }
          }
@@ -204,7 +214,7 @@
      }
  
      public void openSign(TileEntitySign tileentitysign) {}
-@@ -898,8 +981,15 @@
+@@ -898,8 +987,15 @@
                      if (entity instanceof EntityLiving) {
                          f3 = ((EntityLiving) entity).getHealth();
                          if (j > 0 && !entity.isBurning()) {
@@ -222,7 +232,7 @@
                          }
                      }
  
-@@ -930,8 +1020,11 @@
+@@ -930,8 +1026,11 @@
                                  EntityLiving entityliving = (EntityLiving) iterator.next();
  
                                  if (entityliving != this && entityliving != entity && !this.r(entityliving) && this.h(entityliving) < 9.0D) {
@@ -235,7 +245,7 @@
                                  }
                              }
  
-@@ -940,11 +1033,28 @@
+@@ -940,11 +1039,28 @@
                          }
  
                          if (entity instanceof EntityPlayer && entity.velocityChanged) {
@@ -264,7 +274,7 @@
                          }
  
                          if (flag2) {
-@@ -993,7 +1103,14 @@
+@@ -993,7 +1109,14 @@
  
                              this.a(StatisticList.y, Math.round(f5 * 10.0F));
                              if (j > 0) {
@@ -280,7 +290,7 @@
                              }
  
                              if (this.world instanceof WorldServer && f5 > 2.0F) {
-@@ -1009,6 +1126,11 @@
+@@ -1009,6 +1132,11 @@
                          if (flag4) {
                              entity.extinguish();
                          }
@@ -292,7 +302,7 @@
                      }
                  }
  
-@@ -1099,6 +1221,20 @@
+@@ -1099,6 +1227,20 @@
              this.stopRiding();
          }
  
@@ -313,7 +323,7 @@
          this.releaseShoulderEntities();
          this.setSize(0.2F, 0.2F);
          if (this.world.isLoaded(blockposition)) {
-@@ -1159,6 +1295,23 @@
+@@ -1159,6 +1301,23 @@
              this.world.everyoneSleeping();
          }
  
@@ -337,7 +347,7 @@
          this.sleepTicks = flag ? 0 : 100;
          if (flag2) {
              this.setRespawnPosition(this.bedPosition, false);
-@@ -1210,9 +1363,11 @@
+@@ -1210,9 +1369,11 @@
          if (blockposition != null) {
              this.d = blockposition;
              this.e = flag;
@@ -349,7 +359,7 @@
          }
  
      }
-@@ -1540,13 +1695,17 @@
+@@ -1540,13 +1701,17 @@
      }
  
      protected void releaseShoulderEntities() {
@@ -372,7 +382,7 @@
          if (!this.world.isClientSide && !nbttagcompound.isEmpty()) {
              Entity entity = EntityTypes.a(nbttagcompound, this.world);
  
-@@ -1555,9 +1714,10 @@
+@@ -1555,9 +1720,10 @@
              }
  
              entity.setPosition(this.locX, this.locY + 0.699999988079071D, this.locZ);
@@ -384,7 +394,7 @@
      }
  
      public abstract boolean isSpectator();
-@@ -1759,7 +1919,7 @@
+@@ -1759,7 +1925,7 @@
              return entitymonster.c(this.a);
          }