@Override
public void onWornTick(ItemStack stack, EntityLivingBase player) {
Brew brew = getBrew(stack);
if(brew != BotaniaAPI.fallbackBrew && player instanceof EntityPlayer && !player.worldObj.isRemote) {
EntityPlayer eplayer = (EntityPlayer) player;
PotionEffect effect = brew.getPotionEffects(stack).get(0);
float cost = (float) brew.getManaCost(stack) / effect.getDuration() / (1 + effect.getAmplifier()) * 2.5F;
boolean doRand = cost < 1;
if(ManaItemHandler.requestManaExact(stack, eplayer, (int) Math.ceil(cost), false)) {
PotionEffect currentEffect = player.getActivePotionEffect(Potion.potionTypes[effect.getPotionID()]);
if(currentEffect == null || currentEffect.getDuration() < 3) {
PotionEffect applyEffect = new PotionEffect(effect.getPotionID(), 80, effect.getAmplifier());
player.addPotionEffect(applyEffect);
}
if(!doRand || Math.random() < cost)
ManaItemHandler.requestManaExact(stack, eplayer, (int) Math.ceil(cost), true);