001/*
002 * Forge Mod Loader
003 * Copyright (c) 2012-2013 cpw.
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser Public License v2.1
006 * which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
008 * 
009 * Contributors:
010 *     cpw - implementation
011 */
012
013package cpw.mods.fml.common.modloader;
014
015import java.util.List;
016import java.util.Random;
017
018import com.google.common.collect.Lists;
019
020import net.minecraft.entity.passive.EntityVillager;
021import net.minecraft.item.Item;
022import net.minecraft.src.TradeEntry;
023import net.minecraft.village.MerchantRecipeList;
024import cpw.mods.fml.common.registry.VillagerRegistry;
025import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler;
026
027public class ModLoaderVillageTradeHandler implements IVillageTradeHandler
028{
029    private List<TradeEntry> trades = Lists.newArrayList();
030
031    @Override
032    public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random random)
033    {
034        for (TradeEntry ent : trades)
035        {
036            if (ent.buying)
037            {
038                VillagerRegistry.addEmeraldBuyRecipe(villager, recipeList, random, Item.itemsList[ent.id], ent.chance, ent.min, ent.max);
039            }
040            else
041            {
042                VillagerRegistry.addEmeraldSellRecipe(villager, recipeList, random, Item.itemsList[ent.id], ent.chance, ent.min, ent.max);
043            }
044        }
045    }
046
047    public void addTrade(TradeEntry entry)
048    {
049        trades.add(entry);
050    }
051}