Archiviert
13
0

Auto sort enchants on items - Fixes #915

This ensures that enchants are never added in inconsistent order.
The client shows the enchants in a sorted order already

This will auto fix previously created items too on load.
Dieser Commit ist enthalten in:
Aikar 2017-12-19 17:56:13 -05:00
Ursprung 7fb767fe41
Commit 2603e833f7
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 401ADFC9891FAAFE
3 geänderte Dateien mit 80 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -1,4 +1,4 @@
From 5320ce6f08793e99128863e2dc9419b009caa2c3 Mon Sep 17 00:00:00 2001
From 00260e9433c13cfcf1dee3927ee3a9e905c4a8dc Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Thu, 28 May 2015 23:00:19 -0400
Subject: [PATCH] Handle Item Meta Inconsistencies
@ -17,8 +17,76 @@ was added, resulting in 2 different ways to modify an items enchantments.
For consistency, the old API methods now forward to use the
ItemMeta API equivalents, and should deprecate the old API's.
diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
index 0dcea61d2..a8f7ff98f 100644
--- a/src/main/java/net/minecraft/server/ItemStack.java
+++ b/src/main/java/net/minecraft/server/ItemStack.java
@@ -56,6 +56,22 @@ public final class ItemStack {
}
// CraftBukkit start
+ // Paper start
+ private static final java.util.Comparator<NBTTagCompound> enchantSorter = java.util.Comparator.comparingInt(o -> o.getShort("id"));
+ private void processEnchantOrder(NBTTagCompound tag) {
+ if (tag == null || !tag.hasKeyOfType("ench", 9)) {
+ return;
+ }
+ NBTTagList list = tag.getList("ench", 10);
+ if (list.size() < 2) {
+ return;
+ }
+ try {
+ list.sort(enchantSorter); // Paper
+ } catch (Exception ignored) {}
+ }
+ // Paper end
+
public ItemStack(Item item, int i, int j) {
this(item, i, j, true);
}
@@ -113,6 +129,7 @@ public final class ItemStack {
if (nbttagcompound.hasKeyOfType("tag", 10)) {
// CraftBukkit start - make defensive copy as this data may be coming from the save thread
this.tag = (NBTTagCompound) nbttagcompound.getCompound("tag").clone();
+ processEnchantOrder(this.tag); // Paper
if (this.item != null) {
this.item.a(this.tag);
// CraftBukkit end
@@ -585,6 +602,7 @@ public final class ItemStack {
public void setTag(@Nullable NBTTagCompound nbttagcompound) {
this.tag = nbttagcompound;
+ processEnchantOrder(this.tag); // Paper
}
public String getName() {
@@ -658,6 +676,7 @@ public final class ItemStack {
nbttagcompound.setShort("id", (short) Enchantment.getId(enchantment));
nbttagcompound.setShort("lvl", (short) ((byte) i));
nbttaglist.add(nbttagcompound);
+ processEnchantOrder(nbttagcompound); // Paper
}
public boolean hasEnchantments() {
diff --git a/src/main/java/net/minecraft/server/NBTTagList.java b/src/main/java/net/minecraft/server/NBTTagList.java
index ca9eb2f3b..576c3b714 100644
--- a/src/main/java/net/minecraft/server/NBTTagList.java
+++ b/src/main/java/net/minecraft/server/NBTTagList.java
@@ -14,6 +14,12 @@ public class NBTTagList extends NBTBase {
private static final Logger b = LogManager.getLogger();
public List<NBTBase> list = Lists.newArrayList(); // Paper
+ // Paper start
+ public void sort(java.util.Comparator<? extends NBTBase> comparator) {
+ //noinspection unchecked
+ java.util.Collections.sort(list, (java.util.Comparator<NBTBase>) comparator);
+ }
+ // Paper end
private byte type = 0;
public NBTTagList() {}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
index 3f11e427..ebb3e04b 100644
index fb1dc542d..cdf16e15a 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
@@ -4,6 +4,7 @@ import static org.bukkit.craftbukkit.inventory.CraftMetaItem.ENCHANTMENTS;
@ -144,7 +212,7 @@ index 3f11e427..ebb3e04b 100644
static Map<Enchantment, Integer> getEnchantments(net.minecraft.server.ItemStack item) {
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
index c743ae06..0cdc8007 100644
index c743ae066..0cdc8007a 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
@@ -6,13 +6,8 @@ import java.lang.annotation.RetentionPolicy;
@ -290,5 +358,5 @@ index c743ae06..0cdc8007 100644
private final Spigot spigot = new Spigot()
{
--
2.11.0
2.15.1

Datei anzeigen

@ -1,4 +1,4 @@
From 26b973aadf97eaaa7083ac46b35ae44ad3737f9b Mon Sep 17 00:00:00 2001
From 2c8061d8d05a237415c7d1f968a3d4b254121f3a Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 21 Dec 2016 03:48:29 -0500
Subject: [PATCH] Optimize ItemStack.isEmpty()
@ -6,10 +6,10 @@ Subject: [PATCH] Optimize ItemStack.isEmpty()
Remove hashMap lookup every check, simplify code to remove ternary
diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
index 0dcea61d2..3aefb023e 100644
index a8f7ff98f..9465f4c16 100644
--- a/src/main/java/net/minecraft/server/ItemStack.java
+++ b/src/main/java/net/minecraft/server/ItemStack.java
@@ -126,9 +126,15 @@ public final class ItemStack {
@@ -143,9 +143,15 @@ public final class ItemStack {
this.F();
}
@ -27,5 +27,5 @@ index 0dcea61d2..3aefb023e 100644
public static void a(DataConverterManager dataconvertermanager) {
dataconvertermanager.a(DataConverterTypes.ITEM_INSTANCE, (DataInspector) (new DataInspectorBlockEntity()));
--
2.14.2
2.15.1

Datei anzeigen

@ -1,4 +1,4 @@
From ecf214d5296e6e15188e49b0511d750fd4f6c433 Mon Sep 17 00:00:00 2001
From 3b83740b6ac7de77a90e25cc3d9eb986266f250f Mon Sep 17 00:00:00 2001
From: kashike <kashike@vq.lc>
Date: Sun, 9 Apr 2017 23:50:15 -0700
Subject: [PATCH] Fix NFE when attempting to read EMPTY ItemStack
@ -6,10 +6,10 @@ Subject: [PATCH] Fix NFE when attempting to read EMPTY ItemStack
Thanks @gabizou
diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
index 3aefb023e..8c7f57bc7 100644
index 9465f4c16..52cb34abd 100644
--- a/src/main/java/net/minecraft/server/ItemStack.java
+++ b/src/main/java/net/minecraft/server/ItemStack.java
@@ -103,7 +103,7 @@ public final class ItemStack {
@@ -119,7 +119,7 @@ public final class ItemStack {
// CraftBukkit - break into own method
public void load(NBTTagCompound nbttagcompound) {
@ -19,5 +19,5 @@ index 3aefb023e..8c7f57bc7 100644
// CraftBukkit start - Route through setData for filtering
// this.damage = Math.max(0, nbttagcompound.getShort("Damage"));
--
2.14.2
2.15.1