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

The following examples show how to use net.minecraft.potion.PotionEffect#getAmplifier() . 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: ItemCybereyeUpgrade.java    From Cyberware with MIT License 6 votes vote down vote up
@SubscribeEvent
public void handleNightVision(CyberwareUpdateEvent event)
{
	EntityLivingBase e = event.getEntityLiving();
	ItemStack testItem = new ItemStack(this, 1, 0);
	if (CyberwareAPI.isCyberwareInstalled(e, testItem) && EnableDisableHelper.isEnabled(CyberwareAPI.getCyberware(e, testItem)))
	{

		e.addPotionEffect(new PotionEffect(MobEffects.NIGHT_VISION, Integer.MAX_VALUE, 53, true, false));
	}
	else
	{
		PotionEffect effect = e.getActivePotionEffect(MobEffects.NIGHT_VISION);
		if (effect != null && effect.getAmplifier() == 53)
		{
			e.removePotionEffect(MobEffects.NIGHT_VISION);
		}
	}
}
 
Example 3
Source File: VanillaWares.java    From Cyberware with MIT License 6 votes vote down vote up
@SubscribeEvent
public void handleSpiderNightVision(CyberwareUpdateEvent event)
{
	EntityLivingBase e = event.getEntityLiving();
	
	if (CyberwareAPI.isCyberwareInstalled(e, new ItemStack(Items.SPIDER_EYE)))
	{
		e.addPotionEffect(new PotionEffect(MobEffects.NIGHT_VISION, Integer.MAX_VALUE, -53, true, false));
	}
	else
	{
		PotionEffect effect = e.getActivePotionEffect(MobEffects.NIGHT_VISION);
		if (effect != null && effect.getAmplifier() == -53)
		{
			e.removePotionEffect(MobEffects.NIGHT_VISION);
		}
	}
}
 
Example 4
Source File: PotionUtil.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
public static String getFriendlyPotionName(PotionEffect potionEffect) {
    String effectName = I18n.format(potionEffect.getPotion().getName());
    if (potionEffect.getAmplifier() == 1) {
        effectName = effectName + " " + I18n.format("enchantment.level.2");
    } else if (potionEffect.getAmplifier() == 2) {
        effectName = effectName + " " + I18n.format("enchantment.level.3");
    } else if (potionEffect.getAmplifier() == 3) {
        effectName = effectName + " " + I18n.format("enchantment.level.4");
    }

    return effectName;
}
 
Example 5
Source File: AuraEffects.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void doEntityEffect(ChunkCoordinates originTile, Entity e) {
    if(e.worldObj.rand.nextInt(4) == 0) {
        EntityMob mob = (EntityMob) e;
        PotionEffect effect = mob.getActivePotionEffect(RegisteredPotions.ELDRITCH);

        if(effect != null && effect.getAmplifier() > 4) {
            EntityUtils.makeChampion(mob, false);
            mob.removePotionEffect(RegisteredPotions.ELDRITCH.getId());
        } else {
            mob.addPotionEffect(new PotionEffect(RegisteredPotions.ELDRITCH.getId(), MiscUtils.ticksForMinutes(1), effect == null ? 1 : effect.getAmplifier() + 1));
        }
    }
}
 
Example 6
Source File: OvenGlove.java    From NewHorizonsCoreMod with GNU General Public License v3.0 5 votes vote down vote up
private boolean isGlovesResistActive ( EntityPlayer tPlayer )
{
  if( isResistActive( tPlayer ) )
  {
    PotionEffect potion = tPlayer.getActivePotionEffect( Potion.fireResistance );
    if( potion.getDuration() <= potionDuration && potion.getAmplifier() == potionAmplifier && potion.getIsAmbient() == potionAmbient ) {
      return true;
    }
  }
  return false;
}
 
Example 7
Source File: DataHelper.java    From GokiStats with MIT License 5 votes vote down vote up
public static float getFallResistance(EntityLivingBase entity) {
    float resistance = 3.0F;
    PotionEffect potioneffect = entity.getActivePotionEffect(MinecraftEffects.JUMP);
    float bonus = potioneffect != null ? potioneffect.getAmplifier() + 1 : 0.0F;
    // TODO check if this work as float...

    return resistance + bonus;
}
 
Example 8
Source File: PotionTimeSlow.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static float timeScale(Entity entity) {
	// TODO: 10/6/18 make this apply to more than just the potion?

	if (entity instanceof EntityLivingBase) {
		PotionEffect effect = ModPotions.TIME_SLOW.getEffect((EntityLivingBase) entity);
		if (effect != null)
			if(effect.getAmplifier() >= 19) return 0f;  // if 20 (or over for some reason) just return 0
			else return 1f / (effect.getAmplifier() + 1.5f);
	}

	return -1f;
}
 
Example 9
Source File: PotionCrash.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
public void fall(LivingFallEvent e) {
	EntityLivingBase entitySource = e.getEntityLiving();
	PotionEffect crash = entitySource.getActivePotionEffect(this);
	if (crash == null) return;

	PotionEffect jump = entitySource.getActivePotionEffect(MobEffects.JUMP_BOOST);
	float f = (jump == null) ? 0.0f : (jump.getAmplifier() + 1);
	float damage = MathHelper.clamp((e.getDistance() - 3.0f - f) * e.getDamageMultiplier() * 2, 0, 10f);

	float range = damage / 10f + Math.max(crash.getAmplifier(), 5);

	if (damage > 0.0f) {
		e.setDamageMultiplier(e.getDamageMultiplier() / (crash.getAmplifier() + 2));
		List<EntityLivingBase> entities = entitySource.world.getEntitiesWithinAABB(EntityLivingBase.class, entitySource.getEntityBoundingBox().grow(range * 2));
		entities.stream().filter(entity -> entity != entitySource && entity.onGround).forEach(entity -> {
			entity.attackEntityFrom(damageSourceEarthquake(entitySource), range);
			entity.motionY = range / 10.0;
			entity.velocityChanged = true;
		});

		if (!entitySource.world.isRemote) for (BlockPos pos : BlockPos.getAllInBoxMutable(
				new BlockPos(entitySource.getPositionVector())
						.add(-range,
								-2,
								-range),
				new BlockPos(entitySource.getPositionVector())
						.add(range,
								0,
								range))) {
			IBlockState state = entitySource.world.getBlockState(pos);
			if (state.isFullCube()) entitySource.world.playEvent(2001, pos.toImmutable(), Block.getStateId(state));
		}
	}
}
 
Example 10
Source File: PotionLowGrav.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void jump(LivingEvent.LivingJumpEvent event) {
	EntityLivingBase entity = event.getEntityLiving();
	if (!entity.isPotionActive(this)) return;

	PotionEffect effect = entity.getActivePotionEffect(this);
	if (effect == null) return;

	entity.motionY = effect.getAmplifier() / 3.0;
}
 
Example 11
Source File: ShowArmor.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
private void drawPotionEffects(EntityLiving entity) {
    int i = 100;
    int j = 10;
    boolean flag = true;
    Collection collection = entity.getActivePotionEffects();
    if (!collection.isEmpty()) {
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glDisable(GL11.GL_LIGHTING);
        int k = 33;

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

        for (Iterator iterator = entity.getActivePotionEffects().iterator(); iterator.hasNext(); j += k) {
            PotionEffect potioneffect = (PotionEffect) iterator.next();
            Potion potion = Potion.potionTypes[potioneffect.getPotionID()];
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            Wrapper.INSTANCE.mc().getTextureManager().bindTexture(new ResourceLocation("textures/gui/container/inventory.png"));
            this.drawTexturedModalRect(i, j, 0, 166, 140, 32);

            if (potion.hasStatusIcon()) {
                int l = potion.getStatusIconIndex();
                this.drawTexturedModalRect(i + 6, j + 7, l % 8 * 18, 198 + l / 8 * 18, 18, 18);
            }

            potion.renderInventoryEffect(i, j, potioneffect, Wrapper.INSTANCE.mc());
            String s1 = I18n.format(potion.getName());

            s1 += " " + potioneffect.getAmplifier();

            Wrapper.INSTANCE.fontRenderer().drawStringWithShadow(s1, i + 10 + 18, j + 6, 16777215);
            String s = Potion.getDurationString(potioneffect);
            Wrapper.INSTANCE.fontRenderer().drawStringWithShadow(s, i + 10 + 18, j + 6 + 10, 8355711);
        }
    }
}
 
Example 12
Source File: FovModifier.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
@InvokeEvent
public void fovChange(FovUpdateEvent event) {
    float base = 1.0F;

    if (event.getPlayer().isSprinting()) {
        base += (float) (0.15000000596046448 * Settings.SPRINTING_FOV_MODIFIER);
    }

    if (event.getPlayer().getItemInUse() != null && event.getPlayer().getItemInUse().getItem().equals(Items.bow)) {
        int duration = (int) Math.min(event.getPlayer().getItemInUseDuration(), MAX_BOW_TICKS);
        float modifier = MODIFIER_BY_TICK.get(duration);
        base -= modifier * Settings.BOW_FOV_MODIFIER;
    }

    Collection<PotionEffect> effects = event.getPlayer().getActivePotionEffects();
    for (PotionEffect effect : effects) {
        if (effect.getPotionID() == 1) {
            base += (MODIFIER_SPEED * (effect.getAmplifier() + 1) * Settings.SPEED_FOV_MODIFIER);
        }

        if (effect.getPotionID() == 2) {
            base += (MODIFIER_SLOWNESS * (effect.getAmplifier() + 1) * Settings.SLOWNESS_FOV_MODIFIER);
        }
    }

    event.setNewFov(base);
}
 
Example 13
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 14
Source File: ModuleEffectShatter.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
	public boolean run(@NotNull World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
		Entity targetEntity = spell.getVictim(world);
		Entity caster = spell.getCaster(world);
		BlockPos pos = spell.getTargetPos();

		if (pos == null) return false;

		double potency = spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell) / 2;

		if (!spellRing.taxCaster(world, spell, true)) return false;

		if (targetEntity instanceof EntityLivingBase) {
			
			PotionEffect slowness = ((EntityLivingBase) targetEntity).getActivePotionEffect(MobEffects.SLOWNESS);
			PotionEffect frost = ((EntityLivingBase) targetEntity).getActivePotionEffect(ModPotions.SLIPPERY);
			int mult = 0;
			if (slowness != null)
				mult += slowness.getAmplifier() + 1;
			if (frost != null)
				mult += frost.getAmplifier() + 1;
			potency *= 1 + mult * 0.5;
			
			int invTime = targetEntity.hurtResistantTime;
			targetEntity.hurtResistantTime = 0;

			world.playSound(null, pos, ModSounds.MARBLE_EXPLOSION, SoundCategory.NEUTRAL, 2, RandUtil.nextFloat(0.8f, 1.2f));
			world.playSound(null, pos, ModSounds.FIREWORK, SoundCategory.NEUTRAL, 2, RandUtil.nextFloat(0.8f, 1.2f));
			if (caster instanceof EntityLivingBase)
			{
				((EntityLivingBase) caster).setLastAttackedEntity(targetEntity);
				if (caster instanceof EntityPlayer)
					targetEntity.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) caster).setMagicDamage(), (float) potency);
				else
					targetEntity.attackEntityFrom(new DamageSource("generic").setMagicDamage(), (float) potency);
			}
			else
				targetEntity.attackEntityFrom(new DamageSource("generic").setMagicDamage(), (float) potency);
			
			targetEntity.hurtResistantTime = invTime;
		}

		// TODO: EffectShatter Sound
//		Vec3d target = spell.getTargetWithFallback();
//		if (target != null)
//			world.playSound(null, new BlockPos(target), ModSounds.CHAINY_ZAP, SoundCategory.NEUTRAL, 0.5f, 1f);
		return true;
	}
 
Example 15
Source File: PotionEffects.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void draw(int x, double y, boolean isConfig) {
    int row = 0;
    double scale = ElementRenderer.getCurrentScale();
    Collection<PotionEffect> effects = new ArrayList<>();

    if (isConfig) {
        effects.add(new PotionEffect(1, 100, 1));
        effects.add(new PotionEffect(3, 100, 2));
    } else {
        effects = Minecraft.getMinecraft().thePlayer.getActivePotionEffects();
    }

    List<String> tmp = new ArrayList<>();

    for (PotionEffect potioneffect : effects) {
        Potion potion = Potion.potionTypes[potioneffect.getPotionID()];

        if (potionIcon) {
            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
            Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("textures/gui/container/inventory.png"));

            if (potion.hasStatusIcon()) {
                int potionStatusIconIndex = potion.getStatusIconIndex();
                drawTexturedModalRect(!ElementRenderer.getCurrent().isRightSided() ? (int) (x / scale) - 20 :
                        (int) (x / scale), (int) ((y + row * 16)) - 4, potionStatusIconIndex % 8 * 18,
                    198 + potionStatusIconIndex / 8 * 18, 18, 18);
            }
        }

        StringBuilder s1 = new StringBuilder(I18n.format(potion.getName()));

        switch (potioneffect.getAmplifier()) {
            case 1:
                s1.append(" ").append(I18n.format("enchantment.level.2"));
                break;
            case 2:
                s1.append(" ").append(I18n.format("enchantment.level.3"));
                break;
            case 3:
                s1.append(" ").append(I18n.format("enchantment.level.4"));
                break;
        }

        String s = Potion.getDurationString(potioneffect);
        String text = s1 + " - " + s;
        tmp.add(text);
        ElementRenderer.draw((int) (x / scale), ((y + row * 16)), text);
        row++;
    }

    width = isConfig ? ElementRenderer.maxWidth(tmp) : 0;
    height = row * 16;
}
 
Example 16
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 17
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 18
Source File: LingeringPotion.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings({ "rawtypes", "unchecked" })
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isComplex) {
	if (stack.getItemDamage() == 0)
		return;

	List<PotionEffect> effects = getEffects(stack);
	HashMultimap<String, AttributeModifier> attributes = HashMultimap.create();

	if (effects == null || effects.isEmpty()) {
		String s = StatCollector.translateToLocal("potion.empty").trim();
		list.add(EnumChatFormatting.GRAY + s);
	} else
		for (PotionEffect potioneffect : effects) {
			String s1 = StatCollector.translateToLocal(potioneffect.getEffectName()).trim();
			Potion potion = Potion.potionTypes[potioneffect.getPotionID()];
			Map<IAttribute, AttributeModifier> map = potion.func_111186_k();

			if (map != null && map.size() > 0)
				for (Entry<IAttribute, AttributeModifier> entry : map.entrySet()) {
					AttributeModifier attributemodifier = entry.getValue();
					AttributeModifier attributemodifier1 = new AttributeModifier(attributemodifier.getName(), potion.func_111183_a(potioneffect.getAmplifier(), attributemodifier), attributemodifier.getOperation());
					attributes.put(entry.getKey().getAttributeUnlocalizedName(), attributemodifier1);
				}

			if (potioneffect.getAmplifier() > 0)
				s1 = s1 + " " + StatCollector.translateToLocal("potion.potency." + potioneffect.getAmplifier()).trim();
			if (potioneffect.getDuration() > 20)
				s1 = s1 + " (" + Potion.getDurationString(potioneffect) + ")";

			if (potion.isBadEffect())
				list.add(EnumChatFormatting.RED + s1);
			else
				list.add(EnumChatFormatting.GRAY + s1);
		}

	if (!attributes.isEmpty()) {
		list.add("");
		list.add(EnumChatFormatting.DARK_PURPLE + StatCollector.translateToLocal("potion.effects.whenDrank"));

		for (Entry<String, AttributeModifier> entry1 : attributes.entries()) {
			AttributeModifier attributemodifier2 = entry1.getValue();
			double d0 = attributemodifier2.getAmount();
			double d1;

			if (attributemodifier2.getOperation() != 1 && attributemodifier2.getOperation() != 2)
				d1 = attributemodifier2.getAmount();
			else
				d1 = attributemodifier2.getAmount() * 100.0D;

			if (d0 > 0.0D)
				list.add(EnumChatFormatting.BLUE + StatCollector.translateToLocalFormatted("attribute.modifier.plus." + attributemodifier2.getOperation(), new Object[] { ItemStack.field_111284_a.format(d1), StatCollector.translateToLocal("attribute.name." + entry1.getKey()) }));
			else if (d0 < 0.0D) {
				d1 *= -1.0D;
				list.add(EnumChatFormatting.RED + StatCollector.translateToLocalFormatted("attribute.modifier.take." + attributemodifier2.getOperation(), new Object[] { ItemStack.field_111284_a.format(d1), StatCollector.translateToLocal("attribute.name." + entry1.getKey()) }));
			}
		}
	}
}
 
Example 19
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;
        }
    }
}