Started by
brickcreeper798
on
Topic category: Help with Minecraft modding (Java Edition)
I was wondering if there was any way to "import" items into mcreator to use for villager trades. In the villager trade code the item names are in a format different to their regular item IDs (eg... minecraft:bone_meal is now Items.BONE_MEAL) so it would also help if anyone knew how to get hold of these different IDs for items from other mods.
Edited by brickcreeper798 on Mon, 03/10/2025 - 19:58
This was written with grok 3 so some of the steps are just slightly off like when it tells you to ulock the code to edit it, you would actually want to make sure the code stays locked so it doesn't get overwritte however its mostly correct and will work.
QUESTION:
I am using MCreator 2024.4 Neoforge 1.21.1 and I was wondering if there was any way to "import" items into mcreator to use for villager trades. In the villager trade code the item names are in a format different to their regular item IDs (eg... minecraft:bone_meal is now Items.BONE_MEAL) so it would also help if anyone knew how to get hold of these different IDs for items from other mods.
ANSWER:
In MCreator 2024.4 with NeoForge 1.21.1, you can indeed use items from other mods in villager trades, but it requires a bit of manual work since MCreator doesn't have a direct "import" feature for external mod items in its UI. However, you can reference these items in your villager trades by using their proper registry names and the Items class format (e.g., Items.BONE_MEAL). Here's how you can approach this:
Using Items from Other Mods in Villager Trades
You’ll need to use a ResourceLocation to fetch the item dynamically. For example:
java
ItemStack moddedItem = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation("examplemod:example_item")));
Then replace the placeholder item in the trade with moddedItem.
Go to the code editor for your villager trade (found in the generated Java file under src/main/java/yourmodname/) and locate the trade definition. It might look like this:
java
event.getTrades().get(1).add((trader, rand) -> new MerchantOffer(
new ItemStack(Items.EMERALD, 1),
new ItemStack(Items.STONE, 1),
10, 5, 0.05F));
Modify it to:
java
event.getTrades().get(1).add((trader, rand) -> new MerchantOffer(
new ItemStack(Items.EMERALD, 1),
new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation("coolmod:shiny_gem")), 1),
10, 5, 0.05F));
Finding the Items Format for Modded Items
Notes
This approach should let you use modded items in villager trades effectively! Let me know if you need help with a specific mod or item.
That helps thanks!