Started by
gamerat
on
Topic category: Help with Minecraft modding (Java Edition)
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?
If you need your recipe to unlock on certain level you need to find this part
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
Also if you need to get enchanted book with enchantment you can use this
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.
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?
Also, thanks for the info. This is really helpful for me.
Oh yeah sorry. I forget 1 bracket at the end
This should work
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
Have you added imports? Press ctrl + W and it will add them.
Yeah this guy is right. Have you added them?
I hadn't added them (I never new that you had too in the first place...), anyway, thanks for telling me
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.
Ands yes, I did add imports