From e9b89119e0128efdf9a0694ed7494e804c07ded6 Mon Sep 17 00:00:00 2001
From: CraftBukkit/Spigot <noreply+git-craftbukkit@papermc.io>
Date: Thu, 25 Apr 2019 09:55:41 +1000
Subject: [PATCH] SPIGOT-4734: Sign placement fails when looking at grass

By: md_5 <git@md-5.net>
---
 paper-server/nms-patches/ItemSign.patch  |  4 ++--
 paper-server/nms-patches/ItemStack.patch | 25 +++++++++++++-----------
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/paper-server/nms-patches/ItemSign.patch b/paper-server/nms-patches/ItemSign.patch
index df9c5018fd..ea5b6ece5b 100644
--- a/paper-server/nms-patches/ItemSign.patch
+++ b/paper-server/nms-patches/ItemSign.patch
@@ -4,7 +4,7 @@
  
  public class ItemSign extends ItemBlockWallable {
  
-+    public static boolean openSign; // CraftBukkit
++    public static BlockPosition openSign; // CraftBukkit
 +
      public ItemSign(Item.Info item_info, Block block, Block block1) {
          super(block, block1, item_info);
@@ -16,7 +16,7 @@
 -            entityhuman.openSign((TileEntitySign) world.getTileEntity(blockposition));
 +            // CraftBukkit start - SPIGOT-4678
 +            // entityhuman.openSign((TileEntitySign) world.getTileEntity(blockposition));
-+            ItemSign.openSign = true;
++            ItemSign.openSign = blockposition;
 +            // CraftBukkit end
          }
  
diff --git a/paper-server/nms-patches/ItemStack.patch b/paper-server/nms-patches/ItemStack.patch
index 1b298803c9..be4c497492 100644
--- a/paper-server/nms-patches/ItemStack.patch
+++ b/paper-server/nms-patches/ItemStack.patch
@@ -80,7 +80,7 @@
          EntityHuman entityhuman = itemactioncontext.getEntity();
          BlockPosition blockposition = itemactioncontext.getClickPosition();
          ShapeDetectorBlock shapedetectorblock = new ShapeDetectorBlock(itemactioncontext.getWorld(), blockposition, false);
-@@ -104,12 +141,150 @@
+@@ -104,12 +141,153 @@
          if (entityhuman != null && !entityhuman.abilities.mayBuild && !this.b(itemactioncontext.getWorld().t(), shapedetectorblock)) {
              return EnumInteractionResult.PASS;
          } else {
@@ -212,9 +212,12 @@
 +                    }
 +
 +                    // SPIGOT-4678
-+                    if (this.item instanceof ItemSign && ItemSign.openSign) {
-+                        ItemSign.openSign = false;
-+                        entityhuman.openSign((TileEntitySign) world.getTileEntity(new BlockActionContext(itemactioncontext).getClickPosition()));
++                    if (this.item instanceof ItemSign && ItemSign.openSign != null) {
++                        try {
++                            entityhuman.openSign((TileEntitySign) world.getTileEntity(ItemSign.openSign));
++                        } finally {
++                            ItemSign.openSign = null;
++                        }
 +                    }
 +
 +                    // SPIGOT-1288 - play sound stripped from ItemBlock
@@ -232,7 +235,7 @@
  
              return enuminteractionresult;
          }
-@@ -133,7 +308,7 @@
+@@ -133,7 +311,7 @@
          nbttagcompound.setString("id", minecraftkey == null ? "minecraft:air" : minecraftkey.toString());
          nbttagcompound.setByte("Count", (byte) this.count);
          if (this.tag != null) {
@@ -241,7 +244,7 @@
          }
  
          return nbttagcompound;
-@@ -166,6 +341,12 @@
+@@ -166,6 +344,12 @@
      }
  
      public void setDamage(int i) {
@@ -254,7 +257,7 @@
          this.getOrCreateTag().setInt("Damage", Math.max(0, i));
      }
  
-@@ -190,6 +371,21 @@
+@@ -190,6 +374,21 @@
                  }
  
                  i -= k;
@@ -276,7 +279,7 @@
                  if (i <= 0) {
                      return false;
                  }
-@@ -211,6 +407,11 @@
+@@ -211,6 +410,11 @@
                  if (this.isDamaged(i, t0.getRandom(), t0 instanceof EntityPlayer ? (EntityPlayer) t0 : null)) {
                      consumer.accept(t0);
                      Item item = this.getItem();
@@ -288,7 +291,7 @@
  
                      this.subtract(1);
                      if (t0 instanceof EntityHuman) {
-@@ -338,6 +539,17 @@
+@@ -338,6 +542,17 @@
          return this.tag;
      }
  
@@ -306,7 +309,7 @@
      public NBTTagCompound getOrCreateTag() {
          if (this.tag == null) {
              this.setTag(new NBTTagCompound());
-@@ -482,6 +694,12 @@
+@@ -482,6 +697,12 @@
      }
  
      public void setRepairCost(int i) {
@@ -319,7 +322,7 @@
          this.getOrCreateTag().setInt("RepairCost", i);
      }
  
-@@ -524,6 +742,13 @@
+@@ -524,6 +745,13 @@
          nbttaglist.add(nbttagcompound);
      }