Search in sources :

Example 41 with Pos

use of com.builtbroken.mc.imp.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.

the class TileLauncherPrefab method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound nbt) {
    super.readFromNBT(nbt);
    this._targetPos = new Pos(nbt.getCompoundTag("target"));
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos)

Example 42 with Pos

use of com.builtbroken.mc.imp.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.

the class TileLauncherBase method getController.

@Override
public ILauncherController getController() {
    for (byte i = 2; i < 6; i++) {
        Pos position = new Pos((TileEntity) this).add(ForgeDirection.getOrientation(i));
        TileEntity tileEntity = position.getTileEntity(this.worldObj);
        if (tileEntity instanceof ILauncherController) {
            return (ILauncherController) tileEntity;
        }
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILauncherController(resonant.api.explosion.ILauncherController) Pos(com.builtbroken.mc.imp.transform.vector.Pos)

Example 43 with Pos

use of com.builtbroken.mc.imp.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.

the class BlastNuclear method doExplode.

@Override
public void doExplode() {
    int r = this.callCount;
    if (this.world().isRemote) {
        if (ICBMClassic.proxy.isGaoQing()) {
            for (int x = -r; x < r; x++) {
                for (int z = -r; z < r; z++) {
                    double distance = MathHelper.sqrt_double(x * x + z * z);
                    if (distance < r && distance > r - 1) {
                        Location targetPosition = this.position.add(new Pos(x, 0, z));
                        if (this.world().rand.nextFloat() < Math.max(0.001 * r, 0.05)) {
                            ICBMClassic.proxy.spawnParticle("smoke", this.world(), targetPosition, 5F, 1F);
                        }
                    }
                }
            }
        }
    } else {
        if (this.thread != null) {
            if (this.thread.isComplete) {
                this.controller.endExplosion();
            }
        } else {
            this.controller.endExplosion();
            ICBMClassic.INSTANCE.logger().error("Something went wrong with multi-threading while detonating the nuclear explosive.");
        }
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 44 with Pos

use of com.builtbroken.mc.imp.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.

the class BlastNuclear method doPostExplode.

@Override
public void doPostExplode() {
    try {
        if (!this.world().isRemote && this.thread.isComplete) {
            for (Pos p : this.thread.results) {
                Block block = this.world().getBlock(p.xi(), p.yi(), p.zi());
                if (block != null)
                    block.onBlockExploded(this.world(), p.xi(), p.yi(), p.zi(), this);
            }
        }
    } catch (Exception e) {
        ICBMClassic.INSTANCE.logger().error("Nuclear-type detonation Failed!", e);
    }
    this.doDamageEntities(this.getRadius(), this.energy * 1000);
    if (this.isRadioactive) {
        new BlastRot(world(), this.exploder, position.x(), position.y(), position.z(), this.getRadius(), this.energy).explode();
        new BlastMutation(world(), this.exploder, position.x(), position.y(), position.z(), this.getRadius()).explode();
        if (this.world().rand.nextInt(3) == 0) {
            world().rainingStrength = 1f;
        }
    }
    this.world().playSoundEffect(this.position.x(), this.position.y(), this.position.z(), ICBMClassic.PREFIX + "explosion", 10.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) Block(net.minecraft.block.Block)

Example 45 with Pos

use of com.builtbroken.mc.imp.transform.vector.Pos in project ICBM-Classic by BuiltBrokenModding.

the class BlastRedmatter method affectEntity.

/**
     * Makes an entity get affected by Red Matter.
     *
     * @Return True if explosion happened
     */
public boolean affectEntity(float radius, Entity entity, boolean doExplosion) {
    //Ignore players that are in creative mode or can't be harmed
    if (entity instanceof EntityPlayer && (((EntityPlayer) entity).capabilities.isCreativeMode || ((EntityPlayer) entity).capabilities.disableDamage)) {
        return false;
    }
    //Ignore self
    if (entity == this.controller) {
        return false;
    }
    //Ignore entities that mark themselves are ignorable
    if (entity instanceof IExplosiveIgnore) {
        if (((IExplosiveIgnore) entity).canIgnore(this)) {
            return false;
        }
    }
    //Calculate different from center
    double xDifference = entity.posX - position.xi() + 0.5;
    double yDifference = entity.posY - position.yi() + 0.5;
    double zDifference = entity.posZ - position.zi() + 0.5;
    /** The percentage of the closeness of the entity. */
    double xPercentage = 1 - (xDifference / radius);
    double yPercentage = 1 - (yDifference / radius);
    double zPercentage = 1 - (zDifference / radius);
    double distancePercentage = this.position.distance(entity) / radius;
    Pos entityPosition = new Pos(entity);
    Pos centeredPosition = entityPosition.subtract(this.position);
    centeredPosition = (Pos) centeredPosition.transform(new EulerAngle(1.5 * distancePercentage * Math.random(), 1.5 * distancePercentage * Math.random(), 1.5 * distancePercentage * Math.random()));
    Location newPosition = this.position.add(centeredPosition);
    // Orbit Velocity
    entity.addVelocity(newPosition.x() - entityPosition.x(), 0, newPosition.z() - entityPosition.z());
    // Gravity Velocity (0.015 is barely enough to overcome y gravity so do not lower)
    entity.addVelocity(-xDifference * 0.015 * xPercentage, -yDifference * 0.015 * yPercentage, -zDifference * 0.015 * zPercentage);
    boolean explosionCreated = false;
    if (new Pos(entity.posX, entity.posY, entity.posZ).distance(position) < (ENTITY_DESTROY_RADIUS * (getRadius() / NORMAL_RADIUS))) {
        if (entity instanceof EntityExplosion) {
            if (((EntityExplosion) entity).getBlast() instanceof BlastAntimatter) {
                if (doAudio) {
                    this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "explosion", 7.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
                }
                if (this.world().rand.nextFloat() > 0.85 && !this.world().isRemote) {
                    entity.setDead();
                    return explosionCreated;
                }
            } else if (((EntityExplosion) entity).getBlast() instanceof BlastRedmatter) {
                //https://www.wolframalpha.com/input/?i=(4%2F3)pi+*+r%5E3+%3D+(4%2F3)pi+*+a%5E3+%2B+(4%2F3)pi+*+b%5E3
                //We are going to merge both blasts together
                double sizeA = this.getRadius();
                sizeA = sizeA * sizeA * sizeA;
                double sizeB = ((EntityExplosion) entity).getBlast().getRadius();
                sizeB = sizeB * sizeB * sizeB;
                float radiusNew = (float) Math.cbrt(sizeA + sizeB);
                //Average out timer
                this.callCount = (callCount + ((EntityExplosion) entity).getBlast().callCount) / 2;
                //Destroy current instance
                this.isAlive = false;
                this.controller.setDead();
                //Create new to avoid doing packet syncing
                new BlastRedmatter(world(), entity, position.x(), position.y(), position.z(), radiusNew).explode();
            }
            //Kill explosion entity
            ((EntityExplosion) entity).getBlast().isAlive = false;
            //Kill entity in the center of the ball
            entity.setDead();
        } else if (entity instanceof EntityExplosive) {
            ((EntityExplosive) entity).explode();
        } else if (entity instanceof EntityLiving) {
            ((EntityLiving) entity).attackEntityFrom(DamageSource.outOfWorld, 99999999);
        } else {
            //Kill entity in the center of the ball
            entity.setDead();
        }
    }
    return explosionCreated;
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving) Pos(com.builtbroken.mc.imp.transform.vector.Pos) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityExplosion(icbm.classic.content.entity.EntityExplosion) EntityExplosive(icbm.classic.content.entity.EntityExplosive) EulerAngle(com.builtbroken.mc.imp.transform.rotation.EulerAngle) IExplosiveIgnore(resonant.api.explosion.IExplosiveIgnore) Location(com.builtbroken.mc.imp.transform.vector.Location)

Aggregations

Pos (com.builtbroken.mc.imp.transform.vector.Pos)105 Block (net.minecraft.block.Block)25 TileEntity (net.minecraft.tileentity.TileEntity)13 Location (com.builtbroken.mc.imp.transform.vector.Location)11 Entity (net.minecraft.entity.Entity)11 Cube (com.builtbroken.mc.imp.transform.region.Cube)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 Test (org.junit.Test)7 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)6 EntityMissile (icbm.classic.content.entity.EntityMissile)6 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)6 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)6 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)5 PacketTile (com.builtbroken.mc.core.network.packet.PacketTile)5 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)5 ItemStack (net.minecraft.item.ItemStack)5 EulerAngle (com.builtbroken.mc.imp.transform.rotation.EulerAngle)4 BlockTile (com.builtbroken.mc.prefab.tile.BlockTile)4 Tile (com.builtbroken.mc.prefab.tile.Tile)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4