mirror of
https://github.com/PaperMC/Paper.git
synced 2025-03-02 11:22:01 +01:00
Support both entity_data and bucket_entity_data on axolotl/fish buckets
By: md_5 <git@md-5.net>
This commit is contained in:
parent
fb2cd0f8e3
commit
4951fa2dd1
@ -16,11 +16,13 @@ import org.bukkit.inventory.meta.AxolotlBucketMeta;
|
||||
@DelegateDeserialization(SerializableMeta.class)
|
||||
public class CraftMetaAxolotlBucket extends CraftMetaItem implements AxolotlBucketMeta {
|
||||
|
||||
static final ItemMetaKey VARIANT = new ItemMetaKey("axolotl-variant");
|
||||
static final ItemMetaKeyType<CustomData> ENTITY_TAG = new ItemMetaKeyType<>(DataComponents.BUCKET_ENTITY_DATA, "entity-tag");
|
||||
static final ItemMetaKey VARIANT = new ItemMetaKey("Variant", "axolotl-variant");
|
||||
static final ItemMetaKeyType<CustomData> ENTITY_TAG = new ItemMetaKeyType<>(DataComponents.ENTITY_DATA, "entity-tag");
|
||||
static final ItemMetaKeyType<CustomData> BUCKET_ENTITY_TAG = new ItemMetaKeyType<>(DataComponents.BUCKET_ENTITY_DATA, "bucket-entity-tag");
|
||||
|
||||
private Integer variant;
|
||||
private NBTTagCompound entityTag;
|
||||
private NBTTagCompound bucketEntityTag;
|
||||
|
||||
CraftMetaAxolotlBucket(CraftMetaItem meta) {
|
||||
super(meta);
|
||||
@ -32,6 +34,7 @@ public class CraftMetaAxolotlBucket extends CraftMetaItem implements AxolotlBuck
|
||||
CraftMetaAxolotlBucket bucket = (CraftMetaAxolotlBucket) meta;
|
||||
this.variant = bucket.variant;
|
||||
this.entityTag = bucket.entityTag;
|
||||
this.bucketEntityTag = bucket.bucketEntityTag;
|
||||
}
|
||||
|
||||
CraftMetaAxolotlBucket(DataComponentPatch tag) {
|
||||
@ -40,8 +43,15 @@ public class CraftMetaAxolotlBucket extends CraftMetaItem implements AxolotlBuck
|
||||
getOrEmpty(tag, ENTITY_TAG).ifPresent((nbt) -> {
|
||||
entityTag = nbt.copyTag();
|
||||
|
||||
if (entityTag.contains("Variant", CraftMagicNumbers.NBT.TAG_INT)) {
|
||||
this.variant = entityTag.getInt("Variant");
|
||||
if (entityTag.contains(VARIANT.NBT, CraftMagicNumbers.NBT.TAG_INT)) {
|
||||
this.variant = entityTag.getInt(VARIANT.NBT);
|
||||
}
|
||||
});
|
||||
getOrEmpty(tag, BUCKET_ENTITY_TAG).ifPresent((nbt) -> {
|
||||
bucketEntityTag = nbt.copyTag();
|
||||
|
||||
if (bucketEntityTag.contains(VARIANT.NBT, CraftMagicNumbers.NBT.TAG_INT)) {
|
||||
this.variant = bucketEntityTag.getInt(VARIANT.NBT);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -62,6 +72,9 @@ public class CraftMetaAxolotlBucket extends CraftMetaItem implements AxolotlBuck
|
||||
if (tag.contains(ENTITY_TAG.NBT)) {
|
||||
entityTag = tag.getCompound(ENTITY_TAG.NBT);
|
||||
}
|
||||
if (tag.contains(BUCKET_ENTITY_TAG.NBT)) {
|
||||
bucketEntityTag = tag.getCompound(BUCKET_ENTITY_TAG.NBT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -69,22 +82,30 @@ public class CraftMetaAxolotlBucket extends CraftMetaItem implements AxolotlBuck
|
||||
if (entityTag != null && !entityTag.isEmpty()) {
|
||||
internalTags.put(ENTITY_TAG.NBT, entityTag);
|
||||
}
|
||||
if (bucketEntityTag != null && !bucketEntityTag.isEmpty()) {
|
||||
internalTags.put(BUCKET_ENTITY_TAG.NBT, bucketEntityTag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void applyToItem(CraftMetaItem.Applicator tag) {
|
||||
super.applyToItem(tag);
|
||||
|
||||
if (hasVariant()) {
|
||||
if (entityTag == null) {
|
||||
entityTag = new NBTTagCompound();
|
||||
}
|
||||
entityTag.putInt("Variant", variant);
|
||||
}
|
||||
|
||||
if (entityTag != null) {
|
||||
tag.put(ENTITY_TAG, CustomData.of(entityTag));
|
||||
}
|
||||
|
||||
NBTTagCompound bucketEntityTag = (this.bucketEntityTag != null) ? this.bucketEntityTag.copy() : null;
|
||||
if (hasVariant()) {
|
||||
if (bucketEntityTag == null) {
|
||||
bucketEntityTag = new NBTTagCompound();
|
||||
}
|
||||
bucketEntityTag.putInt(VARIANT.NBT, variant);
|
||||
}
|
||||
|
||||
if (bucketEntityTag != null) {
|
||||
tag.put(BUCKET_ENTITY_TAG, CustomData.of(bucketEntityTag));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -98,7 +119,7 @@ public class CraftMetaAxolotlBucket extends CraftMetaItem implements AxolotlBuck
|
||||
}
|
||||
|
||||
boolean isBucketEmpty() {
|
||||
return !(hasVariant() || entityTag != null);
|
||||
return !(hasVariant() || entityTag != null || bucketEntityTag != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -128,7 +149,8 @@ public class CraftMetaAxolotlBucket extends CraftMetaItem implements AxolotlBuck
|
||||
CraftMetaAxolotlBucket that = (CraftMetaAxolotlBucket) meta;
|
||||
|
||||
return (hasVariant() ? that.hasVariant() && this.variant.equals(that.variant) : !that.hasVariant())
|
||||
&& (entityTag != null ? that.entityTag != null && this.entityTag.equals(that.entityTag) : that.entityTag == null);
|
||||
&& (entityTag != null ? that.entityTag != null && this.entityTag.equals(that.entityTag) : that.entityTag == null)
|
||||
&& (bucketEntityTag != null ? that.bucketEntityTag != null && this.bucketEntityTag.equals(that.bucketEntityTag) : that.bucketEntityTag == null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -149,6 +171,9 @@ public class CraftMetaAxolotlBucket extends CraftMetaItem implements AxolotlBuck
|
||||
if (entityTag != null) {
|
||||
hash = 61 * hash + entityTag.hashCode();
|
||||
}
|
||||
if (bucketEntityTag != null) {
|
||||
hash = 61 * hash + bucketEntityTag.hashCode();
|
||||
}
|
||||
|
||||
return original != hash ? CraftMetaAxolotlBucket.class.hashCode() ^ hash : hash;
|
||||
}
|
||||
@ -160,6 +185,9 @@ public class CraftMetaAxolotlBucket extends CraftMetaItem implements AxolotlBuck
|
||||
if (entityTag != null) {
|
||||
clone.entityTag = entityTag.copy();
|
||||
}
|
||||
if (bucketEntityTag != null) {
|
||||
clone.bucketEntityTag = bucketEntityTag.copy();
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
@ -1737,7 +1737,9 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
CraftMetaBlockState.BLOCK_ENTITY_TAG.TYPE,
|
||||
CraftMetaKnowledgeBook.BOOK_RECIPES.TYPE,
|
||||
CraftMetaTropicalFishBucket.ENTITY_TAG.TYPE,
|
||||
CraftMetaTropicalFishBucket.BUCKET_ENTITY_TAG.TYPE,
|
||||
CraftMetaAxolotlBucket.ENTITY_TAG.TYPE,
|
||||
CraftMetaAxolotlBucket.BUCKET_ENTITY_TAG.TYPE,
|
||||
CraftMetaCrossbow.CHARGED_PROJECTILES.TYPE,
|
||||
CraftMetaSuspiciousStew.EFFECTS.TYPE,
|
||||
CraftMetaCompass.LODESTONE_TARGET.TYPE,
|
||||
|
@ -17,11 +17,14 @@ 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 ItemMetaKeyType<CustomData> ENTITY_TAG = new ItemMetaKeyType<>(DataComponents.BUCKET_ENTITY_DATA, "entity-tag");
|
||||
static final ItemMetaKeyType<CustomData> ENTITY_TAG = new ItemMetaKeyType<>(DataComponents.ENTITY_DATA, "entity-tag");
|
||||
static final ItemMetaKeyType<CustomData> BUCKET_ENTITY_TAG = new ItemMetaKeyType<>(DataComponents.BUCKET_ENTITY_DATA, "bucket-entity-tag");
|
||||
|
||||
private Integer variant;
|
||||
private NBTTagCompound entityTag;
|
||||
private NBTTagCompound bucketEntityTag;
|
||||
|
||||
CraftMetaTropicalFishBucket(CraftMetaItem meta) {
|
||||
super(meta);
|
||||
@ -33,6 +36,7 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
||||
CraftMetaTropicalFishBucket bucket = (CraftMetaTropicalFishBucket) meta;
|
||||
this.variant = bucket.variant;
|
||||
this.entityTag = bucket.entityTag;
|
||||
this.bucketEntityTag = bucket.bucketEntityTag;
|
||||
}
|
||||
|
||||
CraftMetaTropicalFishBucket(DataComponentPatch tag) {
|
||||
@ -45,6 +49,13 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
||||
this.variant = entityTag.getInt(VARIANT.NBT);
|
||||
}
|
||||
});
|
||||
getOrEmpty(tag, BUCKET_ENTITY_TAG).ifPresent((nbt) -> {
|
||||
bucketEntityTag = nbt.copyTag();
|
||||
|
||||
if (bucketEntityTag.contains(VARIANT.NBT, CraftMagicNumbers.NBT.TAG_INT)) {
|
||||
this.variant = bucketEntityTag.getInt(VARIANT.NBT);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
CraftMetaTropicalFishBucket(Map<String, Object> map) {
|
||||
@ -63,6 +74,9 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
||||
if (tag.contains(ENTITY_TAG.NBT)) {
|
||||
entityTag = tag.getCompound(ENTITY_TAG.NBT);
|
||||
}
|
||||
if (tag.contains(BUCKET_ENTITY_TAG.NBT)) {
|
||||
bucketEntityTag = tag.getCompound(BUCKET_ENTITY_TAG.NBT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -70,22 +84,30 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
||||
if (entityTag != null && !entityTag.isEmpty()) {
|
||||
internalTags.put(ENTITY_TAG.NBT, entityTag);
|
||||
}
|
||||
if (bucketEntityTag != null && !bucketEntityTag.isEmpty()) {
|
||||
internalTags.put(BUCKET_ENTITY_TAG.NBT, bucketEntityTag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void applyToItem(CraftMetaItem.Applicator tag) {
|
||||
super.applyToItem(tag);
|
||||
|
||||
if (hasVariant()) {
|
||||
if (entityTag == null) {
|
||||
entityTag = new NBTTagCompound();
|
||||
}
|
||||
entityTag.putInt(VARIANT.NBT, variant);
|
||||
}
|
||||
|
||||
if (entityTag != null) {
|
||||
tag.put(ENTITY_TAG, CustomData.of(entityTag));
|
||||
}
|
||||
|
||||
NBTTagCompound bucketEntityTag = (this.bucketEntityTag != null) ? this.bucketEntityTag.copy() : null;
|
||||
if (hasVariant()) {
|
||||
if (bucketEntityTag == null) {
|
||||
bucketEntityTag = new NBTTagCompound();
|
||||
}
|
||||
bucketEntityTag.putInt(VARIANT.NBT, variant);
|
||||
}
|
||||
|
||||
if (bucketEntityTag != null) {
|
||||
tag.put(BUCKET_ENTITY_TAG, CustomData.of(bucketEntityTag));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -99,7 +121,7 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
||||
}
|
||||
|
||||
boolean isBucketEmpty() {
|
||||
return !(hasVariant() || entityTag != null);
|
||||
return !(hasVariant() || entityTag != null || bucketEntityTag != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -155,7 +177,8 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
||||
CraftMetaTropicalFishBucket that = (CraftMetaTropicalFishBucket) meta;
|
||||
|
||||
return (hasVariant() ? that.hasVariant() && this.variant.equals(that.variant) : !that.hasVariant())
|
||||
&& (entityTag != null ? that.entityTag != null && this.entityTag.equals(that.entityTag) : that.entityTag == null);
|
||||
&& (entityTag != null ? that.entityTag != null && this.entityTag.equals(that.entityTag) : that.entityTag == null)
|
||||
&& (bucketEntityTag != null ? that.bucketEntityTag != null && this.bucketEntityTag.equals(that.bucketEntityTag) : that.bucketEntityTag == null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -176,11 +199,13 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
||||
if (entityTag != null) {
|
||||
hash = 61 * hash + entityTag.hashCode();
|
||||
}
|
||||
if (bucketEntityTag != null) {
|
||||
hash = 61 * hash + bucketEntityTag.hashCode();
|
||||
}
|
||||
|
||||
return original != hash ? CraftMetaTropicalFishBucket.class.hashCode() ^ hash : hash;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CraftMetaTropicalFishBucket clone() {
|
||||
CraftMetaTropicalFishBucket clone = (CraftMetaTropicalFishBucket) super.clone();
|
||||
@ -188,6 +213,9 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB
|
||||
if (entityTag != null) {
|
||||
clone.entityTag = entityTag.copy();
|
||||
}
|
||||
if (bucketEntityTag != null) {
|
||||
clone.bucketEntityTag = bucketEntityTag.copy();
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user