Search in sources :

Example 61 with Pos

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

the class BlockExplosive method onBlockPlacedBy.

/** Called when the block is placed in the world. */
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) {
    TileEntity tile = world.getTileEntity(x, y, z);
    if (tile instanceof TileEntityExplosive) {
        Explosives ex = Explosives.get(itemStack.getItemDamage());
        ((TileEntityExplosive) tile).explosive = ex;
        if (!world.isRemote) {
            ExplosivePreDetonationEvent evt = new ExplosivePreDetonationEvent(world, x, y, z, ExplosiveType.BLOCK, ex.handler);
            MinecraftForge.EVENT_BUS.post(evt);
            if (evt.isCanceled()) {
                this.dropBlockAsItem(world, x, y, z, ex.ordinal(), 0);
                world.setBlock(x, y, z, Blocks.air, 0, 2);
                return;
            }
        }
        world.setBlockMetadataWithNotify(x, y, z, VectorHelper.getOrientationFromSide(ForgeDirection.getOrientation(determineOrientation(world, x, y, z, entityLiving)), ForgeDirection.NORTH).ordinal(), 2);
        if (world.isBlockIndirectlyGettingPowered(x, y, z)) {
            BlockExplosive.triggerExplosive(world, x, y, z, ex, 0);
        }
        // If so, then detonate.
        for (byte i = 0; i < 6; i++) {
            Pos position = new Pos(x, y, z).add(ForgeDirection.getOrientation(i));
            Block blockId = position.getBlock(world);
            if (blockId == Blocks.fire || blockId == Blocks.flowing_lava || blockId == Blocks.lava) {
                BlockExplosive.triggerExplosive(world, x, y, z, ex, 2);
                break;
            }
        }
        if (entityLiving != null) {
            FMLLog.fine(entityLiving.getCommandSenderName() + " placed " + ex.handler.getExplosiveName() + " in: " + x + ", " + y + ", " + z + ".");
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ExplosivePreDetonationEvent(resonant.api.explosion.ExplosionEvent.ExplosivePreDetonationEvent) Pos(com.builtbroken.mc.imp.transform.vector.Pos) Block(net.minecraft.block.Block) RenderBombBlock(icbm.classic.client.render.tile.RenderBombBlock) Explosives(icbm.classic.content.explosive.Explosives)

Example 62 with Pos

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

the class BlockExplosive method triggerExplosive.

/*
     * Called to detonate the TNT. Args: world, x, y, z, metaData, CauseOfExplosion (0, intentional,
     * 1, exploded, 2 burned)
     */
public static void triggerExplosive(World world, int x, int y, int z, Explosives explosiveID, int causeOfExplosion) {
    if (!world.isRemote) {
        TileEntity tileEntity = world.getTileEntity(x, y, z);
        if (tileEntity != null) {
            if (tileEntity instanceof TileEntityExplosive) {
                ExplosivePreDetonationEvent evt = new ExplosivePreDetonationEvent(world, x, y, z, ExplosiveType.BLOCK, ((TileEntityExplosive) tileEntity).explosive.handler);
                MinecraftForge.EVENT_BUS.post(evt);
                if (!evt.isCanceled()) {
                    ((TileEntityExplosive) tileEntity).exploding = true;
                    EntityExplosive eZhaDan = new EntityExplosive(world, new Pos(x, y, z).add(0.5), ((TileEntityExplosive) tileEntity).explosive, (byte) world.getBlockMetadata(x, y, z), ((TileEntityExplosive) tileEntity).nbtData);
                    switch(causeOfExplosion) {
                        case 2:
                            eZhaDan.setFire(100);
                            break;
                    }
                    world.spawnEntityInWorld(eZhaDan);
                    world.setBlockToAir(x, y, z);
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ExplosivePreDetonationEvent(resonant.api.explosion.ExplosionEvent.ExplosivePreDetonationEvent) Pos(com.builtbroken.mc.imp.transform.vector.Pos) EntityExplosive(icbm.classic.content.entity.EntityExplosive)

Example 63 with Pos

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

the class ExEnder method doCreateExplosion.

@SuppressWarnings("deprecation")
@Override
public void doCreateExplosion(World world, double x, double y, double z, Entity entity) {
    Pos teleportTarget = null;
    if (entity instanceof IExplosiveContainer) {
        if (((IExplosiveContainer) entity).getTagCompound().hasKey("x") && ((IExplosiveContainer) entity).getTagCompound().hasKey("y") && ((IExplosiveContainer) entity).getTagCompound().hasKey("z")) {
            teleportTarget = new Pos(((IExplosiveContainer) entity).getTagCompound());
        }
    }
    new BlastEnderman(world, entity, x, y, z, 30, teleportTarget).explode();
}
Also used : IExplosiveContainer(resonant.api.explosion.IExplosiveContainer) BlastEnderman(icbm.classic.content.explosive.blast.BlastEnderman) Pos(com.builtbroken.mc.imp.transform.vector.Pos)

Example 64 with Pos

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

the class MissileCluster method update.

@Override
public void update(EntityMissile missileObj) {
    if (missileObj.motionY < -0.5) {
        if (missileObj.missileCount < MAX_CLUSTER) {
            if (!missileObj.worldObj.isRemote) {
                Pos position = missileObj.toPos();
                EntityMissile missile = new EntityMissile(missileObj.worldObj);
                //TODO spread to avoid collision
                missile.setPosition(position.x(), position.y(), position.z());
                missile.launcherPos = position;
                missile.explosiveID = Explosives.CONDENSED;
                double radius = spread;
                double theta = 0;
                double x = 0;
                double y = 0;
                double z = 0;
                if (missileObj.missileCount > 0) {
                    theta = (missileObj.missileCount / 12.0) * Math.PI * 2;
                    x = radius * Math.cos(theta);
                    missile.posX += Math.cos(theta) * 5;
                    z = radius * Math.sin(theta);
                    missile.posZ += Math.sin(theta) * 5;
                }
                missile.missileType = MissileType.CruiseMissile;
                missile.protectionTime = 20 + missileObj.targetHeight - 1;
                missile.launch(missileObj.targetVector.add(new Pos(x, y, z)));
                missileObj.worldObj.spawnEntityInWorld(missile);
            }
            missileObj.protectionTime = 20;
            missileObj.missileCount++;
        } else {
            missileObj.setDead();
        }
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) EntityMissile(icbm.classic.content.entity.EntityMissile)

Example 65 with Pos

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

the class MissileHoming method onInteract.

@Override
public boolean onInteract(EntityMissile missileObj, EntityPlayer entityPlayer) {
    if (!missileObj.worldObj.isRemote && missileObj.getTicksInAir() <= 0) {
        if (entityPlayer.getCurrentEquippedItem() != null) {
            if (entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemTracker) {
                Entity trackingEntity = ((ItemTracker) entityPlayer.getCurrentEquippedItem().getItem()).getTrackingEntity(missileObj.worldObj, entityPlayer.getCurrentEquippedItem());
                if (trackingEntity != null) {
                    if (missileObj.trackingVar != trackingEntity.getEntityId()) {
                        missileObj.trackingVar = trackingEntity.getEntityId();
                        entityPlayer.addChatMessage(new ChatComponentText("Missile target locked to: " + trackingEntity.getCommandSenderName()));
                        if (missileObj.getLauncher() != null && missileObj.getLauncher().getController() != null) {
                            Pos newTarget = new Pos(trackingEntity.posX, 0, trackingEntity.posZ);
                            missileObj.getLauncher().getController().setTarget(newTarget);
                        }
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : Entity(net.minecraft.entity.Entity) ItemTracker(icbm.classic.content.items.ItemTracker) Pos(com.builtbroken.mc.imp.transform.vector.Pos) ChatComponentText(net.minecraft.util.ChatComponentText)

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