Java Code Examples for net.minecraft.potion.PotionEffect#getPotion()

The following examples show how to use net.minecraft.potion.PotionEffect#getPotion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DrinkSoymilkRamune.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) {
	if(!worldIn.isRemote){
	if(getEffectList()!=null&&getEffectList().length>0){
		Random rand = worldIn.rand;
		PotionEffect effect1 = getEffectList()[rand.nextInt(getEffectList().length)];
				if (effect1 != null && effect1.getPotion() != null) {
					Potion por = effect1.getPotion();
					int amp = effect1.getAmplifier();
					int dur = effect1.getDuration();
					if (player.isPotionActive(effect1.getPotion())) {
						PotionEffect check = player.getActivePotionEffect(por);
						dur += check.getDuration();
						amp ++;
					}
					player.addPotionEffect(new PotionEffect(effect1.getPotion(), dur, amp));
				}
		
		}
	}
}
 
Example 2
Source File: ContainerPotionCreator.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@SuppressWarnings ("unchecked")
@Override
public void handleInputPacket(PacketCustom packet) {
    ItemStack potion = potionInv.getStackInSlot(0);
    if (potion == null) {
        return;
    }

    boolean add = packet.readBoolean();
    Potion effect = Potion.getPotionById(packet.readUByte());

    NBTTagList effects = potion.getTagCompound().getTagList("CustomPotionEffects", 10);
    NBTTagList newEffects = new NBTTagList();
    for (int i = 0; i < effects.tagCount(); i++) {
        NBTTagCompound tag = effects.getCompoundTagAt(i);
        PotionEffect e = PotionEffect.readCustomPotionEffectFromNBT(tag);
        if (e.getPotion() != effect) {
            newEffects.appendTag(tag);
        }
    }
    if (add) {
        newEffects.appendTag(new PotionEffect(effect, packet.readInt(), packet.readUByte()).writeCustomPotionEffectToNBT(new NBTTagCompound()));
    }
    potion.getTagCompound().setTag("CustomPotionEffects", newEffects);
}
 
Example 3
Source File: BlockPotionFluid.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
    if (!(entityIn instanceof EntityLivingBase) ||
        worldIn.getTotalWorldTime() % 20 != 0) return;
    EntityLivingBase entity = (EntityLivingBase) entityIn;
    for (PotionEffect potionEffect : potionType.getEffects()) {
        if (!potionEffect.getPotion().isInstant()) {
            PotionEffect instantEffect = new PotionEffect(potionEffect.getPotion(), 60, potionEffect.getAmplifier(), true, true);
            entity.addPotionEffect(instantEffect);
        } else {
            potionEffect.getPotion().affectEntity(null, null, entity, potionEffect.getAmplifier(), 1.0);
        }
    }
}
 
Example 4
Source File: ItemLowerOrgansUpgrade.java    From Cyberware with MIT License 5 votes vote down vote up
@SubscribeEvent
public void handleEatFoodEnd(LivingEntityUseItemEvent.Finish event)
{
	EntityLivingBase e = event.getEntityLiving();
	ItemStack stack = event.getItem();
	
	if (e instanceof EntityPlayer && CyberwareAPI.hasCapability(e) && stack != null && (stack.getItem().getItemUseAction(stack) == EnumAction.EAT || stack.getItem().getItemUseAction(stack) == EnumAction.DRINK))
	{
		EntityPlayer p = (EntityPlayer) e;
		ICyberwareUserData cyberware = CyberwareAPI.getCapability(e);
		
		if (CyberwareAPI.isCyberwareInstalled(p, new ItemStack(this, 1, 0)))
		{
			Collection<PotionEffect> toRemove = new ArrayList<PotionEffect>(p.getActivePotionEffects());
			for (PotionEffect pE : toRemove)
			{
				if (pE.getPotion().isBadEffect())
				{
					p.removePotionEffect(pE.getPotion());
				}
			}
			
			Collection<PotionEffect> toAdd = potions.keySet().contains(p.getEntityId()) ? potions.get(p.getEntityId()) : new ArrayList<PotionEffect>();

			for (PotionEffect add : toAdd)
			{
				for (PotionEffect removed : toRemove)
				{
					if (removed.getPotion() == add.getPotion())
					{
						p.addPotionEffect(add);
						break;
					}
				}
			}
		}
	}
}
 
Example 5
Source File: GuiPotionCreator.java    From NotEnoughItems with MIT License 5 votes vote down vote up
private PotionEffect getEffect(Potion potion) {
    ItemStack potionStack = container.potionInv.getStackInSlot(0);
    if (!potionStack.isEmpty() && potionStack.hasTagCompound() && potionStack.getTagCompound().hasKey("CustomPotionEffects")) {
        NBTTagList potionTagList = potionStack.getTagCompound().getTagList("CustomPotionEffects", 10);
        for (int i = 0; i < potionTagList.tagCount(); i++) {
            PotionEffect effect = PotionEffect.readCustomPotionEffectFromNBT(potionTagList.getCompoundTagAt(i));
            if (effect.getPotion() == potion) {
                return effect;
            }
        }
    }
    return null;
}
 
Example 6
Source File: GuiHandyBag.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void updateActivePotionEffects()
{
    boolean hasVisibleEffect = false;

    for (PotionEffect potioneffect : this.mc.player.getActivePotionEffects())
    {
        Potion potion = potioneffect.getPotion();

        if (potion.shouldRender(potioneffect))
        {
            hasVisibleEffect = true;
            break;
        }
    }

    if (this.mc.player.getActivePotionEffects().isEmpty() == false && hasVisibleEffect)
    {
        if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiScreenEvent.PotionShiftEvent(this)))
        {
            this.guiLeft = (this.width - this.xSize) / 2;
        }
        else
        {
            this.guiLeft = 160 + (this.width - this.xSize - 200) / 2;
        }

        this.hasActivePotionEffects = true;
    }
    else
    {
        this.guiLeft = (this.width - this.xSize) / 2;
        this.hasActivePotionEffects = false;
    }
}
 
Example 7
Source File: GTUtility.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static PotionEffect copyPotionEffect(PotionEffect sample) {
    PotionEffect potionEffect = new PotionEffect(sample.getPotion(), sample.getDuration(), sample.getAmplifier(), sample.getIsAmbient(), sample.doesShowParticles());
    potionEffect.setCurativeItems(sample.getCurativeItems());
    return potionEffect;
}
 
Example 8
Source File: ItemSkinUpgrade.java    From Cyberware with MIT License 4 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGH)
public void handleMissingEssentials(CyberwareUpdateEvent event)
{
	EntityLivingBase e = event.getEntityLiving();
	
	ItemStack test = new ItemStack(this, 1, 3);
	if (CyberwareAPI.isCyberwareInstalled(e, test))
	{
		boolean last = lastImmuno(e);
		boolean powerUsed = e.ticksExisted % 20 == 0 ? CyberwareAPI.getCapability(e).usePower(test, getPowerConsumption(test)) : last;
		
		if (!powerUsed && e instanceof EntityPlayer && e.ticksExisted % 100 == 0 && !e.isPotionActive(CyberwareContent.neuropozyneEffect))
		{
			e.attackEntityFrom(EssentialsMissingHandler.lowessence, 2F);
		}
		
		if (potions.containsKey(e.getEntityId()))
		{
			Collection<PotionEffect> potionsLastActive = potions.get(e.getEntityId());
			Collection<PotionEffect> currentEffects = e.getActivePotionEffects();
			for (PotionEffect cE : currentEffects)
			{
				if (cE.getPotion() == MobEffects.POISON || cE.getPotion() == MobEffects.HUNGER)
				{
					boolean found = false;
					for (PotionEffect lE : potionsLastActive)
					{
						if (lE.getPotion() == cE.getPotion() && lE.getAmplifier() == cE.getAmplifier())
						{
							found = true;
							break;
						}
					}
					
					if (!found)
					{
						e.addPotionEffect(new PotionEffect(cE.getPotion(), (int) (cE.getDuration() * 1.8F), cE.getAmplifier(), cE.getIsAmbient(), cE.doesShowParticles()));
					}
				}
			}
		}
		potions.put(e.getEntityId(), e.getActivePotionEffects());
	}
	else
	{
		lastImmuno.remove(e.getEntityId());
		potions.remove(e.getEntityId());
	}
}
 
Example 9
Source File: CreativeMenuHandler.java    From Cyberware with MIT License 4 votes vote down vote up
@SubscribeEvent
public void handleCreativeInventory(BackgroundDrawnEvent event)
{
	if (event.getGui() instanceof GuiContainerCreative)
	{
		int selectedTabIndex = ReflectionHelper.getPrivateValue(GuiContainerCreative.class, (GuiContainerCreative) event.getGui(), 2);

		if (selectedTabIndex == Cyberware.creativeTab.getTabIndex())
		{
			GuiContainerCreative gui = (GuiContainerCreative) event.getGui();
			int i = (gui.width - 136) / 2;
			int j = (gui.height - 195) / 2;
			
			int xSize = 29;
			int ySize = 129;
			
			int xOffset = 0;
			boolean hasVisibleEffect = false;
			for(PotionEffect potioneffect : mc.thePlayer.getActivePotionEffects())
			{
				Potion potion = potioneffect.getPotion();
				if(potion.shouldRender(potioneffect)) {
					hasVisibleEffect = true; break;
				}
			}
			if (!this.mc.thePlayer.getActivePotionEffects().isEmpty() && hasVisibleEffect)
			{
				xOffset = 59;
			}
			salvaged.xPosition = salvaged.baseX + xOffset;
			manufactured.xPosition = manufactured.baseX + xOffset;

			
			GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
			this.mc.getTextureManager().bindTexture(CEX_GUI_TEXTURES);
			gui.drawTexturedModalRect(i + 166 + xOffset, j + 29, 0, 0, xSize, ySize);
			
			salvaged.visible = true;
			manufactured.visible = true;
		}
		else
		{
			salvaged.visible = false;
			manufactured.visible = false;
		}
	}
}
 
Example 10
Source File: GuiHandyBag.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void drawActivePotionEffects()
{
    int x = this.guiLeft - 124;
    int y = this.guiTop;

    Collection<PotionEffect> collection = this.mc.player.getActivePotionEffects();

    if (collection.isEmpty() == false)
    {
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GlStateManager.disableLighting();
        int entryHeight = 33;

        if (collection.size() > 5)
        {
            entryHeight = 132 / (collection.size() - 1);
        }

        for (PotionEffect potioneffect : Ordering.natural().sortedCopy(collection))
        {
            Potion potion = potioneffect.getPotion();

            if (potion.shouldRender(potioneffect) == false)
            {
                continue;
            }

            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
            this.mc.getTextureManager().bindTexture(INVENTORY_BACKGROUND);
            this.drawTexturedModalRect(x, y, 0, 166, 140, 32);

            if (potion.hasStatusIcon())
            {
                int i1 = potion.getStatusIconIndex();
                this.drawTexturedModalRect(x + 6, y + 7, 0 + i1 % 8 * 18, 198 + i1 / 8 * 18, 18, 18);
            }

            potion.renderInventoryEffect(potioneffect, this, x, y, this.zLevel);

            if (potion.shouldRenderInvText(potioneffect) == false)
            {
                y += entryHeight;
                continue;
            }

            String s1 = I18n.format(potion.getName());
            int amp = potioneffect.getAmplifier();

            if (amp >= 1 && amp <= 3)
            {
                s1 = s1 + " " + I18n.format("enchantment.level." + (amp + 1));
            }

            this.fontRenderer.drawStringWithShadow(s1, (float)(x + 10 + 18), (float)(y + 6), 16777215);
            String s = Potion.getPotionDurationString(potioneffect, 1.0F);
            this.fontRenderer.drawStringWithShadow(s, (float)(x + 10 + 18), (float)(y + 6 + 10), 8355711);
            y += entryHeight;
        }
    }
}
 
Example 11
Source File: EntityWitherWitch.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@Override
public boolean isPotionApplicable(PotionEffect potion) {
  return potion.getPotion() != MobEffects.WITHER && super.isPotionApplicable(potion);
}
 
Example 12
Source File: EntityWitherCat.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@Override
public boolean isPotionApplicable(PotionEffect potion) {
  return potion.getPotion() != MobEffects.WITHER && super.isPotionApplicable(potion);
}