Search in sources :

Example 31 with AttributeModifier

use of net.minecraft.entity.ai.attributes.AttributeModifier in project Bewitchment by Um-Mitternacht.

the class BrewAttributeModifier method applyAttributeModifiers.

public void applyAttributeModifiers(AbstractAttributeMap attributeMap, int amplifier) {
    for (Map.Entry<IAttribute, AttributeModifier> entry : modifierMap.entrySet()) {
        IAttributeInstance attribute = attributeMap.getAttributeInstance(entry.getKey());
        if (attribute == null)
            continue;
        AttributeModifier modifier = entry.getValue();
        attribute.removeModifier(modifier);
        attribute.applyModifier(new AttributeModifier(modifier.getID(), this.getName() + " " + amplifier, modifier.getAmount() * (amplifier + 1), modifier.getOperation()));
    }
}
Also used : IAttribute(net.minecraft.entity.ai.attributes.IAttribute) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) AbstractAttributeMap(net.minecraft.entity.ai.attributes.AbstractAttributeMap) Map(java.util.Map)

Example 32 with AttributeModifier

use of net.minecraft.entity.ai.attributes.AttributeModifier in project ClaySoldiersMod by SanAndreasP.

the class UpgradeShearBlade method onAdded.

@Override
public void onAdded(ISoldier<?> soldier, ItemStack stack, ISoldierUpgradeInst upgradeInst) {
    if (!soldier.getEntity().world.isRemote) {
        upgradeInst.getNbtData().setByte("uses", MAX_USAGES);
        AttributeModifier modifier = upgradeInst.getUpgradeType() == EnumUpgradeType.MAIN_HAND ? BLADE_DMG_1 : BLADE_DMG_2;
        soldier.getEntity().getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).applyModifier(modifier);
        soldier.getEntity().playSound(SoundEvents.ENTITY_ITEM_PICKUP, 0.2F, ((MiscUtils.RNG.randomFloat() - MiscUtils.RNG.randomFloat()) * 0.7F + 1.0F) * 2.0F);
        stack.shrink(1);
    }
}
Also used : AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier)

Example 33 with AttributeModifier

use of net.minecraft.entity.ai.attributes.AttributeModifier in project ClaySoldiersMod by SanAndreasP.

the class UpgradeShearBlade method resetFirstHit.

private void resetFirstHit(ISoldier<?> soldier, ISoldierUpgradeInst upgInstance) {
    upgInstance.getNbtData().setBoolean("firstHit", false);
    AttributeModifier modifier = upgInstance.getUpgradeType() == EnumUpgradeType.MAIN_HAND ? BLADE_FH_DMG_1 : BLADE_FH_DMG_2;
    soldier.getEntity().getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).removeModifier(modifier);
}
Also used : AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier)

Example 34 with AttributeModifier

use of net.minecraft.entity.ai.attributes.AttributeModifier in project ClaySoldiersMod by SanAndreasP.

the class UpgradeShearBlade method onTick.

@Override
public void onTick(ISoldier<?> soldier, ISoldierUpgradeInst upgradeInst) {
    EntityLivingBase attackTgt = soldier.getEntity().getAttackTarget();
    if (!upgradeInst.getNbtData().getBoolean("firstHit")) {
        if (attackTgt == null) {
            upgradeInst.getNbtData().setBoolean("firstHit", true);
            AttributeModifier modifier = upgradeInst.getUpgradeType() == EnumUpgradeType.MAIN_HAND ? BLADE_FH_DMG_1 : BLADE_FH_DMG_2;
            soldier.getEntity().getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).applyModifier(modifier);
        }
    } else {
        if (attackTgt instanceof EntityLiving && ((EntityLiving) attackTgt).getAttackTarget() == soldier) {
            this.resetFirstHit(soldier, upgradeInst);
        }
    }
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving) EntityLivingBase(net.minecraft.entity.EntityLivingBase) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier)

Example 35 with AttributeModifier

use of net.minecraft.entity.ai.attributes.AttributeModifier in project takumicraft by TNTModders.

the class EntityZombieCreeper method onInitialSpawn.

/**
 * Called only once on an entity when first time spawned, via egg, mob spawner, natural spawning etc, but not called
 * when entity is reloaded from nbt. Mainly used for initializing attributes and inventory
 */
@Override
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
    livingdata = super.onInitialSpawn(difficulty, livingdata);
    float f = difficulty.getClampedAdditionalDifficulty();
    this.setCanPickUpLoot(this.rand.nextFloat() < 0.55F * f);
    if (livingdata == null) {
        livingdata = new GroupData(this.world.rand.nextFloat() < ForgeModContainer.zombieBabyChance);
    }
    if (livingdata instanceof GroupData && !(this instanceof EntityGiantCreeper)) {
        GroupData entityzombie$groupdata = (GroupData) livingdata;
        if (entityzombie$groupdata.isChild) {
            this.setChild(true);
            if (this.world.rand.nextFloat() < 0.05D) {
                List<EntityChicken> list = this.world.getEntitiesWithinAABB(EntityChicken.class, this.getEntityBoundingBox().grow(5.0D, 3.0D, 5.0D), EntitySelectors.IS_STANDALONE);
                if (!list.isEmpty()) {
                    EntityChicken entitychicken = list.get(0);
                    entitychicken.setChickenJockey(true);
                    this.startRiding(entitychicken);
                }
            } else if (this.world.rand.nextFloat() < 0.05D) {
                EntityChicken entitychicken1 = new EntityChicken(this.world);
                entitychicken1.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
                entitychicken1.onInitialSpawn(difficulty, null);
                entitychicken1.setChickenJockey(true);
                this.world.spawnEntity(entitychicken1);
                this.startRiding(entitychicken1);
            }
        }
    }
    this.setBreakDoorsAItask(this.rand.nextBoolean());
    this.setEquipmentBasedOnDifficulty(difficulty);
    this.setEnchantmentBasedOnDifficulty(difficulty);
    if (this.getItemStackFromSlot(EntityEquipmentSlot.HEAD).isEmpty() && this.getClass() != EntityZombieVillagerCreeper.class) {
        Calendar calendar = this.world.getCurrentDate();
        if (calendar.get(Calendar.MONTH) + 1 == 10 && calendar.get(Calendar.DATE) == 31) {
            this.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(this.rand.nextFloat() < 0.1F ? Blocks.LIT_PUMPKIN : Blocks.PUMPKIN));
            this.inventoryArmorDropChances[EntityEquipmentSlot.HEAD.getIndex()] = 0.0F;
        }
    }
    this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).applyModifier(new AttributeModifier("Random spawn bonus", this.rand.nextDouble() * 0.05000000074505806D, 0));
    double d0 = this.rand.nextDouble() * 1.5D * f;
    if (d0 > 1.0D) {
        this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).applyModifier(new AttributeModifier("Random zombie-spawn bonus", d0, 2));
    }
    if (this.rand.nextFloat() < f * 0.05F) {
        this.getEntityAttribute(SPAWN_REINFORCEMENTS_CHANCE).applyModifier(new AttributeModifier("Leader zombie bonus", this.rand.nextDouble() * 0.25D + 0.5D, 0));
        this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).applyModifier(new AttributeModifier("Leader zombie bonus", this.rand.nextDouble() * 3.0D + 1.0D, 2));
        this.setBreakDoorsAItask(true);
    }
    return livingdata;
}
Also used : EntityChicken(net.minecraft.entity.passive.EntityChicken) Calendar(java.util.Calendar) ItemStack(net.minecraft.item.ItemStack) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) Nullable(javax.annotation.Nullable)

Aggregations

AttributeModifier (net.minecraft.entity.ai.attributes.AttributeModifier)116 Nonnull (javax.annotation.Nonnull)19 Multimap (com.google.common.collect.Multimap)14 IAttributeInstance (net.minecraft.entity.ai.attributes.IAttributeInstance)11 UUID (java.util.UUID)9 ItemStack (net.minecraft.item.ItemStack)9 IAttribute (net.minecraft.entity.ai.attributes.IAttribute)8 HashMultimap (com.google.common.collect.HashMultimap)6 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)5 Map (java.util.Map)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 EntityEquipmentSlot (net.minecraft.inventory.EntityEquipmentSlot)4 Potion (net.minecraft.potion.Potion)4 PotionEffect (net.minecraft.potion.PotionEffect)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 Calendar (java.util.Calendar)3 EnergyUpgrade (crazypants.enderio.base.item.darksteel.upgrade.energy.EnergyUpgrade)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2