[SPIGOT-8032] ItemMeta#hasCustomModelData breaks backwards compatibility Created: 31/Mar/25  Updated: 01/Apr/25  Resolved: 01/Apr/25

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Bjarne Koll Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Environment:

N/A


Version: 1.21.4
Guidelines Read: Yes

 Description   

ItemMeta#hasCustomModelData has existed in the game since 1.14.
It could be used to guarantee a successful call to ItemMeta#getCustomModelData()int.

WIth the addition of the CustomModelDataComponent, the method transitioned to a plain check if the component itself exists.
getCustomModelData()int however has two requirements
a) the component existing
b) a single float being set

Condition `b` is not actually checked by `hasCustomModelData` and hence leads plugins into `Preconditions.checkState(!floats.isEmpty(), "No numeric custom model data");` for items with custom model data but without floats, thus breaking the API expectations of plugins developed prior to 1.21.4.

Resolving this is rough, the "has" method may have been used to check for the existence of the component by now, meaning fixing this is going to break something (or leave something broken).



 Comments   
Comment by md_5 [ 31/Mar/25 ]

hasCustomModelDataComponent, add a float check to the old one, and add a clear deprecation message should be reasonable

Comment by Bjarne Koll [ 31/Mar/25 ]

I unfortunately do not have much of a suggestion.

Adding the float check to has would fix backwards compat but break current usage.
A new method (e.g. hasCustomModelDataComponent) could be added but, a break is a break.
My hunch would tell me a new has method for the component might be better, I doubt a lot of people have made use of the custom model data component by now given it has only existed for a single version.
But every solution to this will piss off people.

getCustomModelData()int could also yield e.g. -1 or something funky, but that sounds even worse and might break even more.
If you have a nicer solution, that would honestly be great but nothing really comes to my mind.

 

Comment by md_5 [ 31/Mar/25 ]

Just to be clear, is your suggestion to add the float check to the has method?

Generated at Tue Apr 22 05:22:28 UTC 2025 using Jira 10.3.5#10030005-sha1:190c783f2bd6c69cd5accdb70f97e48812a78d14.