Item components in custom commands aren't retained - (2025.3)

Started by TheGameCrafter13 on

Topic category: Feature requests and ideas for MCreator

Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Item components in custom commands aren't retained - (2025.3)
  • MCreator Version: 2025.3.45720
  • Minecraft version (generator): NeoForge for 1.21.1 (21.1.190)

So making a command with an "item parameter" block allows the user to make commands that utilize item lists as auto-complete suggestions (similar to how "/give" grabs a list of all items.)

 

But an inconsistency I found is although you can use brackets [] to specify component data, NONE of that gets carried over to the command item.

 

So purely as an example making a custom command like "/giveme @p minecraft:wooden_sword[minecraft:damage=30]" won't behave like "/give" would.

 

Looking at the actual generated code shows the cause of this appears to be "getDefaultInstance"

(ItemArgument.getItem(arguments, "item").getItem().getDefaultInstance());

 

So without looking at the code I thought this was a bug. But now I see that makes this post a "feature request" for consistency.

Joined Aug 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I worked on a fix that will…
Thu, 11/13/2025 - 00:36

I worked on a fix that will come in a future update (I do not know if Klemen will release a second patch or not). However, if you want to fix it for yourself until this fix arrives, you can do the following steps:

  1. Open your procedure's code
  2. Replace all occurences of ItemArgument.getItem(arguments, "item").getItem().getDefaultInstance() by commandParameterItemStack(arguments, "item"). (If you have multiple different item argument, change "item' by "<parameterName>" where <parameterName> is the text you wrote inside the procedure block's field.)
  3. Then, at the end of the class, add the following method.
  4. Save and lock your file. 
private static ItemStack commandParameterItemStack(CommandContext<CommandSourceStack> arguments, String parameter) {
	ItemInput input = ItemArgument.getItem(arguments, parameter);
	try {
		return input.createItemStack(1, false);
	} catch (CommandSyntaxException e) {
		e.printStackTrace();
		return input.getItem().getDefaultInstance();
	}
}

 

You can use this fix for both versions as the code is the same. 

I hope this will help you for your mod :)

Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks for the responses,…
Sat, 11/15/2025 - 21:54

Thanks for the responses, Goldorion and Klemen! I'm in no rush so I'll probably just wait for the update. Appreciate the coding help too! Either way I'm sure anyone sticking to older versions or needing a more immediate fix will find this useful.

This oversight isn't a huge barrier for me at the moment but I decided this would probably effect other people more, so it'd be worth posting about.