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

Hi. I'm trying to add some custom trades to villagers in 1.10.2. I've done it before in 1.7.10, but i noticed that since the IVillageTradeHandler interface is no longer present in the VillagerRegistry, I cannot do this the way i used to do it. The closest i can seem to find is the IVillageCreationHandler interface, but I'm getting a suspicion that this has nothing to do with trading, but more to do with Village World generation.ย  How would you do this in 1.10.2 ?

Altho the way I mentioned in the topic you posted is to override or cancel the default GUI/trading and then open my own. It seems Da9L may be looking to just "add" to the default villager trading options.

ย 

I've managed to track a location down to "net.minecraftforge.fml.common.registry.VillagerRegistry.class" but other than that, I'm not sure "how" to just add to the default trading.

ย 

EDIT:

Oh wow re-reading that thread I posted in, I also gave the wrong suggestion of just stopping the default trading interface and using a custom one. Oops.

In my mod.

ย 

Trade List:

ย 

package cz.grossik.farmcraft2.village;

ย 

import java.util.Random;

ย 

import javax.annotation.Nonnull;

ย 

import net.minecraft.entity.passive.EntityVillager;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.village.MerchantRecipe;

import net.minecraft.village.MerchantRecipeList;

ย 

public class FC2VillagerTrades

{

public static ItemStack copyStackWithAmount(ItemStack stack, int amount)

{

if(stack==null)

return null;

ItemStack s2 = stack.copy();

s2.stackSize=amount;

return s2;

}

ย 

public static class SeedsForItemstack implements EntityVillager.ITradeList

{

public ItemStack buyingItem;

public EntityVillager.PriceInfo buyAmounts;

ย 

public SeedsForItemstack(@Nonnull ItemStack item, @Nonnull EntityVillager.PriceInfo buyAmounts)

{

this.buyingItem = item;

this.buyAmounts = buyAmounts;

}

ย 

@Override

public void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random)

{

recipeList.add(new MerchantRecipe(copyStackWithAmount(this.buyingItem, this.buyAmounts.getPrice(random)), Items.EMERALD));

}

}

ย 

public static class ItemstackForSeeds implements EntityVillager.ITradeList

{

public ItemStack sellingItem;

public EntityVillager.PriceInfo priceInfo;

ย 

public ItemstackForSeeds(Item par1Item, EntityVillager.PriceInfo priceInfo)

{

this.sellingItem = new ItemStack(par1Item);

this.priceInfo = priceInfo;

}

ย 

public ItemstackForSeeds(ItemStack stack, EntityVillager.PriceInfo priceInfo)

{

this.sellingItem = stack;

this.priceInfo = priceInfo;

}

ย 

@Override

public void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random)

{

int i = 1;

if(this.priceInfo != null)

i = this.priceInfo.getPrice(random);

ItemStack itemstack;

ItemStack itemstack1;

if(i < 0)

{

itemstack = new ItemStack(Items.WHEAT_SEEDS);

itemstack1 = copyStackWithAmount(sellingItem, -i);

} else

{

itemstack = new ItemStack(Items.WHEAT_SEEDS, i, 0);

itemstack1 = copyStackWithAmount(sellingItem, 1);

}

recipeList.add(new MerchantRecipe(itemstack, itemstack1));

}

}

}

ย 

ย 

and register:

ย 

VillagerRegistry.VillagerCareer career_fc2_farmer = new VillagerRegistry.VillagerCareer(villagerProfession_farmer, Main.MODID + ".farmer");
	career_fc2_farmer.addTrade(1, 
			new FC2VillagerTrades.ItemstackForSeeds(ItemHandler.BarleySeeds, new EntityVillager.PriceInfo(1, 2));

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.