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.
Latest News Article
Minecraft Parody: "Grieferman"
Most of you have seen Psy's recent new song, "Gentleman". It's not too often that I run across a parody that's better than the original, but StageFiveTV's parody, "Grieferman", definitely nailed it! Clever lyrics, ...
Minecraft Clips - Videos of the Week
This week, Jess shines a spotlight on some of the best Minecraft videos of the last week, with GassyMexican, SethBling, and more. Enjoy!...
Call of Duty: Ghosts Trailer
Check out this Minecraft-driven re-creation of the COD:G trailer, featured at FPS General! Created by Youtube team FPSNATION, this trailer is sure to entertain, give it a watch!...
Information on adding a new villager? [FORGE]
Started by
Mark719
, Feb 12 2013 11:16 PM
7 replies to this topic
#3
Posted 13 February 2013 - 03:26 PM
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)
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)
#4
Posted 17 February 2013 - 01:48 PM
Crumpetxxix, on 13 February 2013 - 03:26 PM, said:
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)
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?
#5
Posted 17 February 2013 - 02:02 PM
Crumpetxxix, on 13 February 2013 - 03:26 PM, said:
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)
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.
#6
Posted 17 February 2013 - 03:49 PM
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.
Anyways glad it worked for you
Anyways glad it worked for you
#7
Posted 21 February 2013 - 03:40 AM
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.
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.
#8
Posted 22 February 2013 - 02:33 AM
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
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.
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.











