Search in sources :

Example 1 with AttackEntityEvent

use of net.minecraftforge.event.entity.player.AttackEntityEvent in project BuildCraft by BuildCraft.

the class EntityRobot method attackTargetEntityWithCurrentItem.

public void attackTargetEntityWithCurrentItem(Entity par1Entity) {
    BlockPos entPos = Utils.convertFloor(Utils.getVec(par1Entity));
    if (MinecraftForge.EVENT_BUS.post(new AttackEntityEvent(CoreProxy.proxy.getBuildCraftPlayer((WorldServer) worldObj, entPos).get(), par1Entity))) {
        return;
    }
    if (par1Entity.canAttackWithItem()) {
        if (!par1Entity.hitByEntity(this)) {
            Multimap<String, AttributeModifier> attributes = itemInUse != null ? (Multimap<String, AttributeModifier>) itemInUse.getAttributeModifiers() : null;
            float attackDamage = 2.0F;
            int knockback = 0;
            if (attributes != null) {
                for (AttributeModifier modifier : attributes.get(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName())) {
                    switch(modifier.getOperation()) {
                        case 0:
                            attackDamage += modifier.getAmount();
                            break;
                        case 1:
                            attackDamage *= modifier.getAmount();
                            break;
                        case 2:
                            attackDamage *= 1.0F + modifier.getAmount();
                            break;
                    }
                }
            }
            if (par1Entity instanceof EntityLivingBase) {
                // FIXME: This was probably meant to do something at some point
                // attackDamage += EnchantmentHelper.getEnchantmentModifierDamage(this, (EntityLivingBase)
                // par1Entity);
                knockback += EnchantmentHelper.getKnockbackModifier(this);
            }
            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(-MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F) * knockback * 0.5F, 0.1D, MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F) * knockback * 0.5F);
                        this.motionX *= 0.6D;
                        this.motionZ *= 0.6D;
                        this.setSprinting(false);
                    }
                    // FIXME: This was probably meant to do something at some point...
                    // if (par1Entity instanceof EntityLivingBase) {
                    // EnchantmentHelper.((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);
                    }
                    if (itemInUse.stackSize == 0) {
                        setItemInUse(null);
                    }
                }
            }
        }
    }
}
Also used : AttackEntityEvent(net.minecraftforge.event.entity.player.AttackEntityEvent) EntityLivingBase(net.minecraft.entity.EntityLivingBase) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) ItemStack(net.minecraft.item.ItemStack) EntityDamageSource(net.minecraft.util.EntityDamageSource)

Example 2 with AttackEntityEvent

use of net.minecraftforge.event.entity.player.AttackEntityEvent in project SpongeForge by SpongePowered.

the class SpongeForgeEventFactory method createAttackEntityEvent.

public static AttackEntityEvent createAttackEntityEvent(Event event) {
    InteractEntityEvent.Primary spongeEvent = (InteractEntityEvent.Primary) event;
    Optional<Player> player = spongeEvent.getCause().first(Player.class);
    if (!player.isPresent()) {
        return null;
    }
    AttackEntityEvent forgeEvent = new AttackEntityEvent((EntityPlayer) player.get(), (Entity) spongeEvent.getTargetEntity());
    return forgeEvent;
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) EntityPlayer(net.minecraft.entity.player.EntityPlayer) AttackEntityEvent(net.minecraftforge.event.entity.player.AttackEntityEvent) InteractEntityEvent(org.spongepowered.api.event.entity.InteractEntityEvent)

Aggregations

AttackEntityEvent (net.minecraftforge.event.entity.player.AttackEntityEvent)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 AttributeModifier (net.minecraft.entity.ai.attributes.AttributeModifier)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 EntityDamageSource (net.minecraft.util.EntityDamageSource)1 BlockPos (net.minecraft.util.math.BlockPos)1 WorldServer (net.minecraft.world.WorldServer)1 Player (org.spongepowered.api.entity.living.player.Player)1 InteractEntityEvent (org.spongepowered.api.event.entity.InteractEntityEvent)1