Jump to content

How to add custom trades to villagers in 1.10.2


Da9L

Recommended Posts

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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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