Search in sources :

Example 1 with ItemGlassBottle

use of net.minecraft.item.ItemGlassBottle 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)

Aggregations

ItemGlassBottle (net.minecraft.item.ItemGlassBottle)1 ItemPotion (net.minecraft.item.ItemPotion)1 ItemStack (net.minecraft.item.ItemStack)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1