Enchanting Items / Higher Tiers in Villager Trades

Started by gamerat on

Topic category: Help with Minecraft modding (Java Edition)

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Enchanting Items / Higher Tiers in Villager Trades

I followed tbroski's tutorial on adding new trades to villagers, and I want to have the villagers trade enchanted items. I also want certain items to only be unlocked at certain levels. Does anyone know what code to put in?

Joined Apr 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
If you need your recipe to…
Mon, 05/03/2021 - 01:35

If you need your recipe to unlock on certain level you need to find this part

List<VillagerTrades.ITrade> trades = event.getTrades().get(1);

1 is the level of deals you add to change it, just replace with any number between 1-5

If you need the recipes to have different levels, create a new list like this and change the value to 1-5

e.g

@SubscribeEvent
    public void addNewTrade(VillagerTradesEvent event) {
        if (event.getType() == VillagerProfession.BUTCHER) {
            List<VillagerTrades.ITrade> trades = event.getTrades().get(1); // Level 1 recipes
            List<VillagerTrades.ITrade> trades2 = event.getTrades().get(2); // Level 2 recipes
            trades.add(new BasicTrade(new ItemStack(Items.GOLD_INGOT), new ItemStack(Items.CARROT), 1, 0, 0)); // This is level 1 recipe
            trades.add(new BasicTrade(new ItemStack(Items.GOLD_INGOT), new ItemStack(Items.PORKCHOP), 1, 0, 0));
            trades2.add(new BasicTrade(new ItemStack(Items.GOLD_INGOT), new ItemStack(Items.POWERED_RAIL), 1, 0, 0)); // This is level 2 recipe
            trades2.add(new BasicTrade(new ItemStack(Items.GOLD_INGOT), new ItemStack(Items.POISONOUS_POTATO), 1, 0, 0));
        }
    }

 

Joined Apr 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Also if you need to get…
Mon, 05/03/2021 - 02:10

Also if you need to get enchanted book with enchantment you can use this

EnchantedBookItem.getEnchantedItemStack(new EnchantmentData(Enchantments.*NAME OF ENCHANTMENT*, *LEVEL*)

Just replace new ItemStack() with this as this already returns ItemStack

I don't know if this is a best way but it works fine.

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
For some reason the…
Mon, 05/03/2021 - 11:42

For some reason the enchanted book code isn't working for me. I notice in your code you have an open ( statement. Is this a problem?

This is my code:

            trades.add(new BasicTrade(new ItemStack(Items.GOLD_INGOT), EnchantedBookItem.getEnchantedItemStack(new EnchantmentData(Enchantments.FLAME, 1), 1, 0, 0));

The console says it expects a ) at ;

Do you have a fix? 

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Also, thanks for the info…
Mon, 05/03/2021 - 11:44

Also, thanks for the info. This is really helpful for me.

Joined Apr 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Oh yeah sorry. I forget 1…
Mon, 05/03/2021 - 12:55

Oh yeah sorry. I forget 1 bracket at the end

EnchantedBookItem.getEnchantedItemStack(new EnchantmentData(Enchantments.*NAME OF ENCHANTMENT*, *LEVEL*))

This should work

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It still doesn't work for me…
Mon, 05/03/2021 - 20:08

It still doesn't work for me, and shows up with more errors. Here is what the console shows:

Executing Gradle task: runClient
Build info: MCreator 2021.1.16710, forge-1.16.5, 64-bit, 8097 MB, Windows 7, JVM 1.8.0_275, JAVA_HOME: C:\Program Files\Pylo\MCreator\jdk
> Task :compileJava
C:\Users\Administrator\MCreatorWorkspaces\opvillagertrades\src\main\java\net\mcreator\opvillagertrades\VillagerTradeAdder.java:49: error: cannot find symbol trades.add(new BasicTrade(new ItemStack(Items.EMERALD), EnchantedBookItem.getEnchantedItemStack(new EnchantmentData(Enchantments.SHARPNESS, 3)), 1, 0, 0));
^
symbol: class EnchantmentData
location: class VillagerTradeAdder
C:\Users\Administrator\MCreatorWorkspaces\opvillagertrades\src\main\java\net\mcreator\opvillagertrades\VillagerTradeAdder.java:49: error: cannot find symbol trades.add(new BasicTrade(new ItemStack(Items.EMERALD), EnchantedBookItem.getEnchantedItemStack(new EnchantmentData(Enchantments.SHARPNESS, 3)), 1, 0, 0));
^
symbol: variable Enchantments
location: class VillagerTradeAdder
C:\Users\Administrator\MCreatorWorkspaces\opvillagertrades\src\main\java\net\mcreator\opvillagertrades\VillagerTradeAdder.java:49: error: cannot find symbol trades.add(new BasicTrade(new ItemStack(Items.EMERALD), EnchantedBookItem.getEnchantedItemStack(new EnchantmentData(Enchantments.SHARPNESS, 3)), 1, 0, 0));
^
symbol: variable EnchantedBookItem
location: class VillagerTradeAdder
C:\Users\Administrator\MCreatorWorkspaces\opvillagertrades\src\main\java\net\mcreator\opvillagertrades\VillagerTradeAdder.java:79: error: cannot find symbol trades1.add(new BasicTrade(new ItemStack(Items.EMERALD), new ItemStack(Items.NETHERITE_PICKAXE), 64, 2, 0));
^
symbol: variable trades1
location: class VillagerTradeAdder
C:\Users\Administrator\MCreatorWorkspaces\opvillagertrades\src\main\java\net\mcreator\opvillagertrades\VillagerTradeAdder.java:80: error: cannot find symbol trades1.add(new BasicTrade(new ItemStack(Items.EMERALD), new ItemStack(Items.NETHERITE_SHOVEL), 64, 3, 0));
^
symbol: variable trades1
location: class VillagerTradeAdder
C:\Users\Administrator\MCreatorWorkspaces\opvillagertrades\src\main\java\net\mcreator\opvillagertrades\VillagerTradeAdder.java:117: error: cannot find symbol trades3.add(new BasicTrade(new ItemStack(Items.IRON_NUGGET), new ItemStack(Items.CAULDRON), 64, 2, 0));
^
symbol: variable trades3
location: class VillagerTradeAdder
6 errors
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 22s
1 actionable task: 1 executed
BUILD FAILED
Task completed in 22 seconds
 

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Have you added imports?…
Mon, 05/03/2021 - 20:38

Have you added imports? Press ctrl + W and it will add them.

Joined Apr 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yeah this guy is right. Have…
Mon, 05/03/2021 - 20:40

Yeah this guy is right. Have you added them?

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I hadn't added them (I never…
Mon, 05/03/2021 - 21:05

I hadn't added them (I never new that you had too in the first place...), anyway, thanks for telling me

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Not to be picky or anything…
Mon, 05/03/2021 - 21:34

Not to be picky or anything... but is there a way to do enchanted items? I tried simply replacing the "EnchantedBookItem" with other items (like 'TridentItem') but it didn't work.

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ands yes, I did add imports
Mon, 05/03/2021 - 21:35

Ands yes, I did add imports