mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
f835a91d15
Upstream has added the equivalent of our SentientNPC API, with exception to the EnderDragon. We've added Mob to the EnderDragon, and our SentientNPC API should behave the same. Vex#getOwner has been deprecated and a replacement Vex#getSummoner has been added using Mob. However, since 1.13 is not production ready, SentientNPC API is subject for removal in 1.13.1 since 1.13 API is not compatible with 1.12. Please move to the Mob interface ASAP. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: c5ab54d8 Expand GameRule API ab9a606c Improve entity hierarchy by adding Mob interface. CraftBukkit Changes:29e75648
Expand GameRule API50e6858b
Improve entity hierarchy by adding Mob interface.0e1d79b4
Correct error in previous patch
89 lines
4.6 KiB
Diff
89 lines
4.6 KiB
Diff
From 8eb9f1f3fa7924ec6fc84d4b18153c32faaee00f Mon Sep 17 00:00:00 2001
|
|
From: Hugo Manrique <hugmanrique@gmail.com>
|
|
Date: Thu, 26 Jul 2018 14:10:23 +0200
|
|
Subject: [PATCH] Don't call getItemMeta on hasItemMeta
|
|
|
|
Spigot 1.13 checks if any field (which are manually copied from the ItemStack's "tag" NBT tag) on the ItemMeta class of an ItemStack is set.
|
|
|
|
We could just check if the "tag" NBT tag is empty, albeit that would break some plugins. The only general tag added on 1.13 is "Damage", and we can just check if the "tag" NBT tag contains any other tag that's not "Damage" (https://minecraft.gamepedia.com/Player.dat_format#Item_structure) making the `hasItemStack` method behave as before.
|
|
|
|
Returns true if getDamage() == 0 or has damage tag or other tag is set.
|
|
Check the `ItemMetaTest#testTaggedButNotMeta` method to see how this method behaves.
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
index 8ca161f0ed..e9bef85c8b 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
@@ -514,7 +514,7 @@ public final class CraftItemStack extends ItemStack {
|
|
|
|
@Override
|
|
public boolean hasItemMeta() {
|
|
- return hasItemMeta(handle) && !CraftItemFactory.instance().equals(getItemMeta(), null);
|
|
+ return hasItemMeta(handle) && (handle.getDamage() != 0 || (handle.getTag() != null && handle.getTag().map.size() >= (handle.getTag().hasKey(CraftMetaItem.DAMAGE.NBT) ? 2 : 1))); // Paper - keep 1.12 CraftBukkit behavior without calling getItemMeta
|
|
}
|
|
|
|
static boolean hasItemMeta(net.minecraft.server.ItemStack item) {
|
|
diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
|
|
index eb6cf1bb33..79ce3752e8 100644
|
|
--- a/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
|
|
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
|
|
@@ -5,6 +5,7 @@ import static org.hamcrest.Matchers.*;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
+import java.util.Collections; // Paper
|
|
import java.util.List;
|
|
import com.destroystokyo.paper.inventory.meta.ArmorStandMeta; // Paper
|
|
import net.minecraft.server.Block;
|
|
@@ -154,8 +155,47 @@ public class ItemMetaTest extends AbstractTestingBase {
|
|
ItemStack pureBukkit = new ItemStack(Material.SHEARS);
|
|
assertThat("Bukkit and craft stacks should be similar", craft.isSimilar(pureBukkit), is(true));
|
|
assertThat("Bukkit and craft stacks should be equal", craft.equals(pureBukkit), is(true));
|
|
+ // Paper start - test additional ItemMeta damage cases
|
|
+ ItemStack clone = CraftItemStack.asBukkitCopy(CraftItemStack.asNMSCopy(craft));
|
|
+ assertThat("Bukkit and craft stacks should be similar", craft.isSimilar(clone), is(true));
|
|
+ assertThat("Bukkit and craft stacks should be equal", craft.equals(clone), is(true));
|
|
+
|
|
+ pureBukkit = new ItemStack(Material.DIAMOND_SWORD);
|
|
+ pureBukkit.setDurability((short) 2);
|
|
+ net.minecraft.server.ItemStack nms = CraftItemStack.asNMSCopy(pureBukkit);
|
|
+ ItemStack other = CraftItemStack.asBukkitCopy(nms);
|
|
+
|
|
+ assertThat("Bukkit and NMS ItemStack copies should be similar", pureBukkit.isSimilar(other), is(true));
|
|
+ assertThat("Bukkit and NMS ItemStack copies should be equal", pureBukkit.equals(other), is(true));
|
|
}
|
|
|
|
+ private void testItemMeta(ItemStack stack) {
|
|
+ assertThat("Should not have ItemMeta", stack.hasItemMeta(), is(false));
|
|
+
|
|
+ stack.setDurability((short) 0);
|
|
+ assertThat("ItemStack with zero durability should not have ItemMeta", stack.hasItemMeta(), is(false));
|
|
+
|
|
+ stack.setDurability((short) 2);
|
|
+ assertThat("ItemStack with non-zero durability should have ItemMeta", stack.hasItemMeta(), is(true));
|
|
+
|
|
+ stack.setLore(Collections.singletonList("Lore"));
|
|
+ assertThat("ItemStack with lore and durability should have ItemMeta", stack.hasItemMeta(), is(true));
|
|
+
|
|
+ stack.setDurability((short) 0);
|
|
+ assertThat("ItemStack with lore should have ItemMeta", stack.hasItemMeta(), is(true));
|
|
+
|
|
+ stack.setLore(null);
|
|
+ }
|
|
+
|
|
+ @Test
|
|
+ public void testHasItemMeta() {
|
|
+ ItemStack itemStack = new ItemStack(Material.SHEARS);
|
|
+
|
|
+ testItemMeta(itemStack);
|
|
+ testItemMeta(CraftItemStack.asCraftCopy(itemStack));
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Test
|
|
public void testBlockStateMeta() {
|
|
List<Block> queue = new ArrayList<>();
|
|
--
|
|
2.18.0
|
|
|