2016-07-26 19:05:48 -04:00
|
|
|
package WayofTime.bloodmagic.recipe.alchemyTable;
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
|
|
|
|
import WayofTime.bloodmagic.potion.BMPotionUtils;
|
2016-07-26 19:05:48 -04:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.potion.Potion;
|
|
|
|
import net.minecraft.potion.PotionEffect;
|
|
|
|
import net.minecraft.potion.PotionUtils;
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class AlchemyTablePotionAugmentRecipe extends AlchemyTablePotionRecipe {
|
2016-07-26 19:05:48 -04:00
|
|
|
protected double lengthAugment = 0;
|
|
|
|
protected int powerAugment = 0;
|
|
|
|
protected Potion wantedPotion;
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public AlchemyTablePotionAugmentRecipe(int lpDrained, int ticksRequired, int tierRequired, List<ItemStack> inputItems, PotionEffect baseEffect, double lengthAugment, int powerAugment) {
|
2016-07-26 19:05:48 -04:00
|
|
|
super(lpDrained, ticksRequired, tierRequired, inputItems, baseEffect);
|
|
|
|
|
|
|
|
ArrayList<Object> recipe = new ArrayList<Object>();
|
2017-08-15 21:30:48 -07:00
|
|
|
for (ItemStack stack : inputItems) {
|
2016-07-26 19:05:48 -04:00
|
|
|
recipe.add(stack);
|
|
|
|
}
|
|
|
|
recipe.add(getAugmentedPotionFlask(baseEffect));
|
|
|
|
|
|
|
|
this.input = recipe;
|
|
|
|
|
|
|
|
this.wantedPotion = baseEffect.getPotion();
|
|
|
|
this.lengthAugment = lengthAugment;
|
2016-07-26 19:44:42 -04:00
|
|
|
this.powerAugment = powerAugment;
|
2016-07-26 19:05:48 -04:00
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public AlchemyTablePotionAugmentRecipe(int lpDrained, int ticksRequired, int tierRequired, ItemStack inputItem, PotionEffect baseEffect, double lengthAugment, int powerAugment) {
|
2016-12-12 19:56:36 -08:00
|
|
|
this(lpDrained, ticksRequired, tierRequired, Collections.singletonList(inputItem), baseEffect, lengthAugment, powerAugment);
|
2016-07-26 19:05:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public boolean isPotionFlaskValidInput(ItemStack stack) {
|
2016-07-26 19:05:48 -04:00
|
|
|
List<PotionEffect> effectList = PotionUtils.getEffectsFromStack(stack);
|
2017-08-15 21:30:48 -07:00
|
|
|
for (PotionEffect eff : effectList) {
|
|
|
|
if (eff.getPotion() == wantedPotion) {
|
2016-07-26 19:05:48 -04:00
|
|
|
double currentAugment = BMPotionUtils.getLengthAugment(stack, wantedPotion);
|
|
|
|
|
|
|
|
return currentAugment < lengthAugment || eff.getAmplifier() < powerAugment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public ItemStack getModifiedFlaskForInput(ItemStack inputStack) {
|
2018-02-16 17:10:00 -08:00
|
|
|
if (inputStack.isEmpty()) {
|
2017-08-14 20:53:42 -07:00
|
|
|
ItemStack outputStack = new ItemStack(RegistrarBloodMagicItems.POTION_FLASK);
|
2016-07-26 19:05:48 -04:00
|
|
|
|
|
|
|
List<PotionEffect> effectList = new ArrayList<PotionEffect>();
|
|
|
|
int potionLength = wantedPotion.isInstant() ? 1 : BMPotionUtils.getAugmentedLength(baseEffect.getDuration(), lengthAugment, powerAugment - baseEffect.getAmplifier());
|
2016-07-26 19:56:49 -04:00
|
|
|
effectList.add(new PotionEffect(wantedPotion, potionLength, powerAugment - baseEffect.getAmplifier()));
|
2016-07-26 19:05:48 -04:00
|
|
|
|
|
|
|
BMPotionUtils.setEffects(outputStack, effectList);
|
|
|
|
|
|
|
|
return outputStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack outputStack = inputStack.copy();
|
|
|
|
|
|
|
|
List<PotionEffect> effectList = PotionUtils.getEffectsFromStack(outputStack);
|
|
|
|
List<PotionEffect> newEffectList = new ArrayList<PotionEffect>();
|
|
|
|
|
2016-12-12 19:56:36 -08:00
|
|
|
for (PotionEffect effect : effectList) {
|
|
|
|
if (effect.getPotion() == wantedPotion) {
|
2016-07-26 19:05:48 -04:00
|
|
|
double currentLengthAugment = Math.max(lengthAugment, BMPotionUtils.getLengthAugment(outputStack, wantedPotion));
|
|
|
|
int currentPowerAugment = Math.max(powerAugment, effect.getAmplifier());
|
|
|
|
int potionLength = wantedPotion.isInstant() ? 1 : BMPotionUtils.getAugmentedLength(baseEffect.getDuration(), currentLengthAugment, currentPowerAugment);
|
|
|
|
newEffectList.add(new PotionEffect(wantedPotion, potionLength, currentPowerAugment));
|
|
|
|
BMPotionUtils.setLengthAugment(outputStack, wantedPotion, currentLengthAugment);
|
2016-12-12 19:56:36 -08:00
|
|
|
} else {
|
2016-07-26 19:05:48 -04:00
|
|
|
newEffectList.add(effect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BMPotionUtils.setEffects(outputStack, newEffectList);
|
|
|
|
|
|
|
|
return outputStack;
|
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public static ItemStack getAugmentedPotionFlask(PotionEffect baseEffect) {
|
2017-08-14 20:53:42 -07:00
|
|
|
ItemStack outputStack = new ItemStack(RegistrarBloodMagicItems.POTION_FLASK);
|
2016-07-26 19:05:48 -04:00
|
|
|
|
|
|
|
List<PotionEffect> effectList = new ArrayList<PotionEffect>();
|
|
|
|
effectList.add(baseEffect);
|
|
|
|
|
|
|
|
BMPotionUtils.setEffects(outputStack, effectList);
|
|
|
|
|
|
|
|
return outputStack;
|
|
|
|
}
|
|
|
|
}
|