mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 19:15:32 +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 final class ItemStack {
|
||||||
|
|
||||||
public static final ItemStack a = new ItemStack((Item) null);
|
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.item = item;
|
||||||
this.damage = j;
|
this.damage = j;
|
||||||
this.count = i;
|
this.count = i;
|
||||||
@ -28,7 +38,9 @@
|
|||||||
+ if (MinecraftServer.getServer() != null) {
|
+ if (MinecraftServer.getServer() != null) {
|
||||||
+ this.setData(j);
|
+ this.setData(j);
|
||||||
+ }
|
+ }
|
||||||
|
+ if (convert) {
|
||||||
+ this.convertStack();
|
+ this.convertStack();
|
||||||
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
if (this.damage < 0) {
|
if (this.damage < 0) {
|
||||||
- this.damage = 0;
|
- this.damage = 0;
|
||||||
@ -82,7 +94,7 @@
|
|||||||
this.F();
|
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) {
|
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;
|
return enuminteractionresult;
|
||||||
}
|
}
|
||||||
@@ -122,7 +290,7 @@
|
@@ -122,7 +298,7 @@
|
||||||
nbttagcompound.setByte("Count", (byte) this.count);
|
nbttagcompound.setByte("Count", (byte) this.count);
|
||||||
nbttagcompound.setShort("Damage", (short) this.damage);
|
nbttagcompound.setShort("Damage", (short) this.damage);
|
||||||
if (this.tag != null) {
|
if (this.tag != null) {
|
||||||
@ -231,7 +243,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
return nbttagcompound;
|
return nbttagcompound;
|
||||||
@@ -157,11 +325,30 @@
|
@@ -157,11 +333,30 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setData(int i) {
|
public void setData(int i) {
|
||||||
@ -264,7 +276,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int k() {
|
public int k() {
|
||||||
@@ -198,6 +385,11 @@
|
@@ -198,6 +393,11 @@
|
||||||
if (this.f()) {
|
if (this.f()) {
|
||||||
if (this.isDamaged(i, entityliving.getRandom())) {
|
if (this.isDamaged(i, entityliving.getRandom())) {
|
||||||
entityliving.b(this);
|
entityliving.b(this);
|
||||||
@ -276,7 +288,16 @@
|
|||||||
this.subtract(1);
|
this.subtract(1);
|
||||||
if (entityliving instanceof EntityHuman) {
|
if (entityliving instanceof EntityHuman) {
|
||||||
EntityHuman entityhuman = (EntityHuman) entityliving;
|
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);
|
nbttaglist.add(nbttagcompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,9 +40,12 @@ public final class CraftItemStack extends ItemStack {
|
|||||||
return net.minecraft.server.ItemStack.a;
|
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()) {
|
if (original.hasItemMeta()) {
|
||||||
setItemMeta(stack, original.getItemMeta());
|
setItemMeta(stack, original.getItemMeta());
|
||||||
|
} else {
|
||||||
|
// Converted after setItemMeta
|
||||||
|
stack.convertStack();
|
||||||
}
|
}
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
|||||||
void applyToItem(NBTTagCompound tag) {
|
void applyToItem(NBTTagCompound tag) {
|
||||||
super.applyToItem(tag);
|
super.applyToItem(tag);
|
||||||
|
|
||||||
if (entityTag == null) {
|
if (!isSpawnEggEmpty() && entityTag == null) {
|
||||||
entityTag = new NBTTagCompound();
|
entityTag = new NBTTagCompound();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,8 +78,10 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta {
|
|||||||
entityTag.setString(ENTITY_ID.NBT, new MinecraftKey(spawnedType.getName()).toString());
|
entityTag.setString(ENTITY_ID.NBT, new MinecraftKey(spawnedType.getName()).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (entityTag != null) {
|
||||||
tag.set(ENTITY_TAG.NBT, entityTag);
|
tag.set(ENTITY_TAG.NBT, entityTag);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean applicableTo(Material type) {
|
boolean applicableTo(Material type) {
|
||||||
|
Loading…
Reference in New Issue
Block a user