diff --git a/paper-api/src/main/java/org/bukkit/inventory/meta/ItemMeta.java b/paper-api/src/main/java/org/bukkit/inventory/meta/ItemMeta.java index a2eb229ef..1f7d294a7 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/meta/ItemMeta.java +++ b/paper-api/src/main/java/org/bukkit/inventory/meta/ItemMeta.java @@ -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. * diff --git a/paper-api/src/main/java/org/bukkit/inventory/meta/components/CustomModelDataComponent.java b/paper-api/src/main/java/org/bukkit/inventory/meta/components/CustomModelDataComponent.java index 885e87607..e8fc97710 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/meta/components/CustomModelDataComponent.java +++ b/paper-api/src/main/java/org/bukkit/inventory/meta/components/CustomModelDataComponent.java @@ -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 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 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 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 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 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 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 getColors(); /** - * Sets a list of the custom colors. + * Sets a list of colors for the model type's tints. * * @param colors new list */ diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java index 3c8473ca8..228d19195 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java @@ -357,7 +357,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { this.lore = new ArrayList(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 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 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()) {