[SPIGOT-7993] CustomItemModel assignment using Component doesn't work. Created: 12/Jan/25 Updated: 13/Jan/25 Resolved: 13/Jan/25 |
|
| Status: | Resolved |
| Project: | Spigot |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | daruma_256 | Assignee: | Unassigned |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | 1.21.4, bug | ||
| Attachments: |
|
| Version: | This server is running CraftBukkit version 4419-Spigot-aa7842e-df01cf8 (MC: 1.21.4) (Implementing API version 1.21.4-R0.1-SNAPSHOT) |
| Guidelines Read: | Yes |
| Description |
|
※Translated by DeepL Required information as noted in the How to Make a Bug Report. →Probably. Attached are the results using /version ↓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. 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. |
| Comments |
| Comment by daruma_256 [ 13/Jan/25 ] |
|
It now works correctly. Thanks. |
| Comment by md_5 [ 13/Jan/25 ] |
|
Thanks for the helpful explanation. This should hopefully be fixed now. |