Search in sources :

Example 6 with ItemPotion

use of net.minecraft.item.ItemPotion in project GregTech by GregTechCE.

the class PotionFluids method onCapabilityAttach.

/*
     * Attaches capabilities to potion items, so they can be emptied to drain contained potion
     * and transform into empty glass bottles
     * Also allows filing glass bottles with liquid potion to get potion item
     */
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onCapabilityAttach(AttachCapabilitiesEvent<ItemStack> event) {
    ItemStack itemStack = event.getObject();
    if (itemStack.getItem() instanceof ItemPotion) {
        ResourceLocation resourceLocation = new ResourceLocation("gregtech", "fluid_container");
        PotionItemFluidHandler fluidHandler = new PotionItemFluidHandler(itemStack);
        event.addCapability(resourceLocation, fluidHandler);
    } else if (itemStack.getItem() instanceof ItemGlassBottle) {
        ResourceLocation resourceLocation = new ResourceLocation("gregtech", "fluid_container");
        GlassBottleFluidHandler fluidHandler = new GlassBottleFluidHandler(itemStack, event.getCapabilities().values());
        event.addCapability(resourceLocation, fluidHandler);
    }
}
Also used : ItemPotion(net.minecraft.item.ItemPotion) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack) ItemGlassBottle(net.minecraft.item.ItemGlassBottle) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 7 with ItemPotion

use of net.minecraft.item.ItemPotion in project BetterStorage by copygirl.

the class ItemDrinkingHelmet method use.

public static void use(EntityPlayer player) {
    ItemStack drinkingHelmet = getDrinkingHelmet(player);
    if (drinkingHelmet == null)
        return;
    int uses = StackUtils.get(drinkingHelmet, 0, "uses");
    if (uses <= 0)
        return;
    ItemStack[] potions = StackUtils.getStackContents(drinkingHelmet, 2);
    List<PotionEffect> potionEffects = new ArrayList<PotionEffect>();
    for (ItemStack item : potions) if (item.getItem() instanceof ItemPotion) {
        List<PotionEffect> effects = ((ItemPotion) item.getItem()).getEffects(item);
        if (effects != null)
            potionEffects.addAll(effects);
    }
    for (PotionEffect effect : potionEffects) {
        Potion potion = Potion.potionTypes[effect.getPotionID()];
        PotionEffect active = player.getActivePotionEffect(potion);
        effect = new SmallPotionEffect(effect, active);
        player.addPotionEffect(effect);
    }
    player.worldObj.playSoundAtEntity(player, "random.drink", 0.5F, 0.9F + player.worldObj.rand.nextFloat() * 0.1F);
    if (--uses <= 0)
        setPotions(drinkingHelmet, null);
    else
        StackUtils.set(drinkingHelmet, uses, "uses");
}
Also used : SmallPotionEffect(net.mcft.copy.betterstorage.misc.SmallPotionEffect) ItemPotion(net.minecraft.item.ItemPotion) PotionEffect(net.minecraft.potion.PotionEffect) SmallPotionEffect(net.mcft.copy.betterstorage.misc.SmallPotionEffect) ItemPotion(net.minecraft.item.ItemPotion) Potion(net.minecraft.potion.Potion) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 8 with ItemPotion

use of net.minecraft.item.ItemPotion in project ImmersiveEngineering by BluSunrize.

the class RecipePotionBullets method matches.

@Override
public boolean matches(InventoryCrafting inv, World world) {
    ItemStack bullet = ItemStack.EMPTY;
    ItemStack potion = ItemStack.EMPTY;
    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack stackInSlot = inv.getStackInSlot(i);
        if (!stackInSlot.isEmpty()) {
            if (bullet.isEmpty() && isPotionBullet(stackInSlot))
                bullet = stackInSlot;
            else if (potion.isEmpty() && stackInSlot.getItem() instanceof ItemPotion)
                potion = stackInSlot;
            else
                return false;
        }
    }
    return !bullet.isEmpty() && !potion.isEmpty();
}
Also used : ItemPotion(net.minecraft.item.ItemPotion) ItemStack(net.minecraft.item.ItemStack)

Example 9 with ItemPotion

use of net.minecraft.item.ItemPotion in project ImmersiveEngineering by BluSunrize.

the class RecipePotionBullets method getCraftingResult.

@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
    ItemStack bullet = ItemStack.EMPTY;
    ItemStack potion = ItemStack.EMPTY;
    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack stackInSlot = inv.getStackInSlot(i);
        if (!stackInSlot.isEmpty()) {
            if (bullet.isEmpty() && isPotionBullet(stackInSlot))
                bullet = stackInSlot;
            else if (potion.isEmpty() && stackInSlot.getItem() instanceof ItemPotion)
                potion = stackInSlot;
        }
    }
    ItemStack newBullet = Utils.copyStackWithAmount(bullet, 1);
    ItemNBTHelper.setItemStack(newBullet, "potion", potion.copy());
    return newBullet;
}
Also used : ItemPotion(net.minecraft.item.ItemPotion) ItemStack(net.minecraft.item.ItemStack)

Example 10 with ItemPotion

use of net.minecraft.item.ItemPotion in project ImmersiveEngineering by BluSunrize.

the class EventHandler method onCapabilitiesAttachItem.

@SubscribeEvent
public void onCapabilitiesAttachItem(AttachCapabilitiesEvent<ItemStack> event) {
    if (event.getObject().getItem() instanceof ItemPotion) {
        IFluidHandlerItem potionHandler = new IFluidHandlerItem() {

            boolean isEmpty = false;

            FluidStack potion = null;

            void ensurePotionAvailable() {
                if (potion == null)
                    // Lazy generation since NBT usually isn't wavailable when the event is fired
                    potion = MixerPotionHelper.getFluidStackForType(PotionUtils.getPotionFromItem(event.getObject()), 250);
            }

            @Nonnull
            @Override
            public ItemStack getContainer() {
                if (isEmpty)
                    return new ItemStack(Items.GLASS_BOTTLE);
                else
                    return event.getObject();
            }

            @Override
            public IFluidTankProperties[] getTankProperties() {
                ensurePotionAvailable();
                if (isEmpty)
                    return new IFluidTankProperties[0];
                else
                    return new IFluidTankProperties[] { new FluidTankProperties(potion, 250, false, true) };
            }

            @Override
            public int fill(FluidStack resource, boolean doFill) {
                return 0;
            }

            @Nullable
            @Override
            public FluidStack drain(FluidStack resource, boolean doDrain) {
                ensurePotionAvailable();
                if (isEmpty)
                    return null;
                if (!resource.isFluidEqual(potion))
                    return null;
                return drain(resource.amount, doDrain);
            }

            @Nullable
            @Override
            public FluidStack drain(int maxDrain, boolean doDrain) {
                ensurePotionAvailable();
                if (maxDrain < 250)
                    return null;
                if (doDrain)
                    isEmpty = true;
                return new FluidStack(potion, 250);
            }
        };
        event.addCapability(new ResourceLocation(ImmersiveEngineering.MODID, "potions"), new ICapabilityProvider() {

            @Override
            public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
                return capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY;
            }

            @Nullable
            @Override
            public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
                if (capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY)
                    return CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY.cast(potionHandler);
                return null;
            }
        });
    }
}
Also used : ItemPotion(net.minecraft.item.ItemPotion) FluidTankProperties(net.minecraftforge.fluids.capability.FluidTankProperties) IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ItemPotion (net.minecraft.item.ItemPotion)11 ItemStack (net.minecraft.item.ItemStack)11 ResourceLocation (net.minecraft.util.ResourceLocation)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 Nullable (javax.annotation.Nullable)2 PotionEffect (net.minecraft.potion.PotionEffect)2 EnumFacing (net.minecraft.util.EnumFacing)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 RecipeQuery (blusunrize.immersiveengineering.api.tool.AssemblerHandler.RecipeQuery)1 ChemthrowerEffect (blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect)1 ChemthrowerEffect_Extinguish (blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Extinguish)1 ChemthrowerEffect_Potion (blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Potion)1 DefaultFurnaceAdapter (blusunrize.immersiveengineering.api.tool.ExternalHeaterHandler.DefaultFurnaceAdapter)1 IEFluid (blusunrize.immersiveengineering.common.util.IEFluid)1 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 Permissions (com.minecolonies.coremod.colony.permissions.Permissions)1 ItemScanTool (com.minecolonies.coremod.items.ItemScanTool)1 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1