February 11, 201411 yr implement IVillageTradeHandler on a class (I called mine VillagerTradeHandler) add this in your FMLInitializationEvent VillagerRegistry.instance().registerVillageTradeHandler(<villagerID>, <class implementing IVillageTradeHandler >); In manipulateTradesForVillager you just need to use villager.getProfession() to make sure your editing the villager you want. Then use recipeList.add(new MerchantRecipe(<itemstack wanted by the villager>, <itemstack recieved by the player>)); to add the trade. Using EntityVillageraddDefaultEquipmentAndRecipies you can figure out what number is for what profession. Trimmed version of my code: @EventHandler public void load(FMLInitializationEvent event) { VillagerTradeHandler.INSTANCE.load(); } public class VillagerTradeHandler implements IVillageTradeHandler { public static VillagerTradeHandler INSTANCE = new VillagerTradeHandler(); public void load() { VillagerRegistry.instance().registerVillageTradeHandler(1, this); VillagerRegistry.instance().registerVillageTradeHandler(2, this); } @Override public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random random) { switch (villager.getProfession()) { case 1: manipulateLibrarianTrades(recipeList); break; case 2: manipulateEnchanterTrades(recipeList); break; } } private void manipulateLibrarianTrades(MerchantRecipeList recipeList) { Item itemMain = Values.itemMain; if (itemMain != null) { recipeList.add(new MerchantRecipe(new ItemStack(Items.emerald), new ItemStack(itemMain, 1, 11))); recipeList.add(new MerchantRecipe(new ItemStack(Items.emerald), new ItemStack(itemMain, 1, 15))); } } private void manipulateEnchanterTrades(MerchantRecipeList recipeList) { Item itemEquipable = Values.itemEquipable; if (itemEquipable != null) { recipeList.add(new MerchantRecipe(new ItemStack(Items.emerald, 2), new ItemStack(itemEquipable, 1, 0))); recipeList.add(new MerchantRecipe(new ItemStack(Items.emerald, 3), new ItemStack(itemEquipable, 1, 1))); } } }
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.