Example usage for net.minecraftforge.event.entity.player AttackEntityEvent AttackEntityEvent

List of usage examples for net.minecraftforge.event.entity.player AttackEntityEvent AttackEntityEvent

Introduction

In this page you can find the example usage for net.minecraftforge.event.entity.player AttackEntityEvent AttackEntityEvent.

Prototype

public AttackEntityEvent(PlayerEntity player, Entity target) 

Source Link

Usage

From source file:buildcraft.robotics.EntityRobot.java

License:Minecraft Mod Public

public void attackTargetEntityWithCurrentItem(Entity par1Entity) {
    if (MinecraftForge.EVENT_BUS.post(new AttackEntityEvent(CoreProxy.proxy
            .getBuildCraftPlayer((WorldServer) worldObj, (int) posX, (int) posY, (int) posZ).get(),
            par1Entity))) {/* w ww . j  av  a 2s. c  om*/
        return;
    }
    if (par1Entity.canAttackWithItem()) {
        if (!par1Entity.hitByEntity(this)) {
            float attackDamage = 2.0F;
            int knockback = 0;

            if (par1Entity instanceof EntityLivingBase) {
                attackDamage += EnchantmentHelper.getEnchantmentModifierLiving(this,
                        (EntityLivingBase) par1Entity);
                knockback += EnchantmentHelper.getKnockbackModifier(this, (EntityLivingBase) par1Entity);
            }

            if (attackDamage > 0.0F) {
                int fireAspect = EnchantmentHelper.getFireAspectModifier(this);

                if (par1Entity instanceof EntityLivingBase && fireAspect > 0 && !par1Entity.isBurning()) {
                    par1Entity.setFire(fireAspect * 4);
                }

                if (par1Entity.attackEntityFrom(new EntityDamageSource("robot", this), attackDamage)) {
                    this.setLastAttacker(par1Entity);

                    if (knockback > 0) {
                        par1Entity.addVelocity(
                                (double) (-MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F)
                                        * (float) knockback * 0.5F),
                                0.1D, (double) (MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F)
                                        * (float) knockback * 0.5F));
                        this.motionX *= 0.6D;
                        this.motionZ *= 0.6D;
                        this.setSprinting(false);
                    }

                    if (par1Entity instanceof EntityLivingBase) {
                        EnchantmentHelper.func_151384_a((EntityLivingBase) par1Entity, this);
                    }

                    EnchantmentHelper.func_151385_b(this, par1Entity);

                    ItemStack itemstack = itemInUse;

                    if (itemstack != null && par1Entity instanceof EntityLivingBase) {
                        itemstack.getItem().hitEntity(itemstack, (EntityLivingBase) par1Entity, this);
                    }
                }
            }
        }
    }
}