Search in sources :

Example 21 with Pos

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

the class AbstractTileTest method testGetExplosionResistance.

@Test
public void testGetExplosionResistance() {
    FakeWorld world = FakeWorld.newWorld("TestGetExplosionResistance");
    world.setBlock(0, 0, 0, block);
    Tile tile = ((Tile) world.getTileEntity(0, 0, 0));
    tile.getExplosionResistance(player);
    world.setBlock(0, 0, 0, block);
    tile = ((Tile) world.getTileEntity(0, 0, 0));
    tile.getExplosionResistance(player, new Pos(2));
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) FakeWorld(com.builtbroken.mc.testing.junit.world.FakeWorld) PacketTile(com.builtbroken.mc.core.network.packet.PacketTile) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile) Tile(com.builtbroken.mc.prefab.tile.Tile) Test(org.junit.Test)

Example 22 with Pos

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

the class AbstractTileTest method testToPos.

@Test
public void testToPos() {
    FakeWorld world = FakeWorld.newWorld("TestTopos");
    world.setBlock(0, 0, 0, block);
    Tile tile = ((Tile) world.getTileEntity(0, 0, 0));
    Pos pos = tile.toPos();
    Pos pos2 = new Pos(tile.x(), tile.y(), tile.z());
    assertTrue("Pos " + pos + " does not equal " + pos2, pos.equals(pos2));
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) FakeWorld(com.builtbroken.mc.testing.junit.world.FakeWorld) PacketTile(com.builtbroken.mc.core.network.packet.PacketTile) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile) Tile(com.builtbroken.mc.prefab.tile.Tile) Test(org.junit.Test)

Example 23 with Pos

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

the class AbstractTileTest method testDistance.

@Test
public void testDistance() {
    FakeWorld world = FakeWorld.newWorld("TestDistance");
    world.setBlock(0, 0, 0, block);
    Tile tile = ((Tile) world.getTileEntity(0, 0, 0));
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        Pos pos = new Pos(0.5).add(dir);
        Pos center = tile.toPos();
        double distance = tile.distance(pos.x(), pos.y(), pos.z());
        assertTrue("Distance = " + distance + "  Pos = " + pos + "  Center = " + center, Math.abs(distance - 1) <= 0.01);
        player.setLocationAndAngles(pos.x(), pos.y(), pos.z(), 0, 0);
        distance = tile.distance(player);
        assertTrue("Distance = " + distance + "  Pos = " + pos + "  Center = " + center, Math.abs(distance - 1) <= 0.01);
        distance = tile.distance(pos);
        assertTrue("Distance = " + distance + "  Pos = " + pos + "  Center = " + center, Math.abs(distance - 1) <= 0.01);
    }
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) FakeWorld(com.builtbroken.mc.testing.junit.world.FakeWorld) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) PacketTile(com.builtbroken.mc.core.network.packet.PacketTile) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile) Tile(com.builtbroken.mc.prefab.tile.Tile) Test(org.junit.Test)

Example 24 with Pos

use of com.builtbroken.mc.lib.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 instanceof TileEntity) {
        HashMap<IPos3D, String> map = host.getLayoutOfMultiBlock();
        if (map != null && !map.isEmpty()) {
            World world = ((TileEntity) host).getWorldObj();
            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()) {
                Pos pos = new Pos(entry.getKey());
                if (offset) {
                    pos = pos.add(center);
                }
                TileEntity tile = pos.getTileEntity(world);
                if (tile instanceof IMultiTile) {
                    ((IMultiTile) tile).setHost(null);
                    pos.setBlockToAir(world);
                }
            }
            if (doDrops) {
                InventoryUtility.dropBlockAsItem(world, x, y, z, killHost);
            } else if (killHost) {
                world.setBlockToAir(x, y, z);
            }
        } else {
            logger.error("Tile[" + host + "]'s structure map is empty");
        }
    } else {
        logger.error("Tile[" + host + "] is not an instanceof TileEntity");
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) Pos(com.builtbroken.mc.lib.transform.vector.Pos) World(net.minecraft.world.World) IMultiTile(com.builtbroken.mc.api.tile.multiblock.IMultiTile) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with Pos

use of com.builtbroken.mc.lib.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.lib.transform.vector.Pos) HashMap(java.util.HashMap) Map(java.util.Map) Location(com.builtbroken.mc.lib.transform.vector.Location)

Aggregations

Pos (com.builtbroken.mc.lib.transform.vector.Pos)68 Block (net.minecraft.block.Block)11 TileEntity (net.minecraft.tileentity.TileEntity)8 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)8 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)7 Cube (com.builtbroken.mc.lib.transform.region.Cube)6 Test (org.junit.Test)6 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)5 BlockEdit (com.builtbroken.mc.lib.world.edit.BlockEdit)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Vector3DistanceComparator (com.builtbroken.mc.lib.transform.sorting.Vector3DistanceComparator)4 BlockTile (com.builtbroken.mc.prefab.tile.BlockTile)4 Tile (com.builtbroken.mc.prefab.tile.Tile)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 World (net.minecraft.world.World)4 Pair (com.builtbroken.jlib.type.Pair)3 PacketTile (com.builtbroken.mc.core.network.packet.PacketTile)3 Quaternion (com.builtbroken.mc.lib.transform.rotation.Quaternion)3 AbstractTest (com.builtbroken.mc.testing.junit.AbstractTest)3