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);
}
}
}
}
}
}
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;
}
Aggregations