Java Code Examples for net.minecraft.entity.ai.attributes.IAttributeInstance#removeModifier()

The following examples show how to use net.minecraft.entity.ai.attributes.IAttributeInstance#removeModifier() . 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: EntityMage.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
protected void handleAttackLogicUpdate() {
	PotionType potiontype = null;

	if (this.rand.nextFloat() < 0.15F && this.isInsideOfMaterial(Material.WATER) && !this.isPotionActive(MobEffects.WATER_BREATHING)) {
		potiontype = PotionTypes.WATER_BREATHING;
	} else if (this.rand.nextFloat() < 0.15F && this.isBurning() && !this.isPotionActive(MobEffects.FIRE_RESISTANCE)) {
		potiontype = PotionTypes.FIRE_RESISTANCE;
	} else if (this.rand.nextFloat() < 0.05F && this.getHealth() < this.getMaxHealth()) {
		potiontype = PotionTypes.HEALING;
	} else if (this.rand.nextFloat() < 0.5F && this.getAttackTarget() != null && !this.isPotionActive(MobEffects.SPEED)
			&& this.getAttackTarget().getDistanceSq(this) > 121.0D) {
		potiontype = PotionTypes.SWIFTNESS;
	}

	if (potiontype != null) {
		this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_WITCH_DRINK, this.getSoundCategory(), 1.0F,
				0.8F + this.rand.nextFloat() * 0.4F);
		this.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), potiontype));
		this.attackTimer = 10;
		this.setAggressive(true);
		IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED);
		iattributeinstance.removeModifier(MODIFIER);
		iattributeinstance.applyModifier(MODIFIER);
	}
}
 
Example 2
Source File: PotionBuffGolem.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void removeAttributesModifiersFromEntity(EntityLivingBase entity, BaseAttributeMap attrMap, int amplifier) {
    super.removeAttributesModifiersFromEntity(entity, attrMap, amplifier);

    if(entity instanceof EntityGolemBase) {
        EntityGolemBase golem = (EntityGolemBase) entity;

        IAttributeInstance inst = golem.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
        if(inst.getModifier(SPEED_INC_PERCENT.getID()) != null) {
            inst.removeModifier(SPEED_INC_PERCENT);
        }

        inst = golem.getEntityAttribute(SharedMonsterAttributes.maxHealth);
        if(inst.getModifier(HEALTH_INC_PERCENT.getID()) != null) {
            inst.removeModifier(HEALTH_INC_PERCENT);
        }

        inst = golem.getEntityAttribute(SharedMonsterAttributes.attackDamage);
        if(inst.getModifier(DAMAGE_INC_PERCENT.getID()) != null) {
            inst.removeModifier(DAMAGE_INC_PERCENT);
        }
    }
}
 
Example 3
Source File: EntityEndermanFighter.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void setAttackTarget(@Nullable EntityLivingBase target)
{
    super.setAttackTarget(target);

    IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED);

    if (target == null)
    {
        this.setScreaming(false);
        iattributeinstance.removeModifier(ATTACKING_SPEED_BOOST);
    }
    else
    {
        if (iattributeinstance.hasModifier(ATTACKING_SPEED_BOOST) == false)
        {
            iattributeinstance.applyModifier(ATTACKING_SPEED_BOOST);
        }

        if (target instanceof EntityPlayer && this.isScreaming() == false)
        {
            this.setScreaming(true);
        }
    }
}
 
Example 4
Source File: ArtifactTickHandler.java    From Artifacts with MIT License 6 votes vote down vote up
private void updateKnockbackResistance(int artifactKnockbackCount, EntityPlayer player) {
	NBTTagCompound playerData = player.getEntityData();
	int oldKnockbackCount = playerData.getInteger("artifactKnockbackCount");
	
	if(oldKnockbackCount != artifactKnockbackCount) {
		String uu = playerData.getString("artifactKnockbackUUID");
		UUID knockbackID;
		
		if(uu.equals("")) {
			knockbackID = UUID.randomUUID();
			playerData.setString("artifactKnockbackUUID", knockbackID.toString());
		}
		else {
			knockbackID = UUID.fromString(uu);
		}
		
		IAttributeInstance atinst = player.getEntityAttribute(SharedMonsterAttributes.knockbackResistance);
		
		atinst.removeModifier(new AttributeModifier(knockbackID, "KnockbackComponent", 0.2F * oldKnockbackCount, 0));
		atinst.applyModifier(new AttributeModifier(knockbackID, "KnockbackComponent", 0.2F * artifactKnockbackCount, 0));
		
		playerData.setInteger("artifactKnockbackCount", artifactKnockbackCount);
	}
}
 
Example 5
Source File: ArtifactTickHandler.java    From Artifacts with MIT License 6 votes vote down vote up
private void updateSpeedBoost(int artifactSpeedBoostCount, EntityPlayer player) {
	NBTTagCompound playerData = player.getEntityData();
	int oldSpeedBoostCount = playerData.getInteger("artifactSpeedBoostCount");
	
	if(oldSpeedBoostCount != artifactSpeedBoostCount) {
		String uu = playerData.getString("artifactSpeedBoostUUID");
		UUID speedID;
		
		if(uu.equals("")) {
			speedID = UUID.randomUUID();
			playerData.setString("artifactSpeedBoostUUID", speedID.toString());
		}
		else {
			speedID = UUID.fromString(uu);
		}
		
		IAttributeInstance atinst = player.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
		
		atinst.removeModifier(new AttributeModifier(speedID, "SpeedBoostComponent", 0.05F * oldSpeedBoostCount, 2));
		atinst.applyModifier(new AttributeModifier(speedID, "SpeedBoostComponent", 0.05F * artifactSpeedBoostCount, 2));
		
		playerData.setInteger("artifactSpeedBoostCount", artifactSpeedBoostCount);
	}
}
 
Example 6
Source File: EntityEnderminy.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
/**
 * Resets the task
 */
public void resetTask() {
  targetPlayer = null;
  enderminy.setScreaming(false);
  IAttributeInstance iattributeinstance = enderminy.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED);
  iattributeinstance.removeModifier(EntityEnderminy.attackingSpeedBoostModifier);
  super.resetTask();
}
 
Example 7
Source File: EntityUtil.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
public static IAttributeInstance removeModifier(EntityLivingBase ent, IAttribute p, UUID u) {
  IAttributeInstance att = ent.getEntityAttribute(p);
  AttributeModifier curmod = att.getModifier(u);
  if (curmod != null) {
    att.removeModifier(curmod);
  }
  return att;
}
 
Example 8
Source File: ArtifactTickHandler.java    From Artifacts with MIT License 5 votes vote down vote up
private void updateHealthBoost(int artifactHealthBoostCount, EntityPlayer player) {
	NBTTagCompound playerData = player.getEntityData();
	int oldHealthBoostCount = playerData.getInteger("artifactHealthBoostCount");
	
	if(oldHealthBoostCount != artifactHealthBoostCount) {
		String uu = playerData.getString("artifactHealthBoostUUID");
		UUID healthID;
		
		if(uu.equals("")) {
			healthID = UUID.randomUUID();
			playerData.setString("artifactHealthBoostUUID", healthID.toString());
		}
		else {
			healthID = UUID.fromString(uu);
		}
		
		IAttributeInstance atinst = player.getEntityAttribute(SharedMonsterAttributes.maxHealth);
		
		atinst.removeModifier(new AttributeModifier(healthID, "HealthBoostComponent", 5F * oldHealthBoostCount, 0));
		atinst.applyModifier(new AttributeModifier(healthID, "HealthBoostComponent", 5F * artifactHealthBoostCount, 0));
		
		if(player.getHealth() > player.getMaxHealth()) {
			player.setHealth(player.getMaxHealth());
		}
		int diff = (artifactHealthBoostCount - oldHealthBoostCount);
		if(diff > 0 && player.getHealth() < player.getMaxHealth()) {
			player.heal(5*diff);
		}
		
		playerData.setInteger("artifactHealthBoostCount", artifactHealthBoostCount);
	}
}