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

The following examples show how to use net.minecraft.entity.ai.attributes.IAttributeInstance#applyModifier() . 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 applyAttributesModifiersToEntity(EntityLivingBase entity, BaseAttributeMap attrMap, int amplifier) {
    super.applyAttributesModifiersToEntity(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.applyModifier(SPEED_INC_PERCENT);
        }

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

        inst = golem.getEntityAttribute(SharedMonsterAttributes.attackDamage);
        if(inst.getModifier(DAMAGE_INC_PERCENT.getID()) != null) {
            inst.applyModifier(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: EntityEnderminy.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
/**
 * Updates the task
 */
public void updateTask() {
  if(targetPlayer != null) {
    if(--stareTimer <= 0) {
      targetEntity = targetPlayer;
      targetPlayer = null;
      super.startExecuting();
      enderminy.playSound(SoundEvents.ENTITY_ENDERMEN_STARE, 1.0F, 1.0F);
      enderminy.setScreaming(true);
      IAttributeInstance iattributeinstance = enderminy.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED);
      iattributeinstance.applyModifier(EntityEnderminy.attackingSpeedBoostModifier);
    }
  } else {
    if(targetEntity != null) {
      if(targetEntity instanceof EntityPlayer && enderminy.shouldAttackPlayer((EntityPlayer) this.targetEntity)) {
        if(targetEntity.getDistanceSqToEntity(enderminy) < 16.0D) {
          enderminy.teleportRandomly();
        }
        teleportDelay = 0;
      } else if(targetEntity.getDistanceSqToEntity(enderminy) > 256.0D && this.teleportDelay++ >= 30 && enderminy.teleportToEntity(targetEntity)) {
        teleportDelay = 0;
      }
    }
    super.updateTask();
  }
}
 
Example 5
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 6
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 7
Source File: EntityWitherCat.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
protected void updateAttackDamage(float growthRatio) {
  IAttributeInstance att = EntityUtil.removeModifier(this, SharedMonsterAttributes.ATTACK_DAMAGE, ATTACK_BOOST_MOD_UID);
  if (growthRatio == 0) {
    return;
  }
  double damageInc = EntityUtil.isHardDifficulty(world) ? Config.witherCatAngryAttackDamageHardModifier : 0;
  double attackDif = (damageInc + Config.witherCatAngryAttackDamage) - Config.witherCatAttackDamage;
  double toAdd = attackDif * growthRatio;
  AttributeModifier mod = new AttributeModifier(ATTACK_BOOST_MOD_UID, "Transformed Attack Modifier", toAdd, 0);
  att.applyModifier(mod);
}
 
Example 8
Source File: EntityWitherCat.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
protected void updateHealth(float growthRatio) {
  IAttributeInstance att = EntityUtil.removeModifier(this, SharedMonsterAttributes.MAX_HEALTH, HEALTH_BOOST_MOD_UID);
  if (growthRatio == 0) {
    return;
  }
  double currentRatio = getHealth() / getMaxHealth();
  double healthDif = Config.witherCatAngryHealth - Config.witherCatHealth;
  double toAdd = healthDif * growthRatio;
  AttributeModifier mod = new AttributeModifier(HEALTH_BOOST_MOD_UID, "Transformed Attack Modifier", toAdd, 0);
  att.applyModifier(mod);

  double newHealth = currentRatio * getMaxHealth();
  setHealth((float) newHealth);

}
 
Example 9
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);
	}
}