A bunch of back-end for Potions, as well as a minor glitch fix on the Demon Crystals when broken in incorrect manners.
This commit is contained in:
parent
6790d39c7e
commit
c618f27a87
12 changed files with 537 additions and 1 deletions
|
@ -0,0 +1,114 @@
|
|||
package WayofTime.bloodmagic.recipe.alchemyTable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.potion.PotionUtils;
|
||||
import WayofTime.bloodmagic.potion.BMPotionUtils;
|
||||
import WayofTime.bloodmagic.registry.ModItems;
|
||||
|
||||
public class AlchemyTablePotionAugmentRecipe extends AlchemyTablePotionRecipe
|
||||
{
|
||||
protected double lengthAugment = 0;
|
||||
protected int powerAugment = 0;
|
||||
protected Potion wantedPotion;
|
||||
|
||||
public AlchemyTablePotionAugmentRecipe(int lpDrained, int ticksRequired, int tierRequired, List<ItemStack> inputItems, PotionEffect baseEffect, double lengthAugment, int powerAugment)
|
||||
{
|
||||
super(lpDrained, ticksRequired, tierRequired, inputItems, baseEffect);
|
||||
|
||||
ArrayList<Object> recipe = new ArrayList<Object>();
|
||||
for (ItemStack stack : inputItems)
|
||||
{
|
||||
recipe.add(stack);
|
||||
}
|
||||
recipe.add(getAugmentedPotionFlask(baseEffect));
|
||||
|
||||
this.input = recipe;
|
||||
|
||||
this.wantedPotion = baseEffect.getPotion();
|
||||
this.lengthAugment = lengthAugment;
|
||||
}
|
||||
|
||||
public AlchemyTablePotionAugmentRecipe(int lpDrained, int ticksRequired, int tierRequired, ItemStack inputItem, PotionEffect baseEffect, double lengthAugment, int powerAugment)
|
||||
{
|
||||
this(lpDrained, ticksRequired, tierRequired, Arrays.asList(inputItem), baseEffect, lengthAugment, powerAugment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPotionFlaskValidInput(ItemStack stack)
|
||||
{
|
||||
List<PotionEffect> effectList = PotionUtils.getEffectsFromStack(stack);
|
||||
for (PotionEffect eff : effectList)
|
||||
{
|
||||
if (eff.getPotion() == wantedPotion)
|
||||
{
|
||||
double currentAugment = BMPotionUtils.getLengthAugment(stack, wantedPotion);
|
||||
|
||||
return currentAugment < lengthAugment || eff.getAmplifier() < powerAugment;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getModifiedFlaskForInput(ItemStack inputStack)
|
||||
{
|
||||
if (inputStack == null)
|
||||
{
|
||||
ItemStack outputStack = new ItemStack(ModItems.potionFlask);
|
||||
|
||||
List<PotionEffect> effectList = new ArrayList<PotionEffect>();
|
||||
int potionLength = wantedPotion.isInstant() ? 1 : BMPotionUtils.getAugmentedLength(baseEffect.getDuration(), lengthAugment, powerAugment - baseEffect.getAmplifier());
|
||||
effectList.add(new PotionEffect(wantedPotion, potionLength, baseEffect.getAmplifier()));
|
||||
|
||||
BMPotionUtils.setEffects(outputStack, effectList);
|
||||
|
||||
return outputStack;
|
||||
}
|
||||
|
||||
ItemStack outputStack = inputStack.copy();
|
||||
|
||||
List<PotionEffect> effectList = PotionUtils.getEffectsFromStack(outputStack);
|
||||
List<PotionEffect> newEffectList = new ArrayList<PotionEffect>();
|
||||
|
||||
Iterator<PotionEffect> effectIterator = effectList.iterator();
|
||||
while (effectIterator.hasNext())
|
||||
{
|
||||
PotionEffect effect = effectIterator.next();
|
||||
if (effect.getPotion() == wantedPotion)
|
||||
{
|
||||
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);
|
||||
} else
|
||||
{
|
||||
newEffectList.add(effect);
|
||||
}
|
||||
}
|
||||
|
||||
BMPotionUtils.setEffects(outputStack, newEffectList);
|
||||
|
||||
return outputStack;
|
||||
}
|
||||
|
||||
public static ItemStack getAugmentedPotionFlask(PotionEffect baseEffect)
|
||||
{
|
||||
ItemStack outputStack = new ItemStack(ModItems.potionFlask);
|
||||
|
||||
List<PotionEffect> effectList = new ArrayList<PotionEffect>();
|
||||
effectList.add(baseEffect);
|
||||
|
||||
BMPotionUtils.setEffects(outputStack, effectList);
|
||||
|
||||
return outputStack;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
package WayofTime.bloodmagic.recipe.alchemyTable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.potion.PotionUtils;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import WayofTime.bloodmagic.api.recipe.AlchemyTableRecipe;
|
||||
import WayofTime.bloodmagic.registry.ModItems;
|
||||
|
||||
public class AlchemyTablePotionRecipe extends AlchemyTableRecipe
|
||||
{
|
||||
public static final ItemStack basePotionFlaskStack = new ItemStack(ModItems.potionFlask, 1, OreDictionary.WILDCARD_VALUE);
|
||||
protected PotionEffect baseEffect;
|
||||
|
||||
public static final int temporaryMaximumEffectsOnThePotionFlaskYesThisIsALongFieldItIsJustSoIRemember = 3;
|
||||
|
||||
protected double baseAddedImpurity = 5;
|
||||
|
||||
public AlchemyTablePotionRecipe(int lpDrained, int ticksRequired, int tierRequired, List<ItemStack> inputItems, PotionEffect baseEffect)
|
||||
{
|
||||
super(basePotionFlaskStack, lpDrained, ticksRequired, tierRequired);
|
||||
|
||||
ArrayList<Object> recipe = new ArrayList<Object>();
|
||||
for (ItemStack stack : inputItems)
|
||||
{
|
||||
recipe.add(stack);
|
||||
}
|
||||
recipe.add(basePotionFlaskStack);
|
||||
|
||||
this.input = recipe;
|
||||
this.baseEffect = baseEffect;
|
||||
}
|
||||
|
||||
public AlchemyTablePotionRecipe(int lpDrained, int ticksRequired, int tierRequired, ItemStack inputItem, PotionEffect baseEffect)
|
||||
{
|
||||
this(lpDrained, ticksRequired, tierRequired, Arrays.asList(inputItem), baseEffect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRecipeOutput(List<ItemStack> inputList)
|
||||
{
|
||||
int flaskLocation = -1;
|
||||
for (int x = 0; x < inputList.size(); x++)
|
||||
{
|
||||
ItemStack slot = inputList.get(x);
|
||||
|
||||
if (slot != null)
|
||||
{
|
||||
boolean match = slot.getItem() == ModItems.potionFlask;
|
||||
|
||||
if (match)
|
||||
{
|
||||
flaskLocation = x;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flaskLocation != -1)
|
||||
{
|
||||
return getModifiedFlaskForInput(inputList.get(flaskLocation));
|
||||
}
|
||||
|
||||
return getModifiedFlaskForInput(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(List<ItemStack> checkedList, World world, BlockPos pos)
|
||||
{
|
||||
ArrayList<Object> required = new ArrayList<Object>(input);
|
||||
|
||||
for (int x = 0; x < checkedList.size(); x++)
|
||||
{
|
||||
ItemStack slot = checkedList.get(x);
|
||||
|
||||
if (slot != null)
|
||||
{
|
||||
boolean inRecipe = false;
|
||||
Iterator<Object> req = required.iterator();
|
||||
|
||||
while (req.hasNext())
|
||||
{
|
||||
boolean match = false;
|
||||
|
||||
Object next = req.next();
|
||||
|
||||
if (next instanceof ItemStack)
|
||||
{
|
||||
match = OreDictionary.itemMatches((ItemStack) next, slot, false);
|
||||
} else if (next instanceof List)
|
||||
{
|
||||
Iterator<ItemStack> itr = ((List<ItemStack>) next).iterator();
|
||||
while (itr.hasNext() && !match)
|
||||
{
|
||||
match = OreDictionary.itemMatches(itr.next(), slot, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (match)
|
||||
{
|
||||
if (next instanceof ItemStack && ((ItemStack) next).getItem() == ModItems.potionFlask)
|
||||
{
|
||||
if (!isPotionFlaskValidInput(slot))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inRecipe = true;
|
||||
required.remove(next);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!inRecipe)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return required.isEmpty();
|
||||
}
|
||||
|
||||
public boolean isPotionFlaskValidInput(ItemStack stack)
|
||||
{
|
||||
List<PotionEffect> effectList = PotionUtils.getEffectsFromStack(stack);
|
||||
if (effectList.size() + 1 >= temporaryMaximumEffectsOnThePotionFlaskYesThisIsALongFieldItIsJustSoIRemember)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (PotionEffect eff : effectList)
|
||||
{
|
||||
if (eff.getPotion() == baseEffect.getPotion())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public ItemStack getModifiedFlaskForInput(ItemStack inputStack)
|
||||
{
|
||||
if (inputStack == null)
|
||||
{
|
||||
ItemStack outputStack = new ItemStack(ModItems.potionFlask);
|
||||
|
||||
List<PotionEffect> effectList = new ArrayList<PotionEffect>();
|
||||
effectList.add(baseEffect);
|
||||
|
||||
PotionUtils.appendEffects(outputStack, effectList);
|
||||
|
||||
return outputStack;
|
||||
}
|
||||
|
||||
ItemStack outputStack = inputStack.copy();
|
||||
|
||||
List<PotionEffect> effectList = new ArrayList<PotionEffect>();
|
||||
effectList.add(baseEffect);
|
||||
|
||||
PotionUtils.appendEffects(outputStack, effectList);
|
||||
|
||||
return outputStack;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue