NOT FINISHED!!! Current Progress on 1.13-pre7 update
This work is 100% unfinished. I am pushing it up so that we as a team can work on this update. Do not try to use this branch. You will fail.
This commit is contained in:
@@ -18,40 +18,49 @@ 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 82d72ea15..5047a57e9 100644
|
||||
index 7f249a975..70f2dcc9e 100644
|
||||
--- a/src/main/java/net/minecraft/server/ItemStack.java
|
||||
+++ b/src/main/java/net/minecraft/server/ItemStack.java
|
||||
@@ -0,0 +0,0 @@ import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
+import java.util.Collections;
|
||||
+import java.util.Comparator;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
@@ -0,0 +0,0 @@ public final class ItemStack {
|
||||
decimalformat.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance(Locale.ROOT));
|
||||
return decimalformat;
|
||||
}
|
||||
|
||||
// CraftBukkit start
|
||||
+ // Paper start
|
||||
+ private static final java.util.Comparator<NBTTagCompound> enchantSorter = java.util.Comparator.comparingInt(o -> o.getShort("id"));
|
||||
+ private static final java.util.Comparator<? super NBTTagCompound> enchantSorter = java.util.Comparator.comparing(o -> o.getString("id"));
|
||||
+ private void processEnchantOrder(NBTTagCompound tag) {
|
||||
+ if (tag == null || !tag.hasKeyOfType("ench", 9)) {
|
||||
+ if (tag == null || !tag.hasKeyOfType("Enchantments", 9)) {
|
||||
+ return;
|
||||
+ }
|
||||
+ NBTTagList list = tag.getList("ench", 10);
|
||||
+ NBTTagList list = tag.getList("Enchantments", 10);
|
||||
+ if (list.size() < 2) {
|
||||
+ return;
|
||||
+ }
|
||||
+ try {
|
||||
+ list.sort(enchantSorter); // Paper
|
||||
+ //noinspection unchecked
|
||||
+ list.sort((Comparator<? super NBTBase>) enchantSorter); // Paper
|
||||
+ } catch (Exception ignored) {}
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
public ItemStack(Item item, int i, int j) {
|
||||
this(item, i, j, true);
|
||||
}
|
||||
|
||||
public ItemStack(IMaterial imaterial) {
|
||||
this(imaterial, 1);
|
||||
@@ -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
|
||||
this.getItem().a(this.tag);
|
||||
// CraftBukkit end
|
||||
}
|
||||
@@ -0,0 +0,0 @@ public final class ItemStack {
|
||||
// Paper end
|
||||
public void setTag(@Nullable NBTTagCompound nbttagcompound) {
|
||||
@@ -59,34 +68,17 @@ index 82d72ea15..5047a57e9 100644
|
||||
+ processEnchantOrder(this.tag); // Paper
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
public IChatBaseComponent getName() {
|
||||
@@ -0,0 +0,0 @@ public final class ItemStack {
|
||||
nbttagcompound.setShort("id", (short) Enchantment.getId(enchantment));
|
||||
nbttagcompound.setString("id", String.valueOf(Enchantment.enchantments.b(enchantment)));
|
||||
nbttagcompound.setShort("lvl", (short) ((byte) i));
|
||||
nbttaglist.add(nbttagcompound);
|
||||
nbttaglist.add((NBTBase) 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 fb1dc542d..cdf16e15a 100644
|
||||
index 4c4f04557..cb3b952e2 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;
|
||||
@@ -113,14 +105,14 @@ index fb1dc542d..cdf16e15a 100644
|
||||
-
|
||||
- for (int i = 0; i < size; i++) {
|
||||
- NBTTagCompound tag = (NBTTagCompound) list.get(i);
|
||||
- short id = tag.getShort(ENCHANTMENTS_ID.NBT);
|
||||
- if (id == ench.getId()) {
|
||||
- String id = tag.getString(ENCHANTMENTS_ID.NBT);
|
||||
- if (id.equals(ench.getKey().toString())) {
|
||||
- tag.setShort(ENCHANTMENTS_LVL.NBT, (short) level);
|
||||
- return;
|
||||
- }
|
||||
- }
|
||||
- NBTTagCompound tag = new NBTTagCompound();
|
||||
- tag.setShort(ENCHANTMENTS_ID.NBT, (short) ench.getId());
|
||||
- tag.setString(ENCHANTMENTS_ID.NBT, ench.getKey().toString());
|
||||
- tag.setShort(ENCHANTMENTS_LVL.NBT, (short) level);
|
||||
- list.add(tag);
|
||||
+ // Paper start - Replace whole method
|
||||
@@ -146,13 +138,13 @@ index fb1dc542d..cdf16e15a 100644
|
||||
- return 0;
|
||||
- }
|
||||
- return EnchantmentManager.getEnchantmentLevel(CraftEnchantment.getRaw(ench), handle);
|
||||
+ return hasItemMeta() ? getItemMeta().getEnchantLevel(ench) : 0; // Pape - replace entire method with meta
|
||||
+ return hasItemMeta() ? getItemMeta().getEnchantLevel(ench) : 0; // Paper - replace entire method with meta
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeEnchantment(Enchantment ench) {
|
||||
Validate.notNull(ench, "Cannot remove null enchantment");
|
||||
-
|
||||
|
||||
- NBTTagList list = getEnchantmentList(handle), listCopy;
|
||||
- if (list == null) {
|
||||
- return 0;
|
||||
@@ -163,8 +155,8 @@ index fb1dc542d..cdf16e15a 100644
|
||||
-
|
||||
- for (int i = 0; i < size; i++) {
|
||||
- NBTTagCompound enchantment = (NBTTagCompound) list.get(i);
|
||||
- int id = 0xffff & enchantment.getShort(ENCHANTMENTS_ID.NBT);
|
||||
- if (id == ench.getId()) {
|
||||
- String id = enchantment.getString(ENCHANTMENTS_ID.NBT);
|
||||
- if (id.equals(ench.getKey().toString())) {
|
||||
- index = i;
|
||||
- level = 0xffff & enchantment.getShort(ENCHANTMENTS_LVL.NBT);
|
||||
- break;
|
||||
@@ -212,53 +204,42 @@ index fb1dc542d..cdf16e15a 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 c743ae066..0cdc8007a 100644
|
||||
index 3b73e52fa..e43a24989 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;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Constructor;
|
||||
@@ -0,0 +0,0 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
-import java.util.ArrayList;
|
||||
-import java.util.Collection;
|
||||
-import java.util.HashMap;
|
||||
-import java.util.List;
|
||||
-import java.util.Map;
|
||||
-import java.util.NoSuchElementException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
+import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import net.minecraft.server.IChatBaseComponent;
|
||||
+import com.google.common.collect.ImmutableSortedMap;
|
||||
import net.minecraft.server.NBTBase;
|
||||
import net.minecraft.server.NBTTagCompound;
|
||||
import net.minecraft.server.NBTTagList;
|
||||
@@ -0,0 +0,0 @@ import com.google.common.collect.Sets;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
+import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
+import java.util.Collection;
|
||||
+import java.util.Comparator;
|
||||
@@ -0,0 +0,0 @@ import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
+import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
+import java.util.List;
|
||||
+import java.util.Map;
|
||||
+import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
+import java.util.TreeMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.server.NBTCompressedStreamTools;
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
||||
private String displayName;
|
||||
private String locName;
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
private IChatBaseComponent displayName;
|
||||
private IChatBaseComponent locName;
|
||||
private List<String> lore;
|
||||
- private Map<Enchantment, Integer> enchantments;
|
||||
+ private EnchantmentMap enchantments; // Paper
|
||||
private int repairCost;
|
||||
private int hideFlag;
|
||||
private boolean unbreakable;
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
private static final Set<String> HANDLED_TAGS = Sets.newHashSet();
|
||||
|
||||
private NBTTagCompound internalTag;
|
||||
@@ -267,7 +248,7 @@ index c743ae066..0cdc8007a 100644
|
||||
|
||||
CraftMetaItem(CraftMetaItem meta) {
|
||||
if (meta == null) {
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
}
|
||||
|
||||
if (meta.enchantments != null) { // Spigot
|
||||
@@ -276,7 +257,7 @@ index c743ae066..0cdc8007a 100644
|
||||
}
|
||||
|
||||
this.repairCost = meta.repairCost;
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,8 +272,8 @@ index c743ae066..0cdc8007a 100644
|
||||
+ EnchantmentMap enchantments = new EnchantmentMap(); // Paper
|
||||
|
||||
for (int i = 0; i < ench.size(); i++) {
|
||||
int id = 0xffff & ((NBTTagCompound) ench.get(i)).getShort(ENCHANTMENTS_ID.NBT);
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
||||
String id = ((NBTTagCompound) ench.get(i)).getString(ENCHANTMENTS_ID.NBT);
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
void deserializeInternal(NBTTagCompound tag) {
|
||||
}
|
||||
|
||||
@@ -308,7 +289,7 @@ index c743ae066..0cdc8007a 100644
|
||||
for (Map.Entry<?, ?> entry : ench.entrySet()) {
|
||||
// Doctor older enchants
|
||||
String enchantKey = entry.getKey().toString();
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
}
|
||||
|
||||
public Map<Enchantment, Integer> getEnchants() {
|
||||
@@ -324,7 +305,7 @@ index c743ae066..0cdc8007a 100644
|
||||
}
|
||||
|
||||
if (ignoreRestrictions || level >= ench.getStartLevel() && level <= ench.getMaxLevel()) {
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
clone.lore = new ArrayList<String>(this.lore);
|
||||
}
|
||||
if (this.enchantments != null) {
|
||||
@@ -333,7 +314,7 @@ index c743ae066..0cdc8007a 100644
|
||||
}
|
||||
clone.hideFlag = this.hideFlag;
|
||||
clone.unbreakable = this.unbreakable;
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,7 +326,7 @@ index c743ae066..0cdc8007a 100644
|
||||
+ }
|
||||
+
|
||||
+ private EnchantmentMap() {
|
||||
+ super((o1, o2) -> ((Integer) o1.getId()).compareTo(o2.getId()));
|
||||
+ super(Comparator.comparing(o -> o.getKey().toString()));
|
||||
+ }
|
||||
+
|
||||
+ public EnchantmentMap clone() {
|
||||
|
||||
Reference in New Issue
Block a user