[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. WIth the addition of the CustomModelDataComponent, the method transitioned to a plain check if the component itself exists. 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. getCustomModelData()int could also yield e.g. -1 or something funky, but that sounds even worse and might break even more.
|
Comment by md_5 [ 31/Mar/25 ] |
Just to be clear, is your suggestion to add the float check to the has method? |