Adding Specific Enchantments on Villager Trade Items - Explain like I'm five plz

Started by SkyCloud on

Topic category: Help with modding (Java Edition)

Last seen on 05:23, 1. Jul 2024
Joined Aug 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Adding Specific Enchantments on Villager Trade Items - Explain like I'm five plz

Hey folks, I'm afraid I've never touched any form of coding a day in my life. MCreator has been a fantastic option to allow me to make custom villager trades without knowing how to code. Sadly, as I am trying add enchanted items, such as a bow with infinity in this example, or add specific potions, the trade options for MCreator do not offer a way to automatically select which specific enchantment you are looking for.

Thus sadly this requires me to manually add some code to specify an enchantment at a certain level that I am trying to obtain. Here's my prepared trade value with a bow being sold by a villager. Can someone show/type me the exact code I need to copy into this format in order to give the bow the infinity enchantment? Hopefully once I can do one, I'll be able to learn from this and create the rest of the enchantments for other items on my own. 

Here's the copy pasted code if any helpful person just wants to copy paste and modify this direct in their reply to me:

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)

public class NewtradeTestNeoModTrades {
@SubscribeEvent
public static void registerTrades(VillagerTradesEvent event) {
if (event.getType() == VillagerProfession.FLETCHER) {
event.getTrades().get(3).add(new BasicItemListing(new ItemStack(Items.EMERALD, 32),
new ItemStack(Items.BOW), 10, 5, 0.05f));
}
}
}