Posted February 16, 201312 yr I can't figure out how to make a new Villager. Does anyone know of a good tutorial on it?
February 16, 201312 yr Add this into your mod's @init method: VillagerRegistry.instance().registerVillagerType(villagerNumberID, "path/to/villager/texture.png"); villagerNumberID has to be greater than 6 (as all ids below that are already taken), and it can go quite high so it's a good idea to start at 50 or something. Adding trades to this villager is a bit more difficult as Forge's trade adding system is a bit broken at the moment. If I find a quick way to do it i'll let ya know.
February 17, 201312 yr Author Thank you. I got the first part down but adding the trades confused me. Thanks for the help anyways. I'll look around some more and if I find anything I'll let you know.
February 18, 201312 yr Here's some code I've successfully used to add trades to villagers. // Called during init void registerTradeHandlers() { VillagerRegistry reg = VillagerRegistry.instance(); SGTradeHandler handler = new SGTradeHandler(); reg.registerVillageTradeHandler(tokraVillagerID, handler); } // Trade handler class public class SGTradeHandler implements IVillageTradeHandler { public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipes, Random random) { // Trade 1 emerald and 3 naquadah ingots for 1 stargate ring block recipes.add(new MerchantRecipe( new ItemStack(Item.emerald, 4), new ItemStack(SGCraft.naquadahIngot, 3), new ItemStack(SGCraft.sgRingBlock, 1, 0))); } }
February 18, 201312 yr Author Thank you so much. And also if anyone is interested after testing around with this if you use a switch for the villager's profession in the Village Handler and put your trades within that under the villagers's ID it will set the trades to specific types of villagers. i.e. @Override public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random random) { switch(villager.getProfession()) { case 59: recipeList.add(new MerchantRecipe(new ItemStack(Item.diamond), (new ItemStack(Item.emerald, 2)), (new ItemStack(Item.pickaxeDiamond)))); recipeList.add(new MerchantRecipe(new ItemStack(Item.diamond), new ItemStack(Item.emerald), new ItemStack(Item.swordDiamond))); recipeList.add(new MerchantRecipe(new ItemStack(Item.diamond), new ItemStack(Item.emerald,2), new ItemStack(Item.axeDiamond))); recipeList.add(new MerchantRecipe(new ItemStack(Item.diamond), new ItemStack(Item.emerald,2), new ItemStack(Item.shovelDiamond))); recipeList.add(new MerchantRecipe(new ItemStack(Item.diamond), new ItemStack(Item.emerald,2), new ItemStack(Item.hoeDiamond))); recipeList.add(new MerchantRecipe(new ItemStack(Item.diamond,2), new ItemStack(Item.emerald,2), new ItemStack(Item.bootsDiamond))); recipeList.add(new MerchantRecipe(new ItemStack(Item.diamond,4), new ItemStack(Item.emerald,4), new ItemStack(Item.plateDiamond))); recipeList.add(new MerchantRecipe(new ItemStack(Item.diamond,2), new ItemStack(Item.emerald,3), new ItemStack(Item.helmetDiamond))); recipeList.add(new MerchantRecipe(new ItemStack(Item.diamond,3), new ItemStack(Item.emerald,4), new ItemStack(Item.legsDiamond))); break; case 60: recipeList.add(new MerchantRecipe(new ItemStack(Item.carrot),new ItemStack(Item.bread))); recipeList.add(new MerchantRecipe(new ItemStack(Item.ingotIron), new ItemStack(Item.bread, 5))); recipeList.add(new MerchantRecipe(new ItemStack(Item.ingotGold),new ItemStack(Item.appleRed, 64))); recipeList.add(new MerchantRecipe(new ItemStack(Item.potato, 9), new ItemStack(Item.coal), new ItemStack(Item.bakedPotato, )); recipeList.add(new MerchantRecipe(new ItemStack(Item.emerald),new ItemStack(Item.appleGold))); break; } }
February 28, 201312 yr I'm trying to make a villager of my own, but it doesn't spawn naturally and I can only obtain it through a spawn egg. How do I get a villager to appear in the game?
February 28, 201312 yr Well to get your villager to spawn, first of all, you'll need some sort of village component to spawn them in. Once you've got that all done, add this line somewhere in the addComponentParts method: this.spawnVillagers(world, box, 3, 16, 3, 1); world is the method's World param, box is the method's StructureBoundingBox param. The next three integers are the position to spawn the villager, and the last integer is the amount. Add this method somewhere else in your Component class. protected int getVillagerType(int par1) { return 0; } replace 0 with whatever you set your villager's ID to. Now when a village generates with that component in it, one of your villagers will spawn too
February 28, 201312 yr I assume I need a VillageHandler to do that, right? What do I need to create a village component?
March 1, 201312 yr Well it's pretty easy. Take a look at how the vanilla Village Components work, and if you can't figure it out from there, I'll try and help you.
February 6, 201411 yr I'd just like to verify that this does indeed work in 1.7.2, besides the fact that the villager ID and skin need to be declared separately, like so. VillagerRegistry.instance().registerVillagerId(villagerId); VillagerRegistry.instance().registerVillagerSkin(villagerId, new ResourceLocation("modid:yourdirectory/villagerSkin.png")); The resource location of "modid:" is in src/main/resources/assets/modid with 'modid' being whatever the id of your mod is.
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.