Is there a way to use items from other mods to use in custom villager trades

Started by brickcreeper798 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Feb 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Is there a way to use items from other mods to use in custom villager trades
Mon, 03/10/2025 - 19:58 (edited)

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
Joined Mar 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This was written with grok 3…
Sun, 03/16/2025 - 20:06

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

  1. Identify the Item's Registry Name:
    • Every item in Minecraft (including those from other mods) has a unique registry name in the format modid:item_name. For example, minecraft:bone_meal is a vanilla item, but an item from another mod might be something like examplemod:example_item.
    • To find this:
      • Check the mod's documentation or wiki (if available).
      • Use a mod like Just Enough Items (JEI) in-game to hover over the item and see its registry name.
      • Alternatively, look into the mod's source code (if it's open-source) or decompile its JAR file to find the item registry entries.
  2. Convert to the Items Class Format:
    • In NeoForge (and Forge), villager trade code uses the Items class to reference items. For vanilla items, this is straightforward: minecraft:bone_meal becomes Items.BONE_MEAL.
    • For modded items, the Items class doesn't automatically include them because they’re registered by the other mod, not Minecraft or NeoForge itself. Instead, you need to reference the item directly using its registry name in your code.
  3. Adding Modded Items to Villager Trades in MCreator:
    • When creating a villager trade in MCreator, the UI typically lets you pick items from a dropdown, which only includes vanilla items and items defined in your own mod.
    • To use an item from another mod:
      • Create your villager profession and trade in MCreator as usual, but leave the item field blank or use a placeholder (e.g., a vanilla item like Items.STONE).
      • After generating the trade, unlock the code (if locked) and manually edit it to reference the modded item using its registry name.
      • 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.

  4. Example Workflow:
    • Suppose you want a villager to trade an item from a mod called "CoolMod" with the item ID coolmod:shiny_gem.
    • In MCreator, set up the trade with a placeholder item (e.g., Items.EMERALD).
    • 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));

    • Ensure you import net.minecraftforge.registries.ForgeRegistries and net.minecraft.resources.ResourceLocation at the top of the file.
  5. Dependencies:
    • For this to work, the other mod (e.g., "CoolMod") must be a dependency of your mod. In MCreator, go to "Workspace" > "Workspace Settings" > "External APIs" and add the mod as a dependency by specifying its mod ID and version (you may need to manually edit the build.gradle file if MCreator’s UI doesn’t support this fully).
    • Test your mod with the dependency mod installed to ensure the item is available at runtime.

Finding the Items Format for Modded Items

  • Unlike vanilla items, modded items don’t have a direct Items.SOMETHING equivalent unless the mod provides a public API with such constants (most don’t). Instead, you use ForgeRegistries.ITEMS.getValue() with the item's ResourceLocation as shown above.
  • To get these IDs:
    • Use JEI or a similar mod to see the modid:item_name.
    • Check the mod’s source code or ask the mod author/community for the exact registry name.
    • In-game, you can also use the /give command or debug tools to confirm the ID (e.g., /give @p coolmod:shiny_gem).

Notes

  • Code Locking: If you lock the code back after editing, MCreator might overwrite your changes during the next build. Use "User Code Blocks" (introduced in later MCreator versions) to preserve custom code.
  • Testing: Always test in a Minecraft instance with the dependency mod loaded, or you’ll get errors or missing items.
  • Limitations: MCreator’s UI isn’t designed for this natively, so this method relies on manual code tweaks. Future updates or plugins might simplify this process.

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.