ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/gen/JamVillagerTradeHandler.java

97 lines
4 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("JamVillagerTradeHandler.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015-2016 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.gen;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheJams;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.MathHelper;
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{
2016-05-19 20:05:12 +02:00
private final ArrayList<Trade> trades = new ArrayList<Trade>();
public JamVillagerTradeHandler(){
this.addWants("ingotGold", 5, 7);
this.addWants("cropWheat", 15, 25);
this.addWants("dustRedstone", 25, 40);
2016-04-20 21:39:03 +02:00
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);
this.addWants("dustGlowstone", 12, 22);
}
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);
2016-05-02 17:46:53 +02:00
this.trades.add(new Trade(stacks, minSize, maxSize));
2015-10-03 10:19:40 +02:00
}
public void addWants(ItemStack stack, int minSize, int maxSize){
2016-05-02 17:46:53 +02:00
this.trades.add(new Trade(stack, minSize, maxSize));
2015-10-03 10:19:40 +02:00
}
//@Override
public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random rand){
2016-06-17 23:50:38 +02:00
for(int trade = 0; trade < this.trades.size(); trade++){
for(int want = 0; want < this.trades.get(trade).wants.size(); want++){
ItemStack wantsOne = this.trades.get(trade).wants.get(want);
wantsOne.stackSize = MathHelper.getRandomIntegerInRange(rand, this.trades.get(trade).minStackSize, this.trades.get(trade).maxStackSize);
2015-05-04 17:26:50 +02:00
ItemStack wantsTwo = null;
2015-05-04 17:26:50 +02:00
if(rand.nextInt(3) == 0){
2016-06-17 23:50:38 +02:00
int randomSecondTrade = rand.nextInt(this.trades.size());
for(int randomSecondWant = 0; randomSecondWant < this.trades.get(randomSecondTrade).wants.size(); randomSecondWant++){
wantsTwo = this.trades.get(randomSecondTrade).wants.get(randomSecondWant);
wantsTwo.stackSize = MathHelper.getRandomIntegerInRange(rand, this.trades.get(randomSecondTrade).minStackSize, this.trades.get(randomSecondTrade).maxStackSize);
2015-05-04 17:26:50 +02:00
}
}
2015-10-03 10:16:18 +02:00
if(wantsOne == wantsTwo){
wantsTwo = null;
}
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-05-04 17:26:50 +02:00
public static class Trade{
public final ArrayList<ItemStack> wants = new ArrayList<ItemStack>();
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);
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);
this.minStackSize = minStackSize <= 0 ? 1 : minStackSize;
this.maxStackSize = maxStackSize <= 0 ? 1 : maxStackSize;
2015-05-04 17:26:50 +02:00
}
}
}