geforkt von Mirrors/Paper
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:
Ursprung
6364cb2591
Commit
1f44d0b82b
@ -6,7 +6,7 @@ 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
|
||||
@@ -0,0 +0,0 @@ public final class ItemStack {
|
||||
|
@ -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
|
||||
@@ -0,0 +0,0 @@ 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);
|
||||
}
|
||||
@@ -0,0 +0,0 @@ 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
|
||||
@@ -0,0 +0,0 @@ public final class ItemStack {
|
||||
|
||||
public void setTag(@Nullable NBTTagCompound nbttagcompound) {
|
||||
this.tag = nbttagcompound;
|
||||
+ processEnchantOrder(this.tag); // Paper
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -0,0 +0,0 @@ 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
|
||||
@@ -0,0 +0,0 @@ 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
|
||||
@@ -0,0 +0,0 @@ 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
|
||||
@@ -0,0 +0,0 @@ import java.lang.annotation.RetentionPolicy;
|
||||
|
@ -6,7 +6,7 @@ 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
|
||||
@@ -0,0 +0,0 @@ public final class ItemStack {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren