#326: Convert BlockMeta to handle older serialized items.

This commit is contained in:
Jacob Martin 2016-12-03 10:51:53 +11:00 committed by md_5
parent 9beb0c9968
commit b64d852496
3 changed files with 30 additions and 10 deletions

View file

@ -0,0 +1,12 @@
--- a/net/minecraft/server/DataInspectorBlockEntity.java
+++ b/net/minecraft/server/DataInspectorBlockEntity.java
@@ -32,7 +32,8 @@
boolean flag;
if (s1 == null) {
- DataInspectorBlockEntity.a.warn("Unable to resolve BlockEntity for ItemInstance: {}", new Object[] { s});
+ // CraftBukkit - Remove unnecessary warning (occurs when deserializing a Shulker Box item)
+ // DataInspectorBlockEntity.a.warn("Unable to resolve BlockEntity for ItemInstance: {}", new Object[] { s});
flag = false;
} else {
flag = !nbttagcompound2.hasKey("id");

View file

@ -20,18 +20,15 @@
public final class ItemStack {
public static final ItemStack a = new ItemStack((Item) null);
@@ -46,28 +59,49 @@
@@ -46,28 +59,56 @@
this.item = item;
this.damage = j;
this.count = i;
+ // CraftBukkit start - Pass to setData to do filtering
+ if (MinecraftServer.getServer() != null) {
+ this.setData(j);
+ NBTTagCompound savedStack = new NBTTagCompound();
+ this.save(savedStack);
+ MinecraftServer.getServer().getDataConverterManager().a(DataConverterTypes.ITEM_INSTANCE, savedStack); // PAIL: convert
+ this.load(savedStack);
+ }
+ this.convertStack();
+ // CraftBukkit end
if (this.damage < 0) {
- this.damage = 0;
@ -41,6 +38,16 @@
this.F();
}
+ // Called to run this stack through the data converter to handle older storage methods and serialized items
+ public void convertStack() {
+ if (MinecraftServer.getServer() != null) {
+ NBTTagCompound savedStack = new NBTTagCompound();
+ this.save(savedStack);
+ MinecraftServer.getServer().getDataConverterManager().a(DataConverterTypes.ITEM_INSTANCE, savedStack); // PAIL: convert
+ this.load(savedStack);
+ }
+ }
+
private void F() {
+ if (this.g && this == ItemStack.a) throw new AssertionError("TRAP"); // CraftBukkit
this.g = this.isEmpty();
@ -75,7 +82,7 @@
this.F();
}
@@ -94,11 +128,138 @@
@@ -94,11 +135,138 @@
}
public EnumInteractionResult placeItem(EntityHuman entityhuman, World world, BlockPosition blockposition, EnumHand enumhand, EnumDirection enumdirection, float f, float f1, float f2) {
@ -215,7 +222,7 @@
return enuminteractionresult;
}
@@ -122,7 +283,7 @@
@@ -122,7 +290,7 @@
nbttagcompound.setByte("Count", (byte) this.count);
nbttagcompound.setShort("Damage", (short) this.damage);
if (this.tag != null) {
@ -224,7 +231,7 @@
}
return nbttagcompound;
@@ -157,11 +318,30 @@
@@ -157,11 +325,30 @@
}
public void setData(int i) {
@ -257,7 +264,7 @@
}
public int k() {
@@ -205,6 +385,11 @@
@@ -205,6 +392,11 @@
entityhuman.b(StatisticList.c(this.item));
}
@ -269,7 +276,7 @@
this.damage = 0;
}
@@ -509,6 +694,12 @@
@@ -509,6 +701,12 @@
nbttaglist.add(nbttagcompound);
}

View file

@ -423,6 +423,7 @@ public final class CraftItemStack extends ItemStack {
item.setTag(tag);
((CraftMetaItem) itemMeta).applyToItem(tag);
item.convertStack();
return true;
}