2015-08-29 14:33:25 +02:00
|
|
|
|
/*
|
|
|
|
|
* This file ("JamVillagerTradeHandler.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
|
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
|
*
|
|
|
|
|
* <EFBFBD> 2015 Ellpeck
|
|
|
|
|
*/
|
|
|
|
|
|
2015-04-06 15:51:59 +02:00
|
|
|
|
package ellpeck.actuallyadditions.gen;
|
|
|
|
|
|
|
|
|
|
import cpw.mods.fml.common.registry.VillagerRegistry;
|
|
|
|
|
import ellpeck.actuallyadditions.items.InitItems;
|
|
|
|
|
import ellpeck.actuallyadditions.items.metalists.TheJams;
|
|
|
|
|
import net.minecraft.entity.passive.EntityVillager;
|
|
|
|
|
import net.minecraft.init.Items;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2015-06-29 20:55:56 +02:00
|
|
|
|
import net.minecraft.util.MathHelper;
|
2015-04-06 15:51:59 +02:00
|
|
|
|
import net.minecraft.village.MerchantRecipe;
|
|
|
|
|
import net.minecraft.village.MerchantRecipeList;
|
|
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
public class JamVillagerTradeHandler implements VillagerRegistry.IVillageTradeHandler{
|
|
|
|
|
|
2015-05-04 17:26:50 +02:00
|
|
|
|
private ArrayList<Trade> trades = new ArrayList<Trade>();
|
2015-04-06 15:51:59 +02:00
|
|
|
|
|
|
|
|
|
public JamVillagerTradeHandler(){
|
2015-06-29 20:55:56 +02:00
|
|
|
|
this.addWants("ingotGold", 5, 7);
|
|
|
|
|
this.addWants("cropWheat", 15, 25);
|
|
|
|
|
this.addWants("dustRedstone", 25, 40);
|
|
|
|
|
this.addWants(new ItemStack(Items.bucket), 5, 9);
|
|
|
|
|
this.addWants(new ItemStack(Items.glass_bottle), 12, 17);
|
|
|
|
|
this.addWants(new ItemStack(Items.potionitem), 1, 1);
|
|
|
|
|
this.addWants("ingotIron", 10, 15);
|
2015-05-20 22:39:43 +02:00
|
|
|
|
this.addWants("gemDiamond", 1, 2);
|
2015-06-29 20:55:56 +02:00
|
|
|
|
this.addWants("dustGlowstone", 12, 22);
|
2015-04-06 15:51:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
|
public void addWants(String oredictName, int minSize, int maxSize){
|
|
|
|
|
ArrayList<ItemStack> stacks = (ArrayList<ItemStack>)OreDictionary.getOres(oredictName, false);
|
|
|
|
|
trades.add(new Trade(stacks, minSize, maxSize));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addWants(ItemStack stack, int minSize, int maxSize){
|
|
|
|
|
trades.add(new Trade(stack, minSize, maxSize));
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-06 15:51:59 +02:00
|
|
|
|
@Override
|
2015-05-04 17:26:50 +02:00
|
|
|
|
@SuppressWarnings("all")
|
2015-04-06 15:51:59 +02:00
|
|
|
|
public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random rand){
|
2015-05-04 17:26:50 +02:00
|
|
|
|
for(int i = 0; i < trades.size(); i++){
|
|
|
|
|
for(int j = 0; j < trades.get(i).wants.size(); j++){
|
|
|
|
|
ItemStack wantsTwo = null;
|
|
|
|
|
ItemStack wantsOne = trades.get(i).wants.get(j);
|
|
|
|
|
|
2015-06-29 20:55:56 +02:00
|
|
|
|
wantsOne.stackSize = MathHelper.getRandomIntegerInRange(rand, trades.get(i).minStackSize, trades.get(i).maxStackSize);
|
2015-05-04 17:26:50 +02:00
|
|
|
|
if(rand.nextInt(3) == 0){
|
|
|
|
|
int toGet = rand.nextInt(trades.size());
|
|
|
|
|
for(int k = 0; k < trades.get(toGet).wants.size(); k++){
|
|
|
|
|
wantsTwo = trades.get(toGet).wants.get(k);
|
2015-06-29 20:55:56 +02:00
|
|
|
|
wantsTwo.stackSize = MathHelper.getRandomIntegerInRange(rand, trades.get(k).minStackSize, trades.get(k).maxStackSize);
|
2015-05-04 17:26:50 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-10-03 10:16:18 +02:00
|
|
|
|
if(wantsOne == wantsTwo){
|
|
|
|
|
wantsTwo = null;
|
|
|
|
|
}
|
2015-04-06 15:51:59 +02:00
|
|
|
|
|
2015-05-04 17:26:50 +02:00
|
|
|
|
for(int k = 0; k < TheJams.values().length; k++){
|
2015-05-20 22:39:43 +02:00
|
|
|
|
recipeList.add(new MerchantRecipe(wantsOne, wantsTwo, new ItemStack(InitItems.itemJams, rand.nextInt(3)+1, k)));
|
2015-05-04 17:26:50 +02:00
|
|
|
|
}
|
2015-04-06 15:51:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-04 17:26:50 +02:00
|
|
|
|
public static class Trade{
|
|
|
|
|
|
|
|
|
|
public final ArrayList<ItemStack> wants = new ArrayList<ItemStack>();
|
2015-06-29 20:55:56 +02:00
|
|
|
|
public final int minStackSize;
|
|
|
|
|
public final int maxStackSize;
|
2015-05-04 17:26:50 +02:00
|
|
|
|
|
|
|
|
|
public Trade(ArrayList<ItemStack> wants, int minStackSize, int maxStackSize){
|
|
|
|
|
this.wants.addAll(wants);
|
2015-06-29 20:55:56 +02:00
|
|
|
|
this.minStackSize = minStackSize <= 0 ? 1 : minStackSize;
|
|
|
|
|
this.maxStackSize = maxStackSize <= 0 ? 1 : maxStackSize;
|
2015-05-04 17:26:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Trade(ItemStack want, int minStackSize, int maxStackSize){
|
|
|
|
|
this.wants.add(want);
|
2015-06-29 20:55:56 +02:00
|
|
|
|
this.minStackSize = minStackSize <= 0 ? 1 : minStackSize;
|
|
|
|
|
this.maxStackSize = maxStackSize <= 0 ? 1 : maxStackSize;
|
2015-05-04 17:26:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-06 15:51:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|