Search in sources :

Example 11 with Location

use of icbm.classic.lib.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.

the class Blast method doDamageEntities.

/**
 * @return true if the method ran successfully, false if it was interrupted
 */
protected boolean doDamageEntities(float radius, float power, boolean destroyItem) {
    // Step 2: Damage all entities
    radius *= 2.0F;
    Location minCoord = location.add(-radius - 1);
    Location maxCoord = location.add(radius + 1);
    List<Entity> allEntities = world().getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(minCoord.xi(), minCoord.yi(), minCoord.zi(), maxCoord.xi(), maxCoord.yi(), maxCoord.zi()));
    Vec3d var31 = new Vec3d(location.x(), location.y(), location.z());
    if (!ConfigBlast.ANTIMATTER_BLOCK_AND_ENT_DAMAGE_ON_REDMATTER && this instanceof BlastAntimatter) {
        allEntities.sort((e1, e2) -> {
            if (e2 instanceof EntityExplosion && ((EntityExplosion) e2).getBlast() instanceof BlastRedmatter) {
                // put red matter at the front
                return 1;
            } else {
                return -1;
            }
        });
        if (// remove red matter blast and stop doing anything else
        onDamageEntity(allEntities.get(0))) {
            return false;
        }
    }
    for (int i = 0; i < allEntities.size(); ++i) {
        Entity entity = allEntities.get(i);
        if (this.onDamageEntity(entity)) {
            continue;
        }
        if (entity instanceof IMissile) {
            ((IMissile) entity).destroyMissile(true);
            continue;
        }
        if (entity instanceof EntityItem && !destroyItem) {
            continue;
        }
        double distance = entity.getDistance(location.x(), location.y(), location.z()) / radius;
        if (distance <= 1.0D) {
            double xDifference = entity.posX - location.x();
            double yDifference = entity.posY - location.y();
            double zDifference = entity.posZ - location.z();
            double var35 = MathHelper.sqrt(xDifference * xDifference + yDifference * yDifference + zDifference * zDifference);
            xDifference /= var35;
            yDifference /= var35;
            zDifference /= var35;
            double var34 = world().getBlockDensity(var31, entity.getEntityBoundingBox());
            double var36 = (1.0D - distance) * var34;
            int damage = 0;
            damage = (int) ((var36 * var36 + var36) / 2.0D * 8.0D * power + 1.0D);
            entity.attackEntityFrom(DamageSource.causeExplosionDamage(this), damage);
            entity.motionX += xDifference * var36;
            entity.motionY += yDifference * var36;
            entity.motionZ += zDifference * var36;
        }
    }
    return true;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) IMissile(icbm.classic.api.caps.IMissile) EntityExplosion(icbm.classic.content.entity.EntityExplosion) BlastAntimatter(icbm.classic.content.blast.threaded.BlastAntimatter) Vec3d(net.minecraft.util.math.Vec3d) EntityItem(net.minecraft.entity.item.EntityItem) Location(icbm.classic.lib.transform.vector.Location)

Aggregations

Location (icbm.classic.lib.transform.vector.Location)11 ItemStack (net.minecraft.item.ItemStack)4 Pos (icbm.classic.lib.transform.vector.Pos)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 BlockPos (net.minecraft.util.math.BlockPos)3 IExplosive (icbm.classic.api.caps.IExplosive)2 IWorldPosition (icbm.classic.api.data.IWorldPosition)2 IWorldPosItem (icbm.classic.api.items.IWorldPosItem)2 Entity (net.minecraft.entity.Entity)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 IMissile (icbm.classic.api.caps.IMissile)1 IMissileLauncher (icbm.classic.api.caps.IMissileLauncher)1 RadarGunTraceEvent (icbm.classic.api.events.RadarGunTraceEvent)1 IMultiTile (icbm.classic.api.tile.multiblock.IMultiTile)1 IMultiTileHost (icbm.classic.api.tile.multiblock.IMultiTileHost)1 BlastAntimatter (icbm.classic.content.blast.threaded.BlastAntimatter)1 EntityExplosion (icbm.classic.content.entity.EntityExplosion)1 IPacketIDReceiver (icbm.classic.lib.network.IPacketIDReceiver)1