Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

  • 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.

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)));
    }

}

  • Author

Thank you so much. ;D

 

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, 8)));

recipeList.add(new MerchantRecipe(new ItemStack(Item.emerald),new ItemStack(Item.appleGold)));

break;

 

}

 

}

  • 2 weeks later...

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?

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 :)

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.

  • 11 months later...

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.