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);
}
}
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");
}
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();
}
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;
}
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;
}
});
}
}
Aggregations