※Translated by DeepL
Required information as noted in the How to Make a Bug Report.
1:Make sure that you are up to date.
→Probably. Attached are the results using /version
2:Be concise in describing the issue.
→The assignment of CustomItemModel to ItemStack using the new “Component” feature in 1.21.4 is not working and I believe that craftbukkit is responsible.
3:Test your issue in all applicable versions.
→This feature was added in 1.21.4.
4:For API bugs, include a minimal reproduction plugin.
→Attach jar and github link
↓Here is what I would like to do using the command
/give @p minecraft:stick[minecraft:custom_model_data={strings:["test"]}]
I believe the code using Spigot would look something like this.
(I believe the same problem would occur in the case of incorrect implementation.)
ItemStack itemStack = new ItemStack(Material.STICK); ItemMeta itemMeta = itemStack.getItemMeta(); CustomModelDataComponent component = itemMeta.getCustomModelDataComponent(); ArrayList<String> list = new ArrayList<>(); list.add("test"); component.setStrings(list); itemMeta.setCustomModelDataComponent(component); itemStack.setItemMeta(itemMeta);
However, if you run this and check with the data command, etc., you will see the following.
(Omit unnecessary parts)
Item: {components: {"minecraft:custom_model_data": {}}, count: 1, id: "minecraft:stick"},
note: What you get with the first command listed is as follows
Item: {components: {"minecraft:custom_model_data": {strings: ["test"]}}, count: 1, id: "minecraft:stick"},
I think the cause is that setString() etc. do not use input values in CraftCustomModelDataComponent.
Excerpts from this only where necessary
org.bukkit.craftbukkit.v1_21_R3.inventory.components.CraftCustomModelDataComponent
public final class CraftCustomModelDataComponent implements CustomModelDataComponent { private CustomModelData handle; @Override public void setFloats(List<Float> floats) { handle = new CustomModelData(new ArrayList<>(floats), handle.flags(), handle.strings(), handle.colors()); } @Override public void setFlags(List<Boolean> flags) { handle = new CustomModelData(handle.floats(), new ArrayList<>(handle.flags()), handle.strings(), handle.colors()); } @Override public void setStrings(List<String> strings) { handle = new CustomModelData(handle.floats(), handle.flags(), new ArrayList<>(handle.strings()), handle.colors()); } @Override public void setColors(List<Color> colors) { handle = new CustomModelData(handle.floats(), handle.flags(), handle.strings(), new ArrayList<>(handle.colors())); }
In all .set***(), the input value is not used and the current value appears to be re-generated.
Thanks for reading this far. If there is any missing information, I will address it.