Archiviert
13
0

SPIGOT-5907: Item Frame NBT data disappears

Dieser Commit ist enthalten in:
md_5 2020-07-01 10:00:24 +10:00
Ursprung 5a6c529833
Commit a13b8cfc71
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: E8E901AC7C617C11
5 geänderte Dateien mit 137 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -259,6 +259,8 @@ 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 ITEM_FRAME:
return meta instanceof CraftMetaEntityTag ? meta : new CraftMetaEntityTag(meta);
default: default:
return new CraftMetaItem(meta); return new CraftMetaItem(meta);
} }

Datei anzeigen

@ -528,6 +528,8 @@ 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 ITEM_FRAME:
return new CraftMetaEntityTag(item.getTag());
default: default:
return new CraftMetaItem(item.getTag()); return new CraftMetaItem(item.getTag());
} }

Datei anzeigen

@ -0,0 +1,123 @@
package org.bukkit.craftbukkit.inventory;
import com.google.common.collect.ImmutableMap.Builder;
import java.util.Map;
import net.minecraft.server.NBTBase;
import net.minecraft.server.NBTTagCompound;
import org.bukkit.Material;
import org.bukkit.configuration.serialization.DelegateDeserialization;
@DelegateDeserialization(CraftMetaItem.SerializableMeta.class)
public class CraftMetaEntityTag extends CraftMetaItem {
static final ItemMetaKey ENTITY_TAG = new ItemMetaKey("EntityTag", "entity-tag");
NBTTagCompound entityTag;
CraftMetaEntityTag(CraftMetaItem meta) {
super(meta);
}
CraftMetaEntityTag(NBTTagCompound tag) {
super(tag);
if (tag.hasKey(ENTITY_TAG.NBT)) {
entityTag = tag.getCompound(ENTITY_TAG.NBT);
}
}
CraftMetaEntityTag(Map<String, Object> map) {
super(map);
}
@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);
if (entityTag != null) {
tag.set(ENTITY_TAG.NBT, entityTag);
}
}
@Override
boolean applicableTo(Material type) {
switch (type) {
case ITEM_FRAME:
return true;
default:
return false;
}
}
@Override
boolean isEmpty() {
return super.isEmpty() && isEntityTagEmpty();
}
boolean isEntityTagEmpty() {
return !(entityTag != null);
}
@Override
boolean equalsCommon(CraftMetaItem meta) {
if (!super.equalsCommon(meta)) {
return false;
}
if (meta instanceof CraftMetaEntityTag) {
CraftMetaEntityTag that = (CraftMetaEntityTag) meta;
return entityTag != null ? that.entityTag != null && this.entityTag.equals(that.entityTag) : entityTag == null;
}
return true;
}
@Override
boolean notUncommon(CraftMetaItem meta) {
return super.notUncommon(meta) && (meta instanceof CraftMetaEntityTag || isEntityTagEmpty());
}
@Override
int applyHash() {
final int original;
int hash = original = super.applyHash();
if (entityTag != null) {
hash = 73 * hash + entityTag.hashCode();
}
return original != hash ? CraftMetaEntityTag.class.hashCode() ^ hash : hash;
}
@Override
Builder<String, Object> serialize(Builder<String, Object> builder) {
super.serialize(builder);
return builder;
}
@Override
public CraftMetaEntityTag clone() {
CraftMetaEntityTag clone = (CraftMetaEntityTag) super.clone();
if (entityTag != null) {
clone.entityTag = entityTag.clone();
}
return clone;
}
}

Datei anzeigen

@ -155,6 +155,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
.put(CraftMetaTropicalFishBucket.class, "TROPICAL_FISH_BUCKET") .put(CraftMetaTropicalFishBucket.class, "TROPICAL_FISH_BUCKET")
.put(CraftMetaCrossbow.class, "CROSSBOW") .put(CraftMetaCrossbow.class, "CROSSBOW")
.put(CraftMetaSuspiciousStew.class, "SUSPICIOUS_STEW") .put(CraftMetaSuspiciousStew.class, "SUSPICIOUS_STEW")
.put(CraftMetaEntityTag.class, "ENTITY_TAG")
.put(CraftMetaItem.class, "UNSPECIFIC") .put(CraftMetaItem.class, "UNSPECIFIC")
.build(); .build();

Datei anzeigen

@ -324,6 +324,15 @@ public class ItemMetaTest extends AbstractTestingBase {
cleanStack.setItemMeta(meta); cleanStack.setItemMeta(meta);
return cleanStack; return cleanStack;
} }
},
new StackProvider(Material.ITEM_FRAME) {
@Override ItemStack operate(ItemStack cleanStack) {
final CraftMetaEntityTag meta = ((CraftMetaEntityTag) cleanStack.getItemMeta());
meta.entityTag = new NBTTagCompound();
meta.entityTag.setBoolean("Invisible", true);
cleanStack.setItemMeta(meta);
return cleanStack;
}
} }
); );