@SubscribeEvent public void HandleEnchant(LivingAttackEvent fEvent) { if (fEvent.source.damageType != "player" && fEvent.source.damageType != "mob") return; if (!(fEvent.source.getSourceOfDamage() instanceof EntityLivingBase)) return; EntityLivingBase attacker = (EntityLivingBase) fEvent.source.getSourceOfDamage(); if (attacker == null) return; ItemStack dmgSource = ((EntityLivingBase) fEvent.source.getSourceOfDamage()).getHeldItem(); if (dmgSource == null) return; if (EnchantmentHelper.getEnchantmentLevel(effectId, dmgSource) <= 0) return; // We have a cleaving level, let's figure out our damage value. float splashDamage = fEvent.ammount * (EnchantmentHelper.getEnchantmentLevel(effectId, dmgSource) * 0.25F); // Next, find our entities to hit. AxisAlignedBB boundBox = AxisAlignedBB.getBoundingBox( attacker.posX - 5, attacker.posY - 5, attacker.posZ - 5, attacker.posX + 5, attacker.posY + 5, attacker.posZ + 5); @SuppressWarnings("unchecked") ArrayList<Entity> targetEntities = new ArrayList<Entity>( attacker.worldObj.getEntitiesWithinAABBExcludingEntity(fEvent.entity, boundBox)); // Let's remove all the entries that aren't within range of our attacker ListIterator<Entity> itr = targetEntities.listIterator(); while (itr.hasNext()) { Entity target = itr.next(); if (!(target instanceof EntityLivingBase)) continue; if (target == attacker) continue; if (target.getDistanceToEntity(attacker) > 3.5F) continue; Vec3 attackerCheck = Vec3.createVectorHelper( target.posX - attacker.posX, target.posY - attacker.posY, target.posZ - attacker.posZ); double angle = Math.toDegrees(Math.acos(attackerCheck.normalize().dotProduct(attacker.getLookVec()))); if (angle < 60.0D) { // This is within our arc, let's deal our damage. DamageSource source = null; if (attacker instanceof EntityPlayer) source = new EntityDamageSource("player", attacker); if (attacker instanceof EntityMob) source = new EntityDamageSource("mob", attacker); if (source != null) { target.attackEntityFrom(DamageSource.generic, splashDamage); } if (attacker instanceof EntityPlayer) { // Apply knockback int modKnockback = 1; modKnockback += EnchantmentHelper.getKnockbackModifier(attacker, (EntityLivingBase) target); if (attacker.isSprinting()) modKnockback++; if (modKnockback > 0) target.addVelocity( (double) (-MathHelper.sin(attacker.rotationYaw * (float) Math.PI / 180.0F) * (float) modKnockback * 0.5F), 0.1D, (double) (MathHelper.cos(attacker.rotationYaw * (float) Math.PI / 180.0F) * (float) modKnockback * 0.5F)); } } } // Stop the player sprinting attacker.setSprinting(false); }