Example usage for net.minecraftforge.event.entity.living LivingAttackEvent getAmount

List of usage examples for net.minecraftforge.event.entity.living LivingAttackEvent getAmount

Introduction

In this page you can find the example usage for net.minecraftforge.event.entity.living LivingAttackEvent getAmount.

Prototype

public float getAmount() 

Source Link

Usage

From source file:com.crowsofwar.avatar.common.bending.air.AirbendingEvents.java

License:Open Source License

@SubscribeEvent
public void airBubbleShield(LivingAttackEvent e) {
    World world = e.getEntity().worldObj;
    if (!world.isRemote && e.getEntity() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) e.getEntity();
        AvatarPlayerData data = AvatarPlayerData.fetcher().fetch(player);
        if (data.hasStatusControl(StatusControl.BUBBLE_CONTRACT)) {

            List<EntityAirBubble> entities = player.worldObj.getEntitiesWithinAABB(EntityAirBubble.class,
                    player.getEntityBoundingBox(), bubble -> bubble.getOwner() == player);
            for (EntityAirBubble bubble : entities) {

                DamageSource source = e.getSource();
                Entity entity = source.getEntity();
                if (entity != null && (entity instanceof AvatarEntity || entity instanceof EntityArrow)) {
                    entity.setDead();// www.  jav a2 s .c  o m
                    data.getAbilityData(ABILITY_AIR_BUBBLE).addXp(SKILLS_CONFIG.airbubbleProtect);
                    bubble.setHealth(bubble.getHealth() - e.getAmount());
                    e.setCanceled(true);
                }

            }

        }
    }
}

From source file:jayavery.geomastery.main.PlayerEvents.java

License:Open Source License

/** Alters behaviour when the player takes damage. */
@SubscribeEvent//from   www . j a  v  a2  s .  c  o m
public void playerAttacked(LivingAttackEvent event) {

    if (!(event.getEntity() instanceof EntityPlayer)) {

        return;
    }

    EntityPlayer player = (EntityPlayer) event.getEntity();
    DamageSource source = event.getSource();

    // Copy vanilla shield functionality to allow for custom shields
    if (!source.isUnblockable() && player.isActiveItemStackBlocking()
            && player.getActiveItemStack().getItem() instanceof ItemShield) {

        Vec3d sourceVec = source.getDamageLocation();

        if (sourceVec != null) {

            Vec3d playerVec = player.getLook(1.0F);
            Vec3d attackVec = sourceVec.subtractReverse(new Vec3d(player.posX, player.posY, player.posZ))
                    .normalize();
            attackVec = new Vec3d(attackVec.xCoord, 0.0D, attackVec.zCoord);

            if (attackVec.dotProduct(playerVec) < 0.0D && event.getAmount() >= 3) {

                player.getActiveItemStack().damageItem(1 + MathHelper.floor(event.getAmount()), player);
            }
        }
    }
}