Search in sources :

Example 16 with Pos

use of com.builtbroken.mc.imp.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class Vector3Test method testAddition.

/** Simple addition test for Vector3 */
public void testAddition() throws Exception {
    Pos vec = new Pos(0, 1, 0);
    vec = vec.add(1, 1, 1);
    Assert.assertEquals(2.0, vec.y(), 0);
    Assert.assertEquals(1.0, vec.x(), 0);
    Assert.assertEquals(1.0, vec.z(), 0);
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos)

Example 17 with Pos

use of com.builtbroken.mc.imp.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class Vector3Test method testSubtraction.

/** Simple addition test for Vector3 */
public void testSubtraction() throws Exception {
    Pos vec = new Pos(0, 1, 0);
    vec = vec.subtract(1, 1, 1);
    Assert.assertEquals(0.0, vec.y(), 0);
    Assert.assertEquals(-1.0, vec.x(), 0);
    Assert.assertEquals(-1.0, vec.z(), 0);
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos)

Example 18 with Pos

use of com.builtbroken.mc.imp.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class SelectionHandler method updatePlayerRenderData.

public static void updatePlayerRenderData(EntityPlayerMP player) {
    List<Cube> cubes = new ArrayList();
    List<Cube> regions = new ArrayList();
    Cube selection = getSelection(player);
    for (Cube cube : selections.values()) {
        if (cube != selection && cube.distance(new Pos(player)) <= 160) {
            cubes.add(cube);
        }
    }
    for (Region region : RegionManager.getControllerForWorld(player.worldObj).getRegionsNear(player, 160)) {
        for (Cube cube : region.segments) {
            if (cube.isCloseToAnyCorner(new Pos(player), 160)) {
                regions.add(cube);
            }
        }
    }
    Engine.instance.packetHandler.sendToPlayer(new PacketSelectionData(selection, cubes, regions), player);
}
Also used : PacketSelectionData(com.builtbroken.mc.core.network.packet.PacketSelectionData) Cube(com.builtbroken.mc.imp.transform.region.Cube) Pos(com.builtbroken.mc.imp.transform.vector.Pos) ArrayList(java.util.ArrayList) Region(com.builtbroken.mc.modflag.Region)

Example 19 with Pos

use of com.builtbroken.mc.imp.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class MultiBlockHelper method destroyMultiBlockStructure.

/**
     * Breaks down the multiblock stucture linked to the host
     *
     * @param host     - host providing the layour of the structure
     * @param doDrops  - attempt to drop blocks?
     * @param offset   - offset the layout by the location of the host?
     * @param killHost - destroy the host block as well?
     */
public static void destroyMultiBlockStructure(IMultiTileHost host, boolean doDrops, boolean offset, boolean killHost) {
    if (host != null) {
        HashMap<IPos3D, String> map = host.getLayoutOfMultiBlock();
        if (map != null && !map.isEmpty()) {
            IWorldPosition center;
            if (host instanceof TileEntity) {
                center = new Location((TileEntity) host);
            } else if (host instanceof IWorldPosition) {
                center = (IWorldPosition) host;
            } else {
                logger.error("MultiBlockHelper >> Tile[" + host + "]'s is not a TileEntity or IWorldPosition instance, thus we can not get a position to break down the structure.");
                return;
            }
            for (Map.Entry<IPos3D, String> entry : map.entrySet()) {
                Pos pos = entry.getKey() instanceof Pos ? (Pos) entry.getKey() : new Pos(entry.getKey());
                if (offset) {
                    pos = pos.add(center);
                }
                TileEntity tile = pos.getTileEntity(center.world());
                if (tile instanceof IMultiTile) {
                    ((IMultiTile) tile).setHost(null);
                    pos.setBlockToAir(center.world());
                }
            }
            if (doDrops) {
                InventoryUtility.dropBlockAsItem(center, killHost);
            } else if (killHost) {
                center.world().setBlockToAir(center.xi(), center.yi(), center.zi());
            }
        } else {
            logger.error("MultiBlockHelper >> Tile[" + host + "]'s structure map is empty");
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) Pos(com.builtbroken.mc.imp.transform.vector.Pos) IWorldPosition(com.builtbroken.mc.api.IWorldPosition) IMultiTile(com.builtbroken.mc.api.tile.multiblock.IMultiTile) HashMap(java.util.HashMap) Map(java.util.Map) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 20 with Pos

use of com.builtbroken.mc.imp.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class MultiBlockHelper method updateStructure.

/**
     * Runs a world update on all members of the structure
     *
     * @param world
     * @param host
     * @param offset - off set the location data by the center of the host
     */
public static void updateStructure(World world, IMultiTileHost host, boolean offset) {
    //TODO junit test
    if (!(host instanceof TileEntity)) {
        Engine.error("Tile host is not an instance of TileEntity");
    }
    if (world == null) {
        Engine.error("Tile host is not an instance of TileEntity");
    }
    HashMap<IPos3D, String> map = host.getLayoutOfMultiBlock();
    if (map != null && !map.isEmpty()) {
        int x = ((TileEntity) host).xCoord;
        int y = ((TileEntity) host).yCoord;
        int z = ((TileEntity) host).zCoord;
        Pos center = new Pos(x, y, z);
        for (Map.Entry<IPos3D, String> entry : map.entrySet()) {
            Location pos = new Location(world, entry.getKey());
            if (offset) {
                pos = pos.add(center);
            }
            pos.markForUpdate();
        }
        center.markForUpdate(world);
    } else {
        logger.error("Tile[" + host + "]'s structure map is empty");
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) Pos(com.builtbroken.mc.imp.transform.vector.Pos) HashMap(java.util.HashMap) Map(java.util.Map) 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