mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-25 12:05:53 +01:00
SPIGOT-5927: Some items NBT data disappears
This commit is contained in:
parent
dc7c3c61fa
commit
068618eb5b
@ -259,7 +259,11 @@ public final class CraftItemFactory implements ItemFactory {
|
|||||||
return meta instanceof CraftMetaCrossbow ? meta : new CraftMetaCrossbow(meta);
|
return meta instanceof CraftMetaCrossbow ? meta : new CraftMetaCrossbow(meta);
|
||||||
case SUSPICIOUS_STEW:
|
case SUSPICIOUS_STEW:
|
||||||
return meta instanceof CraftMetaSuspiciousStew ? meta : new CraftMetaSuspiciousStew(meta);
|
return meta instanceof CraftMetaSuspiciousStew ? meta : new CraftMetaSuspiciousStew(meta);
|
||||||
|
case COD_BUCKET:
|
||||||
|
case PUFFERFISH_BUCKET:
|
||||||
|
case SALMON_BUCKET:
|
||||||
case ITEM_FRAME:
|
case ITEM_FRAME:
|
||||||
|
case PAINTING:
|
||||||
return meta instanceof CraftMetaEntityTag ? meta : new CraftMetaEntityTag(meta);
|
return meta instanceof CraftMetaEntityTag ? meta : new CraftMetaEntityTag(meta);
|
||||||
case COMPASS:
|
case COMPASS:
|
||||||
return meta instanceof CraftMetaCompass ? meta : new CraftMetaCompass(meta);
|
return meta instanceof CraftMetaCompass ? meta : new CraftMetaCompass(meta);
|
||||||
|
@ -528,7 +528,11 @@ public final class CraftItemStack extends ItemStack {
|
|||||||
return new CraftMetaCrossbow(item.getTag());
|
return new CraftMetaCrossbow(item.getTag());
|
||||||
case SUSPICIOUS_STEW:
|
case SUSPICIOUS_STEW:
|
||||||
return new CraftMetaSuspiciousStew(item.getTag());
|
return new CraftMetaSuspiciousStew(item.getTag());
|
||||||
|
case COD_BUCKET:
|
||||||
|
case PUFFERFISH_BUCKET:
|
||||||
|
case SALMON_BUCKET:
|
||||||
case ITEM_FRAME:
|
case ITEM_FRAME:
|
||||||
|
case PAINTING:
|
||||||
return new CraftMetaEntityTag(item.getTag());
|
return new CraftMetaEntityTag(item.getTag());
|
||||||
case COMPASS:
|
case COMPASS:
|
||||||
return new CraftMetaCompass(item.getTag());
|
return new CraftMetaCompass(item.getTag());
|
||||||
|
@ -15,6 +15,13 @@ public class CraftMetaArmorStand extends CraftMetaItem {
|
|||||||
|
|
||||||
CraftMetaArmorStand(CraftMetaItem meta) {
|
CraftMetaArmorStand(CraftMetaItem meta) {
|
||||||
super(meta);
|
super(meta);
|
||||||
|
|
||||||
|
if (!(meta instanceof CraftMetaArmorStand)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CraftMetaArmorStand armorStand = (CraftMetaArmorStand) meta;
|
||||||
|
this.entityTag = armorStand.entityTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
CraftMetaArmorStand(NBTTagCompound tag) {
|
CraftMetaArmorStand(NBTTagCompound tag) {
|
||||||
|
@ -15,6 +15,13 @@ public class CraftMetaEntityTag extends CraftMetaItem {
|
|||||||
|
|
||||||
CraftMetaEntityTag(CraftMetaItem meta) {
|
CraftMetaEntityTag(CraftMetaItem meta) {
|
||||||
super(meta);
|
super(meta);
|
||||||
|
|
||||||
|
if (!(meta instanceof CraftMetaEntityTag)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CraftMetaEntityTag entity = (CraftMetaEntityTag) meta;
|
||||||
|
this.entityTag = entity.entityTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
CraftMetaEntityTag(NBTTagCompound tag) {
|
CraftMetaEntityTag(NBTTagCompound tag) {
|
||||||
@ -57,7 +64,11 @@ public class CraftMetaEntityTag extends CraftMetaItem {
|
|||||||
@Override
|
@Override
|
||||||
boolean applicableTo(Material type) {
|
boolean applicableTo(Material type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case COD_BUCKET:
|
||||||
|
case PUFFERFISH_BUCKET:
|
||||||
|
case SALMON_BUCKET:
|
||||||
case ITEM_FRAME:
|
case ITEM_FRAME:
|
||||||
|
case PAINTING:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.inventory;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import net.minecraft.server.NBTBase;
|
||||||
import net.minecraft.server.NBTTagCompound;
|
import net.minecraft.server.NBTTagCompound;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -15,8 +16,10 @@ import org.bukkit.inventory.meta.TropicalFishBucketMeta;
|
|||||||
@DelegateDeserialization(SerializableMeta.class)
|
@DelegateDeserialization(SerializableMeta.class)
|
||||||
class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishBucketMeta {
|
class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishBucketMeta {
|
||||||
static final ItemMetaKey VARIANT = new ItemMetaKey("BucketVariantTag", "fish-variant");
|
static final ItemMetaKey VARIANT = new ItemMetaKey("BucketVariantTag", "fish-variant");
|
||||||
|
static final ItemMetaKey ENTITY_TAG = new ItemMetaKey("EntityTag", "entity-tag");
|
||||||
|
|
||||||
private Integer variant;
|
private Integer variant;
|
||||||
|
private NBTTagCompound entityTag;
|
||||||
|
|
||||||
CraftMetaTropicalFishBucket(CraftMetaItem meta) {
|
CraftMetaTropicalFishBucket(CraftMetaItem meta) {
|
||||||
super(meta);
|
super(meta);
|
||||||
@ -35,6 +38,10 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
|||||||
if (tag.hasKeyOfType(VARIANT.NBT, CraftMagicNumbers.NBT.TAG_INT)) {
|
if (tag.hasKeyOfType(VARIANT.NBT, CraftMagicNumbers.NBT.TAG_INT)) {
|
||||||
this.variant = tag.getInt(VARIANT.NBT);
|
this.variant = tag.getInt(VARIANT.NBT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tag.hasKey(ENTITY_TAG.NBT)) {
|
||||||
|
entityTag = tag.getCompound(ENTITY_TAG.NBT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CraftMetaTropicalFishBucket(Map<String, Object> map) {
|
CraftMetaTropicalFishBucket(Map<String, Object> map) {
|
||||||
@ -46,6 +53,22 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void deserializeInternal(NBTTagCompound tag, Object context) {
|
||||||
|
super.deserializeInternal(tag, context);
|
||||||
|
|
||||||
|
if (tag.hasKey(ENTITY_TAG.NBT)) {
|
||||||
|
entityTag = tag.getCompound(ENTITY_TAG.NBT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void serializeInternal(Map<String, NBTBase> internalTags) {
|
||||||
|
if (entityTag != null && !entityTag.isEmpty()) {
|
||||||
|
internalTags.put(ENTITY_TAG.NBT, entityTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void applyToItem(NBTTagCompound tag) {
|
void applyToItem(NBTTagCompound tag) {
|
||||||
super.applyToItem(tag);
|
super.applyToItem(tag);
|
||||||
@ -53,6 +76,10 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
|||||||
if (hasVariant()) {
|
if (hasVariant()) {
|
||||||
tag.setInt(VARIANT.NBT, variant);
|
tag.setInt(VARIANT.NBT, variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (entityTag != null) {
|
||||||
|
tag.set(ENTITY_TAG.NBT, entityTag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -71,7 +98,7 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean isBucketEmpty() {
|
boolean isBucketEmpty() {
|
||||||
return !(hasVariant());
|
return !(hasVariant() || entityTag != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -126,7 +153,8 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
|||||||
if (meta instanceof CraftMetaTropicalFishBucket) {
|
if (meta instanceof CraftMetaTropicalFishBucket) {
|
||||||
CraftMetaTropicalFishBucket that = (CraftMetaTropicalFishBucket) meta;
|
CraftMetaTropicalFishBucket that = (CraftMetaTropicalFishBucket) meta;
|
||||||
|
|
||||||
return (hasVariant() ? that.hasVariant() && this.variant.equals(that.variant) : !that.hasVariant());
|
return (hasVariant() ? that.hasVariant() && this.variant.equals(that.variant) : !that.hasVariant())
|
||||||
|
&& entityTag != null ? that.entityTag != null && this.entityTag.equals(that.entityTag) : entityTag == null;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -144,6 +172,9 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
|||||||
if (hasVariant()) {
|
if (hasVariant()) {
|
||||||
hash = 61 * hash + variant;
|
hash = 61 * hash + variant;
|
||||||
}
|
}
|
||||||
|
if (entityTag != null) {
|
||||||
|
hash = 61 * hash + entityTag.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
return original != hash ? CraftMetaTropicalFishBucket.class.hashCode() ^ hash : hash;
|
return original != hash ? CraftMetaTropicalFishBucket.class.hashCode() ^ hash : hash;
|
||||||
}
|
}
|
||||||
@ -151,7 +182,13 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CraftMetaTropicalFishBucket clone() {
|
public CraftMetaTropicalFishBucket clone() {
|
||||||
return (CraftMetaTropicalFishBucket) super.clone();
|
CraftMetaTropicalFishBucket clone = (CraftMetaTropicalFishBucket) super.clone();
|
||||||
|
|
||||||
|
if (entityTag != null) {
|
||||||
|
clone.entityTag = entityTag.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user