mirror of
https://github.com/PaperMC/Paper.git
synced 2025-05-19 05:30:23 -07:00
Improve ItemMeta#hasCustomModelData compatibility (#12414)
Ports the follow commits from spigot to paper. All credits to go the respective commit authors listed below. Bukkit: 47480cd07c0957a94b220f3087b851594b063e54 CraftBukkit: c6c8165aa0d5679b9b015b209c1645a222f8c3a6 CraftBukkit: d275d3b96e041f6421f3bb7de1e6022ea8be5456 By: md_5 <git@md-5.net> By: Doc <nachito94@msn.com>
This commit is contained in:
parent
121a7bf4eb
commit
7d5695d774
@ -321,7 +321,12 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
|
||||
* custom item model.
|
||||
*
|
||||
* @return true if this has custom model data
|
||||
* @deprecated more complex custom model data can be specified with
|
||||
* {@link #hasCustomModelDataComponent()}. Integers from the old custom
|
||||
* model data are equivalent to a single float in the
|
||||
* {@link CustomModelDataComponent#getFloats()} list.
|
||||
*/
|
||||
@Deprecated(since = "1.21.5")
|
||||
boolean hasCustomModelData();
|
||||
|
||||
/**
|
||||
@ -334,7 +339,12 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
|
||||
* before calling this method.
|
||||
*
|
||||
* @return the custom model data that is set
|
||||
* @deprecated more complex custom model data can be specified with
|
||||
* {@link #getCustomModelDataComponent()}. Integers from the old custom
|
||||
* model data are equivalent to a single float in the
|
||||
* {@link CustomModelDataComponent#getFloats()} list.
|
||||
*/
|
||||
@Deprecated(since = "1.21.5")
|
||||
int getCustomModelData();
|
||||
|
||||
/**
|
||||
@ -359,9 +369,21 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
|
||||
* custom item model.
|
||||
*
|
||||
* @param data the data to set, or null to clear
|
||||
* @deprecated more complex custom model data can be specified with
|
||||
* {@link #setCustomModelDataComponent(org.bukkit.inventory.meta.components.CustomModelDataComponent)}.
|
||||
* Integers from the old custom model data are equivalent to a single float
|
||||
* in the {@link CustomModelDataComponent#setFloats(java.util.List)} list.
|
||||
*/
|
||||
@Deprecated(since = "1.21.5")
|
||||
void setCustomModelData(@Nullable Integer data);
|
||||
|
||||
/**
|
||||
* Checks if the custom model data component is set.
|
||||
*
|
||||
* @return if a custom model data component is set
|
||||
*/
|
||||
boolean hasCustomModelDataComponent();
|
||||
|
||||
/**
|
||||
* Sets the custom model data component.
|
||||
*
|
||||
|
@ -13,7 +13,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
public interface CustomModelDataComponent extends ConfigurationSerializable {
|
||||
|
||||
/**
|
||||
* Gets a list of the custom floats.
|
||||
* Gets a list of the floats for the range_dispatch model type.
|
||||
*
|
||||
* @return unmodifiable list
|
||||
*/
|
||||
@ -21,14 +21,14 @@ public interface CustomModelDataComponent extends ConfigurationSerializable {
|
||||
List<Float> getFloats();
|
||||
|
||||
/**
|
||||
* Sets a list of the custom floats.
|
||||
* Sets a list of the floats for the range_dispatch model type.
|
||||
*
|
||||
* @param floats new list
|
||||
*/
|
||||
void setFloats(@NotNull List<Float> floats);
|
||||
|
||||
/**
|
||||
* Gets a list of the custom flags.
|
||||
* Gets a list of the booleans for the condition model type.
|
||||
*
|
||||
* @return unmodifiable list
|
||||
*/
|
||||
@ -36,14 +36,14 @@ public interface CustomModelDataComponent extends ConfigurationSerializable {
|
||||
List<Boolean> getFlags();
|
||||
|
||||
/**
|
||||
* Sets a list of the custom flags.
|
||||
* Sets a list of the booleans for the condition model type.
|
||||
*
|
||||
* @param flags new list
|
||||
*/
|
||||
void setFlags(@NotNull List<Boolean> flags);
|
||||
|
||||
/**
|
||||
* Gets a list of the custom strings.
|
||||
* Gets a list of strings for the select model type.
|
||||
*
|
||||
* @return unmodifiable list
|
||||
*/
|
||||
@ -51,14 +51,14 @@ public interface CustomModelDataComponent extends ConfigurationSerializable {
|
||||
List<String> getStrings();
|
||||
|
||||
/**
|
||||
* Sets a list of the custom strings.
|
||||
* Sets a list of strings for the select model type.
|
||||
*
|
||||
* @param strings new list
|
||||
*/
|
||||
void setStrings(@NotNull List<String> strings);
|
||||
|
||||
/**
|
||||
* Gets a list of the custom colors.
|
||||
* Gets a list of colors for the model type's tints.
|
||||
*
|
||||
* @return unmodifiable list
|
||||
*/
|
||||
@ -66,7 +66,7 @@ public interface CustomModelDataComponent extends ConfigurationSerializable {
|
||||
List<Color> getColors();
|
||||
|
||||
/**
|
||||
* Sets a list of the custom colors.
|
||||
* Sets a list of colors for the model type's tints.
|
||||
*
|
||||
* @param colors new list
|
||||
*/
|
||||
|
@ -357,7 +357,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
this.lore = new ArrayList<Component>(meta.lore);
|
||||
}
|
||||
|
||||
if (meta.hasCustomModelData()) {
|
||||
if (meta.hasCustomModelDataComponent()) {
|
||||
this.customModelData = new CraftCustomModelDataComponent(meta.customModelData);
|
||||
}
|
||||
this.enchantableValue = meta.enchantableValue;
|
||||
@ -939,7 +939,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
tag.put(CraftMetaItem.LORE, new ItemLore(this.lore));
|
||||
}
|
||||
|
||||
if (this.hasCustomModelData()) {
|
||||
if (this.hasCustomModelDataComponent()) {
|
||||
tag.put(CraftMetaItem.CUSTOM_MODEL_DATA, this.customModelData.getHandle());
|
||||
}
|
||||
|
||||
@ -1116,7 +1116,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
|
||||
@Overridden
|
||||
boolean isEmpty() {
|
||||
return !(this.hasDisplayName() || this.hasItemName() || this.hasLocalizedName() || this.hasEnchants() || (this.lore != null) || this.hasCustomModelData() || this.hasEnchantable() || this.hasBlockData() || this.hasRepairCost() || !this.unhandledTags.build().isEmpty() || !this.removedTags.isEmpty() || !this.persistentDataContainer.isEmpty() || this.hasAnyItemFlag() || this.isHideTooltip() || this.hasTooltipStyle() || this.hasItemModel() || this.isUnbreakable() || this.hasEnchantmentGlintOverride() || this.isGlider() || this.hasDamageResistant() || this.hasMaxStackSize() || this.hasRarity() || this.hasUseRemainder() || this.hasUseCooldown() || this.hasFood() || this.hasTool() || this.hasJukeboxPlayable() || this.hasEquippable() || this.hasDamageValue() || this.hasMaxDamage() || this.hasAttributeModifiers() || this.customTag != null || this.canPlaceOnPredicates != null || this.canBreakPredicates != null);
|
||||
return !(this.hasDisplayName() || this.hasItemName() || this.hasLocalizedName() || this.hasEnchants() || (this.lore != null) || this.hasCustomModelDataComponent() || this.hasEnchantable() || this.hasBlockData() || this.hasRepairCost() || !this.unhandledTags.build().isEmpty() || !this.removedTags.isEmpty() || !this.persistentDataContainer.isEmpty() || this.hasAnyItemFlag() || this.isHideTooltip() || this.hasTooltipStyle() || this.hasItemModel() || this.isUnbreakable() || this.hasEnchantmentGlintOverride() || this.isGlider() || this.hasDamageResistant() || this.hasMaxStackSize() || this.hasRarity() || this.hasUseRemainder() || this.hasUseCooldown() || this.hasFood() || this.hasTool() || this.hasJukeboxPlayable() || this.hasEquippable() || this.hasDamageValue() || this.hasMaxDamage() || this.hasAttributeModifiers() || this.customTag != null || this.canPlaceOnPredicates != null || this.canBreakPredicates != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1380,21 +1380,29 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
|
||||
@Override
|
||||
public boolean hasCustomModelData() {
|
||||
return this.customModelData != null;
|
||||
if (customModelData != null) {
|
||||
List<Float> floats = customModelData.getFloats();
|
||||
return !floats.isEmpty();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCustomModelData() {
|
||||
Preconditions.checkState(this.hasCustomModelData(), "We don't have CustomModelData! Check hasCustomModelData first!");
|
||||
|
||||
List<Float> floats = this.customModelData.getFloats();
|
||||
Preconditions.checkState(!floats.isEmpty(), "No numeric custom model data");
|
||||
return floats.getFirst().intValue();
|
||||
return customModelData.getFloats().get(0).intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomModelDataComponent() {
|
||||
return customModelData != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomModelDataComponent getCustomModelDataComponent() {
|
||||
return (this.hasCustomModelData()) ? new CraftCustomModelDataComponent(this.customModelData) : new CraftCustomModelDataComponent(new CustomModelData(List.of(), List.of(), List.of(), List.of()));
|
||||
return (this.hasCustomModelDataComponent()) ? new CraftCustomModelDataComponent(this.customModelData) : new CraftCustomModelDataComponent(new CustomModelData(List.of(), List.of(), List.of(), List.of()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1943,7 +1951,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
&& (this.hasItemName() ? meta.hasItemName() && this.itemName.equals(meta.itemName) : !meta.hasItemName())
|
||||
&& (this.hasEnchants() ? meta.hasEnchants() && this.enchantments.equals(meta.enchantments) : !meta.hasEnchants())
|
||||
&& (Objects.equals(this.lore, meta.lore))
|
||||
&& (this.hasCustomModelData() ? meta.hasCustomModelData() && this.customModelData.equals(meta.customModelData) : !meta.hasCustomModelData())
|
||||
&& (this.hasCustomModelDataComponent() ? meta.hasCustomModelDataComponent() && this.customModelData.equals(meta.customModelData) : !meta.hasCustomModelDataComponent())
|
||||
&& (this.hasEnchantable() ? meta.hasEnchantable() && this.enchantableValue.equals(meta.enchantableValue) : !meta.hasEnchantable())
|
||||
&& (this.hasBlockData() ? meta.hasBlockData() && this.blockData.equals(meta.blockData) : !meta.hasBlockData())
|
||||
&& (this.hasRepairCost() ? meta.hasRepairCost() && this.repairCost == meta.repairCost : !meta.hasRepairCost())
|
||||
@ -1996,7 +2004,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
hash = 61 * hash + (this.hasDisplayName() ? this.displayName.hashCode() : 0);
|
||||
hash = 61 * hash + (this.hasItemName() ? this.itemName.hashCode() : 0);
|
||||
hash = 61 * hash + ((this.lore != null) ? this.lore.hashCode() : 0);
|
||||
hash = 61 * hash + (this.hasCustomModelData() ? this.customModelData.hashCode() : 0);
|
||||
hash = 61 * hash + (this.hasCustomModelDataComponent() ? this.customModelData.hashCode() : 0);
|
||||
hash = 61 * hash + (this.hasEnchantable() ? this.enchantableValue.hashCode() : 0);
|
||||
hash = 61 * hash + (this.hasBlockData() ? this.blockData.hashCode() : 0);
|
||||
hash = 61 * hash + (this.hasEnchants() ? this.enchantments.hashCode() : 0);
|
||||
@ -2038,7 +2046,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
if (this.lore != null) {
|
||||
clone.lore = new ArrayList<>(this.lore);
|
||||
}
|
||||
if (this.hasCustomModelData()) {
|
||||
if (this.hasCustomModelDataComponent()) {
|
||||
clone.customModelData = new CraftCustomModelDataComponent(this.customModelData);
|
||||
}
|
||||
clone.enchantableValue = this.enchantableValue;
|
||||
@ -2129,7 +2137,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
builder.put(CraftMetaItem.LORE.BUKKIT, jsonLore);
|
||||
}
|
||||
|
||||
if (this.hasCustomModelData()) {
|
||||
if (this.hasCustomModelDataComponent()) {
|
||||
builder.put(CraftMetaItem.CUSTOM_MODEL_DATA.BUKKIT, this.customModelData);
|
||||
}
|
||||
if (this.hasEnchantable()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user