Hey was just wondering have you any information on adding a new villager to Minecraft, similar to what is on Thaumcraft where he only sales a specific set of items. So if there any tutorials or some information I can read to help me along with the process.
Thank you.
Rollback Post to RevisionRollBack
I take in all suggestions and comments on my mods, even if I don't reply I have logged it somewhere.
Adding a new villager is pretty easy.. as long as your not making them do anythign crazy. I actually made my own over the past couple days, i dont use forge however but this is what i did. (The reason why mine took a couple days is because i made him an archer so there was a lot more modding that i had to do rather than just making a new guy to buy stuff from)
In the EntityVillager file theres a few fields you need to change. To start off in the function "public String getTexture()" you need to add a new case for your new villager type so it can find the texture for your villager, remember that case number bcuz thats the number that will your new villagers proffession number throughout the rest of the code.
Next in the function "private void addDefaultEquipmentAndRecipies(int par1)". This is where you will set what your new villager sells, go down to where the switch statement starts "switch (this.getProfession())" and using the same number you did in getTexture() add a new case for yours and add the merchant items like it does above (i havent quite looked at exactly how the addMerchantItem and addBlacksmithItem functions work but i think it explains them in a comment above the actual function within the code.. and its pretty self explanitory if you just read over the code. At the very bottom of the file there is also a villager stock list / blacksmith selling list, you also have to put the items you used down here (if theyre not already there) to work in conjunction with the addDefaultEquipmentAndRecipes, addMerchantItem, and addBlacksmithItem.
Finally in the "public void initCreature()" function you should just see one line "this.setProffession(this.worldObj.rand.nextInt(5)); This function sets a random proffession when a new villager is spawned. Just to be clear the rand.nextInt(5) means its picking a random number between 0-4, not 0-5 or 1-5. So if you made your new villager proffession to be number 5 then you would need the number 6 in rand.nextInt(6)
Need a good universal mob farm? Check out the Double Shift Towers. Designed for 1.9 and gets 22,000 Items / Hour with a very simple redstone set up - https://www.youtube.com/watch?v=jL8aoJpjjgU
Adding a new villager is pretty easy.. as long as your not making them do anythign crazy. I actually made my own over the past couple days, i dont use forge however but this is what i did. (The reason why mine took a couple days is because i made him an archer so there was a lot more modding that i had to do rather than just making a new guy to buy stuff from)
In the EntityVillager file theres a few fields you need to change. To start off in the function "public String getTexture()" you need to add a new case for your new villager type so it can find the texture for your villager, remember that case number bcuz thats the number that will your new villagers proffession number throughout the rest of the code.
Next in the function "private void addDefaultEquipmentAndRecipies(int par1)". This is where you will set what your new villager sells, go down to where the switch statement starts "switch (this.getProfession())" and using the same number you did in getTexture() add a new case for yours and add the merchant items like it does above (i havent quite looked at exactly how the addMerchantItem and addBlacksmithItem functions work but i think it explains them in a comment above the actual function within the code.. and its pretty self explanitory if you just read over the code. At the very bottom of the file there is also a villager stock list / blacksmith selling list, you also have to put the items you used down here (if theyre not already there) to work in conjunction with the addDefaultEquipmentAndRecipes, addMerchantItem, and addBlacksmithItem.
Finally in the "public void initCreature()" function you should just see one line "this.setProffession(this.worldObj.rand.nextInt(5)); This function sets a random proffession when a new villager is spawned. Just to be clear the rand.nextInt(5) means its picking a random number between 0-4, not 0-5 or 1-5. So if you made your new villager proffession to be number 5 then you would need the number 6 in rand.nextInt(6)
I still dont get it, what to add to the addmerchantitem and addblacksmithitem cases?
I mean, does blacksmithitem mean selling? and merchant mean buying?
Adding a new villager is pretty easy.. as long as your not making them do anythign crazy. I actually made my own over the past couple days, i dont use forge however but this is what i did. (The reason why mine took a couple days is because i made him an archer so there was a lot more modding that i had to do rather than just making a new guy to buy stuff from)
In the EntityVillager file theres a few fields you need to change. To start off in the function "public String getTexture()" you need to add a new case for your new villager type so it can find the texture for your villager, remember that case number bcuz thats the number that will your new villagers proffession number throughout the rest of the code.
Next in the function "private void addDefaultEquipmentAndRecipies(int par1)". This is where you will set what your new villager sells, go down to where the switch statement starts "switch (this.getProfession())" and using the same number you did in getTexture() add a new case for yours and add the merchant items like it does above (i havent quite looked at exactly how the addMerchantItem and addBlacksmithItem functions work but i think it explains them in a comment above the actual function within the code.. and its pretty self explanitory if you just read over the code. At the very bottom of the file there is also a villager stock list / blacksmith selling list, you also have to put the items you used down here (if theyre not already there) to work in conjunction with the addDefaultEquipmentAndRecipes, addMerchantItem, and addBlacksmithItem.
Finally in the "public void initCreature()" function you should just see one line "this.setProffession(this.worldObj.rand.nextInt(5)); This function sets a random proffession when a new villager is spawned. Just to be clear the rand.nextInt(5) means its picking a random number between 0-4, not 0-5 or 1-5. So if you made your new villager proffession to be number 5 then you would need the number 6 in rand.nextInt(6)
Never mind! i found out blacksmith means buying and merchant means selling.
Are you sure? In the code comments I could have sworn if you made the emerald price negative it meant it was buying, not selling. It seemed to me the only difference when I glanced over that code is that blacksmith seemed to have a slightly random factor on the amount of items he would buy or sell for the emerald. However I'm not at my PC to confirm this right now.
Need a good universal mob farm? Check out the Double Shift Towers. Designed for 1.9 and gets 22,000 Items / Hour with a very simple redstone set up - https://www.youtube.com/watch?v=jL8aoJpjjgU
I've been searching around for a couple days now using this forum, forge and the general internet and no one seems to have any information on how to add villagers with a mod. Specifically on the purpose and use of the forge VillageRegistry class. It appears to be used for this exact thing but there's no simple information on how to actually use it in my mod. I know I could just alter the base files and easily add in the information but it sounds like it would conflict with other mods.
Or would it not? It just seems like it would be simpler to be able to add a line or a method or something to the main mod class registering the villagerid (case?) and type (reference name?) and texture (string /nameGFX/customvillager.png) and of course what it trades with blacksmith and merchant recipes.
Maybe I'm way off base but I thought I'd ask just in case I can get some helpful information.
Alright I found some info on the forge forum. By adding some code to the init method you can call the villager in. By adding a tradehandler class implementing the IVillageTradeHandler you can set a trade to the new type. So far it doesn't seem to spawn at default but I did get them to birth one.
The init code is:
VillagerRegistry.instance().registerVillagerType(villager id), "/yourmodGFX/newvillager.png"); //id must be greater than 6
newvillagerTradeHandler newTradeHandler = new newvillagerTradeHandler();
VillagerRegistry.instance().registerVillageTradeHandler(villager id, newTradeHandler);
VillagerRegistry.instance().getRegisteredVillagers(); \\not sure if this is required. But I didn't see a new one born until i added it
public class newvillagerTradeHandler implements IVillageTradeHandler {
public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipes, Random random) {
// Trade 4 emeralds and 3 apples for a diamond axe
recipes.add(new MerchantRecipe(
new ItemStack(Item.emerald, 4),
new ItemStack(Item.appleRed, 3),
new ItemStack(Item.axeDiamond, 1, 0)));
}
Still working on how to add more recipes and give them random chance like the other villagers. But it all looks like its in villageregistry. Note that for every villager you will need a different tradehandler to give them different trades.
Thank you.
In the EntityVillager file theres a few fields you need to change. To start off in the function "public String getTexture()" you need to add a new case for your new villager type so it can find the texture for your villager, remember that case number bcuz thats the number that will your new villagers proffession number throughout the rest of the code.
Next in the function "private void addDefaultEquipmentAndRecipies(int par1)". This is where you will set what your new villager sells, go down to where the switch statement starts "switch (this.getProfession())" and using the same number you did in getTexture() add a new case for yours and add the merchant items like it does above (i havent quite looked at exactly how the addMerchantItem and addBlacksmithItem functions work but i think it explains them in a comment above the actual function within the code.. and its pretty self explanitory if you just read over the code. At the very bottom of the file there is also a villager stock list / blacksmith selling list, you also have to put the items you used down here (if theyre not already there) to work in conjunction with the addDefaultEquipmentAndRecipes, addMerchantItem, and addBlacksmithItem.
Finally in the "public void initCreature()" function you should just see one line "this.setProffession(this.worldObj.rand.nextInt(5)); This function sets a random proffession when a new villager is spawned. Just to be clear the rand.nextInt(5) means its picking a random number between 0-4, not 0-5 or 1-5. So if you made your new villager proffession to be number 5 then you would need the number 6 in rand.nextInt(6)
Bored enough to watch some vanilla lets plays? http://www.youtube.com/user/Crump3txxix
Need a good universal mob farm? Check out the Double Shift Towers. Designed for 1.9 and gets 22,000 Items / Hour with a very simple redstone set up - https://www.youtube.com/watch?v=jL8aoJpjjgU
I still dont get it, what to add to the addmerchantitem and addblacksmithitem cases?
I mean, does blacksmithitem mean selling? and merchant mean buying?
Modder... some things i made:
- Tiny People/Mythology Mod
- Tameable Chickens mod
- Bee mob mod
- Paper Animals mod
Never mind! i found out blacksmith means buying and merchant means selling.
Modder... some things i made:
- Tiny People/Mythology Mod
- Tameable Chickens mod
- Bee mob mod
- Paper Animals mod
Anyways glad it worked for you
Bored enough to watch some vanilla lets plays? http://www.youtube.com/user/Crump3txxix
Need a good universal mob farm? Check out the Double Shift Towers. Designed for 1.9 and gets 22,000 Items / Hour with a very simple redstone set up - https://www.youtube.com/watch?v=jL8aoJpjjgU
Or would it not? It just seems like it would be simpler to be able to add a line or a method or something to the main mod class registering the villagerid (case?) and type (reference name?) and texture (string /nameGFX/customvillager.png) and of course what it trades with blacksmith and merchant recipes.
Maybe I'm way off base but I thought I'd ask just in case I can get some helpful information.
The init code is:
VillagerRegistry.instance().registerVillagerType(villager id), "/yourmodGFX/newvillager.png"); //id must be greater than 6
newvillagerTradeHandler newTradeHandler = new newvillagerTradeHandler();
VillagerRegistry.instance().registerVillageTradeHandler(villager id, newTradeHandler);
VillagerRegistry.instance().getRegisteredVillagers(); \\not sure if this is required. But I didn't see a new one born until i added it
The newvillagerTradeHandler class should be:
package name.modname.common.core.handlers;
import java.util.Random;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.village.MerchantRecipe;
import net.minecraft.village.MerchantRecipeList;
import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler;
public class newvillagerTradeHandler implements IVillageTradeHandler {
public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipes, Random random) {
// Trade 4 emeralds and 3 apples for a diamond axe
recipes.add(new MerchantRecipe(
new ItemStack(Item.emerald, 4),
new ItemStack(Item.appleRed, 3),
new ItemStack(Item.axeDiamond, 1, 0)));
}
Still working on how to add more recipes and give them random chance like the other villagers. But it all looks like its in villageregistry. Note that for every villager you will need a different tradehandler to give them different trades.