mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
SPIGOT-2980: Improve SpawnEgg NBT application and ItemStack conversion.
This commit is contained in:
parent
a6d8fa2eac
commit
613be0d841
@ -20,7 +20,17 @@
|
||||
public final class ItemStack {
|
||||
|
||||
public static final ItemStack a = new ItemStack((Item) null);
|
||||
@@ -46,28 +59,56 @@
|
||||
@@ -42,32 +55,68 @@
|
||||
this(item, i, 0);
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
public ItemStack(Item item, int i, int j) {
|
||||
+ this(item, i, j, true);
|
||||
+ }
|
||||
+
|
||||
+ public ItemStack(Item item, int i, int j, boolean convert) {
|
||||
+ // CraftBukkit end
|
||||
this.item = item;
|
||||
this.damage = j;
|
||||
this.count = i;
|
||||
@ -28,7 +38,9 @@
|
||||
+ if (MinecraftServer.getServer() != null) {
|
||||
+ this.setData(j);
|
||||
+ }
|
||||
+ this.convertStack();
|
||||
+ if (convert) {
|
||||
+ this.convertStack();
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
if (this.damage < 0) {
|
||||
- this.damage = 0;
|
||||
@ -82,7 +94,7 @@
|
||||
this.F();
|
||||
}
|
||||
|
||||
@@ -94,11 +135,138 @@
|
||||
@@ -94,11 +143,138 @@
|
||||
}
|
||||
|
||||
public EnumInteractionResult placeItem(EntityHuman entityhuman, World world, BlockPosition blockposition, EnumHand enumhand, EnumDirection enumdirection, float f, float f1, float f2) {
|
||||
@ -222,7 +234,7 @@
|
||||
|
||||
return enuminteractionresult;
|
||||
}
|
||||
@@ -122,7 +290,7 @@
|
||||
@@ -122,7 +298,7 @@
|
||||
nbttagcompound.setByte("Count", (byte) this.count);
|
||||
nbttagcompound.setShort("Damage", (short) this.damage);
|
||||
if (this.tag != null) {
|
||||
@ -231,7 +243,7 @@
|
||||
}
|
||||
|
||||
return nbttagcompound;
|
||||
@@ -157,11 +325,30 @@
|
||||
@@ -157,11 +333,30 @@
|
||||
}
|
||||
|
||||
public void setData(int i) {
|
||||
@ -264,7 +276,7 @@
|
||||
}
|
||||
|
||||
public int k() {
|
||||
@@ -198,6 +385,11 @@
|
||||
@@ -198,6 +393,11 @@
|
||||
if (this.f()) {
|
||||
if (this.isDamaged(i, entityliving.getRandom())) {
|
||||
entityliving.b(this);
|
||||
@ -276,7 +288,16 @@
|
||||
this.subtract(1);
|
||||
if (entityliving instanceof EntityHuman) {
|
||||
EntityHuman entityhuman = (EntityHuman) entityliving;
|
||||
@@ -509,6 +701,12 @@
|
||||
@@ -239,7 +439,7 @@
|
||||
}
|
||||
|
||||
public ItemStack cloneItemStack() {
|
||||
- ItemStack itemstack = new ItemStack(this.item, this.count, this.damage);
|
||||
+ ItemStack itemstack = new ItemStack(this.item, this.count, this.damage, false); // CraftBukkit
|
||||
|
||||
if (this.tag != null) {
|
||||
itemstack.tag = this.tag.g();
|
||||
@@ -509,6 +709,12 @@
|
||||
nbttaglist.add(nbttagcompound);
|
||||
}
|
||||
|
||||
|
@ -40,9 +40,12 @@ public final class CraftItemStack extends ItemStack {
|
||||
return net.minecraft.server.ItemStack.a;
|
||||
}
|
||||
|
||||
net.minecraft.server.ItemStack stack = new net.minecraft.server.ItemStack(item, original.getAmount(), original.getDurability());
|
||||
net.minecraft.server.ItemStack stack = new net.minecraft.server.ItemStack(item, original.getAmount(), original.getDurability(), false);
|
||||
if (original.hasItemMeta()) {
|
||||
setItemMeta(stack, original.getItemMeta());
|
||||
} else {
|
||||
// Converted after setItemMeta
|
||||
stack.convertStack();
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
||||
void applyToItem(NBTTagCompound tag) {
|
||||
super.applyToItem(tag);
|
||||
|
||||
if (entityTag == null) {
|
||||
if (!isSpawnEggEmpty() && entityTag == null) {
|
||||
entityTag = new NBTTagCompound();
|
||||
}
|
||||
|
||||
@ -78,7 +78,9 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
||||
entityTag.setString(ENTITY_ID.NBT, new MinecraftKey(spawnedType.getName()).toString());
|
||||
}
|
||||
|
||||
tag.set(ENTITY_TAG.NBT, entityTag);
|
||||
if (entityTag != null) {
|
||||
tag.set(ENTITY_TAG.NBT, entityTag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user