public VillagerCareer addTrade(int level, ITradeList... trades) { if (level <= 0) throw new IllegalArgumentException("Levels start at 1"); List<ITradeList> levelTrades = level <= this.trades.size() ? this.trades.get(level - 1) : null; if (levelTrades == null) { while (this.trades.size() < level) { levelTrades = Lists.newArrayList(); this.trades.add(levelTrades); } } if (levelTrades == null) //Not sure how this could happen, but screw it { levelTrades = Lists.newArrayList(); this.trades.set(level - 1, levelTrades); } for (ITradeList t : trades) levelTrades.add(t); return this; }
private static ITradeList[] makeTradePalette(ITradeList[]... list){ if(list.length == 1) return list[0]; int totalsize = 0; for(ITradeList[] e : list){ totalsize += e.length; } ITradeList[] concat = new ITradeList[totalsize]; int index = 0; int element = 0; while(index < totalsize){ System.arraycopy(list[element], 0, concat, index, list[element].length); index += list[element].length; element++; } return concat; }
@Override public ItemStack getBuyingStack(ITradeList t) { EmeraldForItems trade = (EmeraldForItems)t; ItemStack stack = new ItemStack(trade.buyingItem, 1, 0); return stack; }
@Override public ItemStack getSellingStack(ITradeList t) { ItemAndEmeraldToItem trade = (ItemAndEmeraldToItem)t; ItemStack stack = trade.sellingItemstack.copy(); return stack; }
@Override public ItemStack getSellingStack(ITradeList t) { ListEnchantedBookForEmeralds trade = (ListEnchantedBookForEmeralds)t; ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK, 1, 0); return stack; }
@Override public ItemStack getSellingStack(ITradeList t) { ListEnchantedItemForEmeralds trade = (ListEnchantedItemForEmeralds)t; ItemStack stack = trade.enchantedItemStack.copy(); return stack; }
@Override public ItemStack getSellingStack(ITradeList t) { ListItemForEmeralds trade = (ListItemForEmeralds)t; ItemStack stack = trade.itemToBuy.copy(); return stack; }
@Override public ItemStack getSellingStack(ITradeList t) { // TreasureMapForEmeralds trade = (TreasureMapForEmeralds)t; ItemStack stack = new ItemStack(Items.FILLED_MAP, 1); return stack; }
private static void clearCareerTrades(VillagerCareer career) { List<List<ITradeList>> trades = new VTTVillagerCareer(career).getTrades(); for (List<ITradeList> careerTrades : trades) { careerTrades.clear(); } trades.clear(); }
private static ITradeList[] makePurchasePalette(int emeraldPrice, int stackSize, Item... items){ ITradeList[] trades = new ITradeList[items.length]; for(int i = 0; i < items.length; i++){ Item item = items[i]; trades[i] = new SimpleTrade( new ItemStack(net.minecraft.init.Items.EMERALD,emeraldPrice,0), fluctuation(emeraldPrice), (ItemStack)null, 0, new ItemStack(item,stackSize,0), 0); } return trades; }
private static ITradeList[] makeSalePalette(int emeraldValue, int stackSize, Item... items){ ITradeList[] trades = new ITradeList[items.length]; for(int i = 0; i < items.length; i++){ Item item = items[i]; trades[i] = new SimpleTrade( new ItemStack(item,stackSize,0), fluctuation(stackSize), (ItemStack)null, 0, new ItemStack(net.minecraft.init.Items.EMERALD,emeraldValue,0), 0); } return trades; }
public ItemStack getBuyingStack(ITradeList trade) { return ItemStack.EMPTY; }
public ItemStack getSellingStack(ITradeList trade) { return ItemStack.EMPTY; }
private static void clearCareerTrades(VillagerCareer career, int careerLevel) { List<ITradeList> trades = new VTTVillagerCareer(career).getTrades(careerLevel); trades.clear(); }
/** * Sorts the trades at each level of a career so that the buying trades appear before the selling trades * @param career The VillagerCareer instance on which to sort the trades */ private static void sortCareerTrades(VillagerCareer career) { // get the trades from the career instance in a modifiable form List<List<ITradeList>> trades = new VTTVillagerCareer(career).getTrades(); // iterate over the trades at each career level for (List<ITradeList> levelTrades : trades) { // sort the trades using a comparator Collections.sort(levelTrades, new Comparator<ITradeList>() { @Override public int compare(ITradeList tradeA, ITradeList tradeB) { // get the appropriate trade handler for the two trades being compared ITradeHandler handlerA = TradeHandlers.tradeHandlers.get(tradeA.getClass()); ITradeHandler handlerB = TradeHandlers.tradeHandlers.get(tradeB.getClass()); if (handlerA != null && handlerB != null) { // if one is a buying trade and the other a selling trade, put the buying trade first if (handlerA instanceof VTTVillagerBuyingHandler && handlerB instanceof VTTVillagerSellingHandler) { return -1; } else if (handlerA instanceof VTTVillagerSellingHandler && handlerB instanceof VTTVillagerBuyingHandler) { return 1; } } // otherwise leave their current positions unmodified return 0; } }); } }
public List<List<ITradeList>> getTrades() { return ReflectionHelper.getFieldValue(careerTradesField, this.career); }
public List<ITradeList> getTrades(int level) { List<List<ITradeList>> trades = this.getTrades(); int index = level - 1; return index >= 0 && index < trades.size() ? trades.get(index) : null; }
public List<ITradeList> getTrades(int level) { return level >= 0 && level < this.trades.size() ? Collections.unmodifiableList(this.trades.get(level)) : null; }
private VillagerCareer init(EntityVillager.ITradeList[][] trades) { for (int x = 0; x < trades.length; x++) this.trades.add(Lists.newArrayList(trades[x])); return this; }
private VillagerCareer init(EntityVillager.ITradeList[][] traids) { return this; }
/** * Creates an ITradeList instanec that randomly adds multiple trades at a time * @param tradeCount Number of trades to add to the merchant's trade menu * @param tradePalette The trades to randomly choose from */ public MultiTradeGenerator(int tradeCount, List<ITradeList> tradePalette){ this.numberOfTrades = Math.min(tradeCount,tradePalette.size()); trades = tradePalette.toArray(new ITradeList[tradePalette.size()]); }