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:
WayofTime 2016-07-26 19:05:48 -04:00
parent 6790d39c7e
commit c618f27a87
12 changed files with 537 additions and 1 deletions

View file

@ -0,0 +1,92 @@
package WayofTime.bloodmagic.potion;
import java.util.Collection;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.recipe.alchemyTable.AlchemyTablePotionAugmentRecipe;
import com.google.common.base.Objects;
public class BMPotionUtils
{
public static double getLengthAugment(ItemStack flaskStack, Potion potion)
{
NBTHelper.checkNBT(flaskStack);
NBTTagCompound tag = flaskStack.getTagCompound();
return tag.getDouble(Constants.NBT.POTION_AUGMENT_LENGHT + potion.getName());
}
public static void setLengthAugment(ItemStack flaskStack, Potion potion, double value)
{
if (value < 0)
{
value = 0;
}
NBTHelper.checkNBT(flaskStack);
NBTTagCompound tag = flaskStack.getTagCompound();
tag.setDouble(Constants.NBT.POTION_AUGMENT_LENGHT + potion.getName(), value);
}
public static int getAugmentedLength(int originalLength, double lengthAugment, double powerAugment)
{
return Math.max((int) (originalLength * (Math.pow(8f / 3f, lengthAugment) * Math.pow(0.5, powerAugment))), 1);
}
/**
* Copied from PotionUtils
*
* @param stack
* @param effects
* @return
*/
public static ItemStack setEffects(ItemStack stack, Collection<PotionEffect> effects)
{
if (effects.isEmpty())
{
return stack;
} else
{
NBTTagCompound nbttagcompound = (NBTTagCompound) Objects.firstNonNull(stack.getTagCompound(), new NBTTagCompound());
NBTTagList nbttaglist = new NBTTagList();
for (PotionEffect potioneffect : effects)
{
nbttaglist.appendTag(potioneffect.writeCustomPotionEffectToNBT(new NBTTagCompound()));
}
nbttagcompound.setTag("CustomPotionEffects", nbttaglist);
stack.setTagCompound(nbttagcompound);
return stack;
}
}
public static AlchemyTablePotionAugmentRecipe getLengthAugmentRecipe(int lpDrained, int ticksRequired, int tierRequired, List<ItemStack> inputItems, PotionEffect baseEffect, double lengthAugment)
{
return new AlchemyTablePotionAugmentRecipe(lpDrained, ticksRequired, tierRequired, inputItems, baseEffect, lengthAugment, 0);
}
public static AlchemyTablePotionAugmentRecipe getPowerAugmentRecipe(int lpDrained, int ticksRequired, int tierRequired, List<ItemStack> inputItems, PotionEffect baseEffect, int powerAugment)
{
return new AlchemyTablePotionAugmentRecipe(lpDrained, ticksRequired, tierRequired, inputItems, baseEffect, 0, powerAugment);
}
public static AlchemyTablePotionAugmentRecipe getLengthAugmentRecipe(int lpDrained, int ticksRequired, int tierRequired, ItemStack inputItem, PotionEffect baseEffect, double lengthAugment)
{
return new AlchemyTablePotionAugmentRecipe(lpDrained, ticksRequired, tierRequired, inputItem, baseEffect, lengthAugment, 0);
}
public static AlchemyTablePotionAugmentRecipe getPowerAugmentRecipe(int lpDrained, int ticksRequired, int tierRequired, ItemStack inputItem, PotionEffect baseEffect, int powerAugment)
{
return new AlchemyTablePotionAugmentRecipe(lpDrained, ticksRequired, tierRequired, inputItem, baseEffect, 0, powerAugment);
}
}

View file

@ -0,0 +1,112 @@
package WayofTime.bloodmagic.potion.item;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionUtils;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.client.IVariantProvider;
public class ItemPotionFlask extends Item implements IVariantProvider
{
public ItemPotionFlask()
{
setUnlocalizedName(Constants.Mod.MODID + ".potionFlask");
setCreativeTab(BloodMagic.tabBloodMagic);
setMaxStackSize(1);
setMaxDamage(8);
}
@Override
public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase entityLiving)
{
EntityPlayer player = entityLiving instanceof EntityPlayer ? (EntityPlayer) entityLiving : null;
int remainingUses = stack.getMaxDamage() - stack.getItemDamage();
if (remainingUses <= 0)
{
return stack;
}
if (player == null || !player.capabilities.isCreativeMode)
{
stack.setItemDamage(stack.getItemDamage() + 1);
}
if (!world.isRemote)
{
for (PotionEffect potioneffect : PotionUtils.getEffectsFromStack(stack))
{
entityLiving.addPotionEffect(new PotionEffect(potioneffect));
}
}
return stack;
}
@Override
public int getMaxItemUseDuration(ItemStack stack)
{
return 32;
}
@Override
public EnumAction getItemUseAction(ItemStack stack)
{
return EnumAction.DRINK;
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand)
{
int remainingUses = stack.getMaxDamage() - stack.getItemDamage();
if (remainingUses <= 0)
{
return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
}
player.setActiveHand(hand);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced)
{
PotionUtils.addPotionTooltip(stack, tooltip, 1.0F);
}
// @Override
// @SideOnly(Side.CLIENT)
// public void getSubItems(Item itemIn, CreativeTabs tab, List<ItemStack> subItems)
// {
// for (PotionType potiontype : PotionType.REGISTRY)
// {
// subItems.add(PotionUtils.addPotionToItemStack(new ItemStack(itemIn), potiontype));
// }
// }
@Override
public List<Pair<Integer, String>> getVariants()
{
List<Pair<Integer, String>> ret = new ArrayList<Pair<Integer, String>>();
ret.add(new ImmutablePair<Integer, String>(0, "type=normal"));
return ret;
}
}