Example usage for net.minecraftforge.event.brewing PotionBrewEvent.Pre getItem

List of usage examples for net.minecraftforge.event.brewing PotionBrewEvent.Pre getItem

Introduction

In this page you can find the example usage for net.minecraftforge.event.brewing PotionBrewEvent.Pre getItem.

Prototype

@Nonnull
    public ItemStack getItem(int index) 

Source Link

Usage

From source file:com.github.liachmodded.uhcreloaded.forge.rule.CancelPotionBrewing.java

License:Open Source License

@SubscribeEvent
public void cancelCertainPotionBrewing(PotionBrewEvent.Pre evt) {
    ItemStack modifier = evt.getItem(3);
    for (int i = 0; i < evt.getLength(); i++) {
        ItemStack stack = evt.getItem(i);
        if (!stack.isEmpty()) {
            ItemStack output = BrewingRecipeRegistry.getOutput(stack, modifier);
            if (output.getItem() instanceof ItemPotion) {
                if (!ConfigHandler.allowBrewingPotionSplash && output.getItem() instanceof ItemSplashPotion) {
                    evt.setCanceled(true);
                    return;
                }//w  w w  . j a v  a2 s. c  o m
                if (!ConfigHandler.allowBrewingPotionLingering
                        && output.getItem() instanceof ItemLingeringPotion) {
                    evt.setCanceled(true);
                    return;
                }
                List<PotionEffect> potionEffects = PotionUtils.getEffectsFromStack(output);
                for (PotionEffect effect : potionEffects) {
                    if (effect.getAmplifier() > ConfigHandler.brewingPotionMaxLevel) {
                        evt.setCanceled(true);
                        return;
                    }
                    if (!ConfigHandler.allowBrewingPotionRegen
                            && effect.getPotion() == MobEffects.REGENERATION) {
                        evt.setCanceled(true);
                        return;
                    }
                }
            }
        }
    }
}

From source file:net.lyonlancer5.mcmp.karasu.event.EventFireHelper.java

License:Apache License

public static boolean onPotionAttemptBrew(ItemStack[] stacks) {
    ItemStack[] tmp = new ItemStack[stacks.length];
    for (int x = 0; x < tmp.length; x++)
        tmp[x] = ItemStack.copyItemStack(stacks[x]);

    PotionBrewEvent.Pre event = new PotionBrewEvent.Pre(tmp);
    if (MinecraftForge.EVENT_BUS.post(event)) {
        boolean changed = false;
        for (int x = 0; x < stacks.length; x++) {
            changed |= ItemStack.areItemStacksEqual(tmp[x], stacks[x]);
            stacks[x] = event.getItem(x);
        }//from w  w w .  ja  v a 2  s.  c  o m
        if (changed)
            onPotionBrewed(stacks);
        return true;
    }
    return false;
}