Java Code Examples for net.minecraft.entity.player.EntityPlayer.getActivePotionEffect()

The following are Jave code examples for showing how to use getActivePotionEffect() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Bewitchment   File: ItemRemedyTalisman.java   View Source Code Vote up 6 votes
@Override
public void onWornTick(ItemStack itemstack, EntityLivingBase player) {
	if (player.ticksExisted % 40 == 0 && player instanceof EntityPlayer) {
		EntityPlayer p = (EntityPlayer) player;
		boolean flag = p.getActivePotionEffect(MobEffects.POISON) != null || p.getActivePotionEffect(MobEffects.NAUSEA) != null || p.getActivePotionEffect(MobEffects.WITHER) != null || p.getActivePotionEffect(MobEffects.BLINDNESS) != null || p.getActivePotionEffect(MobEffects.WEAKNESS) != null;
		p.removePotionEffect(MobEffects.NAUSEA);
		p.removePotionEffect(MobEffects.WITHER);
		p.removePotionEffect(MobEffects.BLINDNESS);
		p.removePotionEffect(MobEffects.POISON);
		p.removePotionEffect(MobEffects.WEAKNESS);
		if (flag) {
			itemstack.setItemDamage(itemstack.getItemDamage() + 1);
			if (itemstack.getItemDamage() >= itemstack.getMaxDamage()) {
				itemstack.setCount(0);
			}
		}
	}
}
 
Example 2
Project: chesttransporter   File: ItemChestTransporter.java   View Source Code Vote up 5 votes
private void addEffect(EntityPlayer player, Potion potion, int amplifier)
{
    PotionEffect effect = player.getActivePotionEffect(potion);
    if (effect == null || effect.getDuration() < 20)
    {
        player.addPotionEffect(new PotionEffect(potion, 20 * 3, amplifier));
    }
}
 
Example 3
Project: uniquecrops   File: UCEventHandlerServer.java   View Source Code Vote up 5 votes
@SubscribeEvent
public void onPlayerJump(LivingJumpEvent event) {
	
	if (!(event.getEntityLiving() instanceof EntityPlayer))
		return;
	
	EntityPlayer player = (EntityPlayer)event.getEntityLiving();
	if (player.getActivePotionEffect(MobEffects.SLOWNESS) != null && player.getActivePotionEffect(MobEffects.SLOWNESS).getAmplifier() >= 4)
		player.motionY = 0;
}
 
Example 4
Project: TrustCircle   File: Events.java   View Source Code Vote up 4 votes
@SubscribeEvent
public void onPlayerUpdate(LivingUpdateEvent event){
    EntityLivingBase entity = event.getEntityLiving();
    if(entity != null && !entity.worldObj.isRemote && entity instanceof EntityPlayer){
        EntityPlayer player = (EntityPlayer)entity;
        if(player.worldObj.getTotalWorldTime()%TrustCircle.updateInterval == 0){
            double modifier = 0;

            for(EntityPlayer other : player.worldObj.playerEntities){
                if(other != player && !other.isSpectator()){
                    if(doesTeamWork(player.getTeam(), other.getTeam())){
                        double dist = other.getDistanceSq(player.posX, player.posY, player.posZ);
                        if(dist <= TrustCircle.maxRange*TrustCircle.maxRange){
                            double mod = dist <= 0 ? 1 : (1/Math.sqrt(dist));
                            modifier += mod*TrustCircle.baseCalcModifier;

                            if(!TrustCircle.allowMultiplePlayers){
                                break;
                            }
                        }
                    }
                }
            }

            if(modifier > 0){
                int amplifier = Math.min(3, MathHelper.ceiling_double_int(modifier*TrustCircle.amplifierModifier)-1);
                int duration = Math.max(TrustCircle.updateInterval+1, MathHelper.ceiling_double_int(modifier*TrustCircle.durationModifier));

                PotionEffect active = player.getActivePotionEffect(TrustCircle.potionTrust);
                boolean ampChange = active != null && active.getAmplifier() != amplifier;
                if(active == null || ampChange || active.getDuration() <= TrustCircle.updateInterval){
                    if(ampChange){
                        player.removePotionEffect(TrustCircle.potionTrust);
                    }

                    player.addPotionEffect(new PotionEffect(TrustCircle.potionTrust, duration, amplifier, true, true));
                }
            }
        }
    }
}