geforkt von Mirrors/Paper
SPIGOT-5927: Some items NBT data disappears
Dieser Commit ist enthalten in:
Ursprung
dc7c3c61fa
Commit
068618eb5b
@ -259,7 +259,11 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
return meta instanceof CraftMetaCrossbow ? meta : new CraftMetaCrossbow(meta);
|
||||
case SUSPICIOUS_STEW:
|
||||
return meta instanceof CraftMetaSuspiciousStew ? meta : new CraftMetaSuspiciousStew(meta);
|
||||
case COD_BUCKET:
|
||||
case PUFFERFISH_BUCKET:
|
||||
case SALMON_BUCKET:
|
||||
case ITEM_FRAME:
|
||||
case PAINTING:
|
||||
return meta instanceof CraftMetaEntityTag ? meta : new CraftMetaEntityTag(meta);
|
||||
case COMPASS:
|
||||
return meta instanceof CraftMetaCompass ? meta : new CraftMetaCompass(meta);
|
||||
|
@ -528,7 +528,11 @@ public final class CraftItemStack extends ItemStack {
|
||||
return new CraftMetaCrossbow(item.getTag());
|
||||
case SUSPICIOUS_STEW:
|
||||
return new CraftMetaSuspiciousStew(item.getTag());
|
||||
case COD_BUCKET:
|
||||
case PUFFERFISH_BUCKET:
|
||||
case SALMON_BUCKET:
|
||||
case ITEM_FRAME:
|
||||
case PAINTING:
|
||||
return new CraftMetaEntityTag(item.getTag());
|
||||
case COMPASS:
|
||||
return new CraftMetaCompass(item.getTag());
|
||||
|
@ -15,6 +15,13 @@ public class CraftMetaArmorStand extends CraftMetaItem {
|
||||
|
||||
CraftMetaArmorStand(CraftMetaItem meta) {
|
||||
super(meta);
|
||||
|
||||
if (!(meta instanceof CraftMetaArmorStand)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CraftMetaArmorStand armorStand = (CraftMetaArmorStand) meta;
|
||||
this.entityTag = armorStand.entityTag;
|
||||
}
|
||||
|
||||
CraftMetaArmorStand(NBTTagCompound tag) {
|
||||
|
@ -15,6 +15,13 @@ public class CraftMetaEntityTag extends CraftMetaItem {
|
||||
|
||||
CraftMetaEntityTag(CraftMetaItem meta) {
|
||||
super(meta);
|
||||
|
||||
if (!(meta instanceof CraftMetaEntityTag)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CraftMetaEntityTag entity = (CraftMetaEntityTag) meta;
|
||||
this.entityTag = entity.entityTag;
|
||||
}
|
||||
|
||||
CraftMetaEntityTag(NBTTagCompound tag) {
|
||||
@ -57,7 +64,11 @@ public class CraftMetaEntityTag extends CraftMetaItem {
|
||||
@Override
|
||||
boolean applicableTo(Material type) {
|
||||
switch (type) {
|
||||
case COD_BUCKET:
|
||||
case PUFFERFISH_BUCKET:
|
||||
case SALMON_BUCKET:
|
||||
case ITEM_FRAME:
|
||||
case PAINTING:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.inventory;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.server.NBTBase;
|
||||
import net.minecraft.server.NBTTagCompound;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
@ -15,8 +16,10 @@ import org.bukkit.inventory.meta.TropicalFishBucketMeta;
|
||||
@DelegateDeserialization(SerializableMeta.class)
|
||||
class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishBucketMeta {
|
||||
static final ItemMetaKey VARIANT = new ItemMetaKey("BucketVariantTag", "fish-variant");
|
||||
static final ItemMetaKey ENTITY_TAG = new ItemMetaKey("EntityTag", "entity-tag");
|
||||
|
||||
private Integer variant;
|
||||
private NBTTagCompound entityTag;
|
||||
|
||||
CraftMetaTropicalFishBucket(CraftMetaItem meta) {
|
||||
super(meta);
|
||||
@ -35,6 +38,10 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
||||
if (tag.hasKeyOfType(VARIANT.NBT, CraftMagicNumbers.NBT.TAG_INT)) {
|
||||
this.variant = tag.getInt(VARIANT.NBT);
|
||||
}
|
||||
|
||||
if (tag.hasKey(ENTITY_TAG.NBT)) {
|
||||
entityTag = tag.getCompound(ENTITY_TAG.NBT);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
void applyToItem(NBTTagCompound tag) {
|
||||
super.applyToItem(tag);
|
||||
@ -53,6 +76,10 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
||||
if (hasVariant()) {
|
||||
tag.setInt(VARIANT.NBT, variant);
|
||||
}
|
||||
|
||||
if (entityTag != null) {
|
||||
tag.set(ENTITY_TAG.NBT, entityTag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,7 +98,7 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
||||
}
|
||||
|
||||
boolean isBucketEmpty() {
|
||||
return !(hasVariant());
|
||||
return !(hasVariant() || entityTag != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -126,7 +153,8 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
||||
if (meta instanceof CraftMetaTropicalFishBucket) {
|
||||
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;
|
||||
}
|
||||
@ -144,6 +172,9 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
||||
if (hasVariant()) {
|
||||
hash = 61 * hash + variant;
|
||||
}
|
||||
if (entityTag != null) {
|
||||
hash = 61 * hash + entityTag.hashCode();
|
||||
}
|
||||
|
||||
return original != hash ? CraftMetaTropicalFishBucket.class.hashCode() ^ hash : hash;
|
||||
}
|
||||
@ -151,7 +182,13 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
||||
|
||||
@Override
|
||||
public CraftMetaTropicalFishBucket clone() {
|
||||
return (CraftMetaTropicalFishBucket) super.clone();
|
||||
CraftMetaTropicalFishBucket clone = (CraftMetaTropicalFishBucket) super.clone();
|
||||
|
||||
if (entityTag != null) {
|
||||
clone.entityTag = entityTag.clone();
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren