SPIGOT-8032: Improve ItemMeta#hasCustomModelData compatibility

This commit is contained in:
md_5 2025-04-01 20:24:44 +11:00
parent cc864ea9be
commit d275d3b96e
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11

View File

@ -1332,21 +1332,29 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
@Override @Override
public boolean hasCustomModelData() { public boolean hasCustomModelData() {
return customModelData != null; if (customModelData != null) {
List<Float> floats = customModelData.getFloats();
return !floats.isEmpty();
}
return false;
} }
@Override @Override
public int getCustomModelData() { public int getCustomModelData() {
Preconditions.checkState(hasCustomModelData(), "We don't have CustomModelData! Check hasCustomModelData first!"); Preconditions.checkState(hasCustomModelData(), "We don't have CustomModelData! Check hasCustomModelData first!");
List<Float> floats = customModelData.getFloats(); return customModelData.getFloats().get(0).intValue();
Preconditions.checkState(!floats.isEmpty(), "No numeric custom model data"); }
return floats.get(0).intValue();
@Override
public boolean hasCustomModelDataComponent() {
return customModelData != null;
} }
@Override @Override
public CustomModelDataComponent getCustomModelDataComponent() { 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 @Override