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

The following examples show how to use net.minecraft.entity.EntityLivingBase#getActivePotionEffect() . 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
Source Project: Cyberware   File: VanillaWares.java    License: 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 2
Source Project: Cyberware   File: ItemCybereyeUpgrade.java    License: 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
public void affectEntity(EntityLivingBase entity) {
	this.reapplicationDelayMap.put(entity, reapplicationDelay);
	PotionEffect effect = entity.getActivePotionEffect(ModPotions.ZACH_CORRUPTION);
	if (effect == null)
		entity.addPotionEffect(new PotionEffect(ModPotions.ZACH_CORRUPTION, 100, 0, true, false));
	else
		entity.addPotionEffect(new PotionEffect(ModPotions.ZACH_CORRUPTION, 100, effect.getAmplifier() + 1, true, false));
}
 
Example 4
@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 5
@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 6
@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 7
@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 8
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 9
Source Project: GokiStats   File: DataHelper.java    License: 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 10
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 11
@Override
public void onUpdate() {
    super.onUpdate();
    if(redstoneSignal > 0)
        return;
    final int range = 6;
    final int cost = 40;
    List<EntityLivingBase> entities = supertile.getWorldObj().getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(supertile.xCoord - range, supertile.yCoord - range, supertile.zCoord - range, supertile.xCoord + range, supertile.yCoord + range, supertile.zCoord + range));
    for(EntityLivingBase entity : entities) {
        if(!(entity instanceof EntityPlayer) && entity.getActivePotionEffect(Potion.weakness) == null && mana >= cost && !entity.worldObj.isRemote) {
            entity.addPotionEffect(new PotionEffect(Potion.weakness.id, 60, 2));
            mana -= cost;
        }
    }
}