From b1c5fd68174d38ee203a111c0b77c498419b068d Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Mon, 10 Jun 2019 19:02:32 +1000
Subject: [PATCH] SPIGOT-5054: Prevent issue with invalid hanging entities

---
 nms-patches/EntityHanging.patch | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/nms-patches/EntityHanging.patch b/nms-patches/EntityHanging.patch
index 66e94dd2af..f67f3ff14a 100644
--- a/nms-patches/EntityHanging.patch
+++ b/nms-patches/EntityHanging.patch
@@ -173,3 +173,21 @@
              this.die();
              this.a((Entity) null);
          }
+@@ -168,7 +228,7 @@
+ 
+     @Override
+     public void b(NBTTagCompound nbttagcompound) {
+-        nbttagcompound.setByte("Facing", (byte) this.direction.get2DRotationValue());
++        if (this.direction != null) nbttagcompound.setByte("Facing", (byte) this.direction.get2DRotationValue()); // CraftBukkit
+         BlockPosition blockposition = this.getBlockPosition();
+ 
+         nbttagcompound.setInt("TileX", blockposition.getX());
+@@ -179,7 +239,7 @@
+     @Override
+     public void a(NBTTagCompound nbttagcompound) {
+         this.blockPosition = new BlockPosition(nbttagcompound.getInt("TileX"), nbttagcompound.getInt("TileY"), nbttagcompound.getInt("TileZ"));
+-        this.setDirection(EnumDirection.fromType2(nbttagcompound.getByte("Facing")));
++        if (nbttagcompound.hasKeyOfType("Facing", 99)) this.setDirection(EnumDirection.fromType2(nbttagcompound.getByte("Facing"))); // CraftBukkit
+     }
+ 
+     public abstract int getHangingWidth();