Java Code Examples for net.minecraft.entity.EntityLivingBase#isPotionActive()

The following examples show how to use net.minecraft.entity.EntityLivingBase#isPotionActive() . These examples are extracted from open source projects. 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
@Override
public void performEffect(@Nonnull EntityLivingBase entity, int amplifier) {
	if (!entity.isPotionActive(this)) return;

	double dist = -0.05;
	double shift = 0.175;

	World world = entity.world;
	if (world.containsAnyLiquid(entity.getEntityBoundingBox().offset(0.0, dist + shift, 0.0)) && entity.motionY < 0.5) {
		entity.motionY += 0.15;
	} else if (world.containsAnyLiquid(entity.getEntityBoundingBox().offset(0.0, dist, 0.0)) && entity.motionY < 0.0) {
		entity.motionY = 0.0;
		entity.onGround = true;
	} else if (world.containsAnyLiquid(entity.getEntityBoundingBox().offset(0.0, dist + entity.motionY - 0.05, 0.0)) && entity.motionY < 0.0) {
		entity.setPosition(entity.posX, Math.floor(entity.posY), entity.posZ);
		entity.motionY /= 5;
		entity.onGround = true;
	} else if (entity.motionY < 0) {
		entity.motionY = Math.max(entity.motionY, amplifier * -0.1);
	}

	entity.fallDistance = 0f;
}
 
Example 2
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onTick(LivingEvent.LivingUpdateEvent event) {
	EntityLivingBase e = event.getEntityLiving();
	if(e.isPotionActive(ModPotions.TIME_SLOW) && timeScale(e) == 0) {
		boolean shouldFreeze = true;
		if(e.isDead || e.getHealth() <= 0) {
			shouldFreeze = false;
		}
		if(e instanceof EntityDragon && ((EntityDragon) e).getPhaseManager().getCurrentPhase().getType() == PhaseList.DYING) {
			shouldFreeze = false;
		}
		if(shouldFreeze) {
			handleImportantEntityTicks(e);
			event.setCanceled(true);
		}
	}
}
 
Example 3
protected void attackWithPotion(EntityLivingBase target) {
	double targetY = target.posY + (double) target.getEyeHeight() - 1.100000023841858D;
	double targetX = target.posX + target.motionX - this.posX;
	double d2 = targetY - this.posY;
	double targetZ = target.posZ + target.motionZ - this.posZ;

	float f = MathHelper.sqrt(targetX * targetX + targetZ * targetZ);
	PotionType potiontype = PotionTypes.HARMING;

	if (f >= 8.0F && !target.isPotionActive(MobEffects.SLOWNESS)) {
		potiontype = PotionTypes.SLOWNESS;
	} else if (target.getHealth() >= 8.0F && !target.isPotionActive(MobEffects.POISON)) {
		potiontype = PotionTypes.POISON;
	} else if (f <= 3.0F && !target.isPotionActive(MobEffects.WEAKNESS) && this.rand.nextFloat() < 0.25F) {
		potiontype = PotionTypes.WEAKNESS;
	}

	EntityPotion entitypotion = new EntityPotion(this.world, this,
			PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION), potiontype));
	entitypotion.rotationPitch -= -20.0F;
	entitypotion.shoot(targetX, d2 + (double) (f * 0.2F), targetZ, 0.75F, 8.0F);

	this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_WITCH_THROW, this.getSoundCategory(), 1.0F,
			0.8F + this.rand.nextFloat() * 0.4F);
	this.world.spawnEntity(entitypotion);
}
 
Example 4
Source Project: Et-Futurum   File: EntityLingeringEffect.java    License: The Unlicense 6 votes vote down vote up
@Override
public void applyEntityCollision(Entity e) {
	if (!(e instanceof EntityLivingBase))
		return;
	EntityLivingBase entity = (EntityLivingBase) e;
	List<PotionEffect> effects = ((LingeringPotion) ModItems.lingering_potion).getEffects(stack);
	boolean addedEffect = false;

	for (PotionEffect effect : effects) {
		int effectID = effect.getPotionID();
		if (Potion.potionTypes[effectID].isInstant()) {
			Potion.potionTypes[effectID].affectEntity(thrower, entity, effect.getAmplifier(), 0.25);
			addedEffect = true;
		} else if (!entity.isPotionActive(effectID)) {
			entity.addPotionEffect(effect);
			addedEffect = true;
		}
	}

	if (addedEffect) {
		int ticks = dataWatcher.getWatchableObjectInt(TICKS_DATA_WATCHER);
		if (setTickCount(ticks + 5 * 20)) // Add 5 seconds to the expiration time (decreasing radius by 0.5 blocks)
			return;
	}
}
 
Example 5
private static boolean shouldBounce(EntityLivingBase entity) {
	if (entity.isPotionActive(ModPotions.BOUNCING)) {
		return true;
	} else {
		for (BouncyBlock block : INSTANCE.blocks) {
			if (block.doesMatch(entity)) {
				return true;
			}
		}
	}
	return false;
}
 
Example 6
@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 7
@SubscribeEvent
public void fall(LivingFallEvent event) {
	EntityLivingBase entity = event.getEntityLiving();
	if (!entity.isPotionActive(this)) return;

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

	event.setDistance((float) (event.getDistance() / (effect.getAmplifier() + 0.5)));
}
 
Example 8
@SubscribeEvent
public void flyableFall(PlayerFlyableFallEvent event) {
	EntityLivingBase entity = event.getEntityLiving();
	if (!entity.isPotionActive(this)) return;

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

	event.setDistance((float) (event.getDistance() / (effect.getAmplifier() + 0.5)));
}
 
Example 9
@Override
public void performEffect(@Nonnull EntityLivingBase entity, int amplifier) {
	if (!entity.isPotionActive(this)) return;

	if (HEALTH_MAP.containsKey(entity.getUniqueID())) {
		//	if (RandUtil.nextInt(500) == 0) {
		entity.setHealth(HEALTH_MAP.get(entity.getUniqueID()));
		//		HEALTH_MAP.put(entity.getUniqueID(), entity.getHealth());
		//	}
	}
}
 
Example 10
private static void handleImportantEntityTicks(EntityLivingBase e) {
	if (e.hurtTime > 0) {
		e.hurtTime--;
	}
	if (e.hurtResistantTime > 0) {
		e.hurtResistantTime--;
	}

	e.prevLimbSwingAmount = e.limbSwingAmount;
	e.prevRenderYawOffset = e.renderYawOffset;
	e.prevRotationPitch = e.rotationPitch;
	e.prevRotationYaw = e.rotationYaw;
	e.prevRotationYawHead = e.rotationYawHead;
	e.prevSwingProgress = e.swingProgress;
	e.prevDistanceWalkedModified = e.distanceWalkedModified;
	e.prevCameraPitch = e.cameraPitch;

	if(e.isPotionActive(ModPotions.TIME_SLOW) && timeScale(e) == 0) {
		PotionEffect pe = e.getActivePotionEffect(ModPotions.TIME_SLOW);
		if (!pe.onUpdate(e)) {
			if (!e.world.isRemote) {
				e.removePotionEffect(ModPotions.TIME_SLOW);
			}
		}
	}

	if(e instanceof EntityDragon) {
		IPhase phase = ((EntityDragon) e).getPhaseManager().getCurrentPhase();
		if(phase.getType() != PhaseList.HOLDING_PATTERN && phase.getType() != PhaseList.DYING) {
			((EntityDragon) e).getPhaseManager().setPhase(PhaseList.HOLDING_PATTERN);
		}
	}
}
 
Example 11
Source Project: Cyberware   File: ItemHeartUpgrade.java    License: MIT License 5 votes vote down vote up
protected float applyPotionDamageCalculations(EntityLivingBase e, DamageSource source, float damage)
{
	if (source.isDamageAbsolute())
	{
		return damage;
	}
	else
	{
		if (e.isPotionActive(MobEffects.RESISTANCE) && source != DamageSource.outOfWorld)
		{
			int i = (e.getActivePotionEffect(MobEffects.RESISTANCE).getAmplifier() + 1) * 5;
			int j = 25 - i;
			float f = damage * (float)j;
			damage = f / 25.0F;
		}

		if (damage <= 0.0F)
		{
			return 0.0F;
		}
		else
		{
			int k = EnchantmentHelper.getEnchantmentModifierDamage(e.getArmorInventoryList(), source);

			if (k > 0)
			{
				damage = CombatRules.getDamageAfterMagicAbsorb(damage, (float)k);
			}

			return damage;
		}
	}
}
 
Example 12
public static int getFortuneLevel(EntityLivingBase entity) {
    int fortuneLevel = getRealEnchantmentLevel(Enchantment.fortune.effectId, entity.getHeldItem());
    if(entity.isPotionActive(RegisteredPotions.POTION_LUCK)) {
        int lvl = entity.getActivePotionEffect(RegisteredPotions.POTION_LUCK).getAmplifier() + 1; //Amplifier 0-indexed
        fortuneLevel += lvl;
    }
    return fortuneLevel;
}
 
Example 13
public static int getLootingLevel(EntityLivingBase entity) {
    int lootingLevel = getRealEnchantmentLevel(Enchantment.looting.effectId, entity.getHeldItem());
    if(entity.isPotionActive(RegisteredPotions.POTION_LUCK)) {
        int lvl = entity.getActivePotionEffect(RegisteredPotions.POTION_LUCK).getAmplifier() + 1; //Amplifier 0-indexed
        lootingLevel += lvl;
    }
    return lootingLevel;
}
 
Example 14
Source Project: Production-Line   File: PLPotion.java    License: MIT License 5 votes vote down vote up
public void applyPotion(EntityLivingBase entityLivingBase, int durationTime, int level) {
    if (entityLivingBase.isPotionActive(salty)) {
        level += ((PLEffect) entityLivingBase.getActivePotionEffect(salty)).level;
    }

    PLEffect effect = new PLEffect(this, durationTime, level);

    if (this == salty && FMLCommonHandler.instance().getSide() == Side.CLIENT) {
        effect.setPotionDurationMax(true);
    }

    effect.setCurativeItems(this.curativeItems);
    entityLivingBase.addPotionEffect(effect);
}
 
Example 15
Source Project: Cyberware   File: ItemSkinUpgrade.java    License: 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());
	}
}