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

Posted

Hello.

 

First of all i want to say that this is my entry project into modding with Forge, so my experience is low. However it has been a good experience so far.

 

So just to try it out, i began creating a very simple mod that adds custom trades to villagers. I wanted them to be able to trade emeralds for enchanted books at a higher rate.

 

So far it works well. I have two classes: My main class, and a TradeHandler. Besides loading configs my main class only has this:

 

VillagerRegistry.instance().registerVillageTradeHandler(1, new TradeHandler());
VillagerRegistry.instance().registerVillageTradeHandler(2, new TradeHandler());
VillagerRegistry.instance().registerVillageTradeHandler(3, new TradeHandler());
VillagerRegistry.instance().registerVillageTradeHandler(4, new TradeHandler());

 

My Trade handler looks like this:

 

public class TradeHandler implements IVillageTradeHandler{

@Override
public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random random)
{
	Random rand = new Random();	
	int Price = 64;

	Enchantment enchantment = Enchantment.enchantmentsBookList[random.nextInt(Enchantment.enchantmentsBookList.length)];
	//Enchantment enchantment = Enchantment.enchantmentsBookList[15];
        ItemStack enchantedBook = new ItemStack(Item.enchantedBook, 1);
        int lvl = MathHelper.getRandomIntegerInRange(rand, enchantment.getMinLevel(), enchantment.getMaxLevel());
        enchantedBook.addEnchantment(enchantment, lvl);
        switch (lvl) {
        	case 1 : Price = Main.lvl1Price;
        			 break;
        	case 2 : Price = Main.lvl2Price;
		 		 break;
        	case 3 : Price = Main.lvl3Price;
		 		 break;
        	case 4 : Price = Main.lvl4Price;
        			 break;
        	case 5 : Price = Main.lvl5Price;
		 		 break;
        }
        
        final String[] highCostBooks = convertStringToArraystring(Main.highPriceEnchantments);
        if(stringContainsItemFromList(enchantment.getTranslatedName(lvl), highCostBooks))
        {
        	Price = Main.highPriceEnchantmentsPrice;
        }

        

	recipeList.add(new MerchantRecipe(new ItemStack(Item.emerald, Price, 0), enchantedBook));
}

public static boolean stringContainsItemFromList(String inputString, String[] items)
{
    for(int i =0; i < items.length; i++)
    {
        if(inputString.contains(items[i]))
        {
            return true;
        }
    }
    return false;
}

public static String[] convertStringToArraystring(String input)
{
	String[] split = input.split(",");
	return split;
}

}

 

My problem is that, on a vanilla minecraft installation my custom trades is shown like 50% of the times.. But on a modded installation where other mods also add trades, i only get a 5% chance of my trade showing on a villager. I want this to have a higher chance. So basicly ..

 

Is it possible to set a higher chance of a specifc trade to get shown ?

 

Thanks in advance !

Could I ask for a clarification of your issue?

 

By "vanilla minecraft installation" do you mean "Forge modded without other mods installed", which would indicate the problem is that your villager trades are getting "crowded out" by villager trades added by other mods?

  • Author

Could I ask for a clarification of your issue?

 

By "vanilla minecraft installation" do you mean "Forge modded without other mods installed", which would indicate the problem is that your villager trades are getting "crowded out" by villager trades added by other mods?

 

Exactly what i mean :-)

Well, I don't know that there is a good way of accomplishing that without crowding other mods' trades in return. There are quite a few methods in the VillagerRegistry that your mod can use to fiddle with the trade manifests. You're probably interested in manipulateTradesForVillager, which would let you directly manipulate the MerchantRecipeList of a given villager, or manageVillagerTrades which is a callback you could use for dealing with them in aggregate.

 

If you want a guaranteed way of accessing your custom trades, would you be willing to consider a custom villager? I understand that this isn't in the original scope of your mod's functionality but I feel it would be a better solution (in terms of compatibility, which is the root of your problem here) than just budging other mods' trades to the side. There are handy methods in the VillagerRegistry for this too, including ones that set the skin and whatnot.

 

TL;DR - Poke through VillagerRegistry.class, the answers are therein!

 

EDIT: Also, 1.6.4?

  • Author

Well, I don't know that there is a good way of accomplishing that without crowding other mods' trades in return. There are quite a few methods in the VillagerRegistry that your mod can use to fiddle with the trade manifests. You're probably interested in manipulateTradesForVillager, which would let you directly manipulate the MerchantRecipeList of a given villager, or manageVillagerTrades which is a callback you could use for dealing with them in aggregate.

 

If you want a guaranteed way of accessing your custom trades, would you be willing to consider a custom villager? I understand that this isn't in the original scope of your mod's functionality but I feel it would be a better solution (in terms of compatibility, which is the root of your problem here) than just budging other mods' trades to the side. There are handy methods in the VillagerRegistry for this too, including ones that set the skin and whatnot.

 

TL;DR - Poke through VillagerRegistry.class, the answers are therein!

 

EDIT: Also, 1.6.4?

 

Ill take a look at that.. Oh and as for the 1.6.4.. I have no intention of releasing a 1.6.4 version.. I have a 1.7.10 version ready which is the one i want to release.. The 1.6.4 is for my self on a server that runs 1.6.4..

 

I dont want to release the 1.6.4 version because in my opinion, staying at older versions just slows the hole progress of upgrading down for everyone :-)

  • Author

A custom villager would surely be a possibility. Also good for the learning.

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.