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