use of net.minecraft.entity.ai.attributes.IAttributeInstance in project ArsMagica2 by Mithion.
the class BuffStatModifiers method clearAllModifiers.
private void clearAllModifiers(EntityLivingBase entity, KeyValuePair<IAttribute, AttributeModifier>... modifiers) {
for (KeyValuePair<IAttribute, AttributeModifier> entry : modifiers) {
IAttributeInstance inst = entity.getEntityAttribute(entry.getKey());
if (inst == null)
continue;
AttributeModifier currentModifier = inst.getModifier(entry.getValue().getID());
if (currentModifier == entry.getValue()) {
inst.removeModifier(currentModifier);
}
}
}
use of net.minecraft.entity.ai.attributes.IAttributeInstance in project ArsMagica2 by Mithion.
the class BuffStatModifiers method applyOrRemoveScalingModifiersForBuff.
private void applyOrRemoveScalingModifiersForBuff(EntityLivingBase entity, int potionID, IAttribute attribute, AttributeModifier... modifiers) {
IAttributeInstance inst = entity.getEntityAttribute(attribute);
if (inst == null) {
return;
}
AttributeModifier currentModifier = inst.getModifier(modifiers[0].getID());
if (entity.isPotionActive(potionID)) {
int magnitude = entity.getActivePotionEffect(Potion.potionTypes[potionID]).getAmplifier();
AttributeModifier modifier = modifiers[Math.min(magnitude, modifiers.length - 1)];
if (currentModifier != modifier) {
if (currentModifier != null) {
inst.removeModifier(currentModifier);
}
inst.applyModifier(modifier);
}
} else {
if (currentModifier != null) {
inst.removeModifier(currentModifier);
}
}
}
use of net.minecraft.entity.ai.attributes.IAttributeInstance in project ArsMagica2 by Mithion.
the class AffinityModifiers method applyHealthModifiers.
public void applyHealthModifiers(EntityPlayer ent, float enderDepth, float waterDepth, float fireDepth, float lightningDepth) {
IAttributeInstance attribute = ent.getEntityAttribute(SharedMonsterAttributes.maxHealth);
applyOrRemoveModifier(attribute, waterWeakness, ((fireDepth >= 0.5f && fireDepth <= 0.9f) || (enderDepth >= 0.5f && enderDepth <= 0.9f) || (lightningDepth >= 0.5f && lightningDepth <= 0.9f)) && ent.isWet());
applyOrRemoveModifier(attribute, fireWeakness, (waterDepth >= 0.5f && waterDepth <= 0.9f) && (ent.isBurning() || ent.worldObj.provider.dimensionId == -1));
int worldTime = (int) ent.worldObj.getWorldTime() % 24000;
applyOrRemoveModifier(attribute, sunlightWeakness, (enderDepth > 0.65 && enderDepth <= 0.95f) && ent.worldObj.canBlockSeeTheSky((int) ent.posX, (int) ent.posY, (int) ent.posZ) && (worldTime > 23000 || worldTime < 12500));
}
use of net.minecraft.entity.ai.attributes.IAttributeInstance in project ArsMagica2 by Mithion.
the class AffinityModifiers method applySpeedModifiersBasedOnDepth.
public void applySpeedModifiersBasedOnDepth(EntityPlayer ent, float natureDepth, float iceDepth, float lightningDepth) {
IAttributeInstance attribute = ent.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
applyOrRemoveModifier(attribute, natureAffinityRoots, natureDepth >= 0.5f);
applyOrRemoveModifier(attribute, lightningAffinitySpeed, lightningDepth >= 0.65f);
applyOrRemoveModifier(attribute, iceAffinityColdBlooded, iceDepth >= 0.1f && !isOnIce(ent));
}
use of net.minecraft.entity.ai.attributes.IAttributeInstance in project RFToolsDimensions by McJty.
the class ForgeEventHandlers method onEntitySpawnEvent.
@SubscribeEvent
public void onEntitySpawnEvent(LivingSpawnEvent.CheckSpawn event) {
World world = event.getWorld();
int id = world.provider.getDimension();
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
DimensionInformation dimensionInformation = dimensionManager.getDimensionInformation(id);
if (PowerConfiguration.preventSpawnUnpowered) {
if (dimensionInformation != null) {
// RFTools dimension.
DimensionStorage storage = DimensionStorage.getDimensionStorage(world);
int energy = storage.getEnergyLevel(id);
if (energy <= 0) {
event.setResult(Event.Result.DENY);
Logging.logDebug("Dimension power low: Prevented a spawn of " + event.getEntity().getClass().getName());
}
}
}
if (dimensionInformation != null) {
if (dimensionInformation.hasEffectType(EffectType.EFFECT_STRONGMOBS) || dimensionInformation.hasEffectType(EffectType.EFFECT_BRUTALMOBS)) {
if (event.getEntity() instanceof EntityLivingBase) {
EntityLivingBase entityLivingBase = (EntityLivingBase) event.getEntity();
IAttributeInstance entityAttribute = entityLivingBase.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH);
double newMax;
if (dimensionInformation.hasEffectType(EffectType.EFFECT_BRUTALMOBS)) {
newMax = entityAttribute.getBaseValue() * GeneralConfiguration.brutalMobsFactor;
} else {
newMax = entityAttribute.getBaseValue() * GeneralConfiguration.strongMobsFactor;
}
entityAttribute.setBaseValue(newMax);
entityLivingBase.setHealth((float) newMax);
}
}
}
if (event.getEntity() instanceof IMob) {
BlockPos coordinate = new BlockPos((int) event.getEntity().posX, (int) event.getEntity().posY, (int) event.getEntity().posZ);
/* if (PeacefulAreaManager.isPeaceful(new GlobalCoordinate(coordinate, id))) {
event.setResult(Event.Result.DENY);
Logging.logDebug("Peaceful manager: Prevented a spawn of " + event.entity.getClass().getName());
} else */
if (dimensionInformation != null && dimensionInformation.isPeaceful()) {
// RFTools dimension.
event.setResult(Event.Result.DENY);
Logging.logDebug("Peaceful dimension: Prevented a spawn of " + event.getEntity().getClass().getName());
}
} else if (event.getEntity() instanceof IAnimals) {
if (dimensionInformation != null && dimensionInformation.isNoanimals()) {
// RFTools dimension.
event.setResult(Event.Result.DENY);
Logging.logDebug("Noanimals dimension: Prevented a spawn of " + event.getEntity().getClass().getName());
}
}
// @todo
}
Aggregations