Search in sources :

Example 16 with Pos

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

the class TestBlockEdit method testHashCode.

@Test
public void testHashCode() {
    World world = FakeWorld.newWorld("BlockEditTest");
    World world2 = FakeWorld.newWorld("BlockEditTest2");
    BlockEdit location = new BlockEdit(world, 0, 0, 0);
    BlockEdit location2 = new BlockEdit(world, 0, 0, 0);
    // Test would equals
    Assert.assertEquals("BlockEdit one should equal itself", location.hashCode(), location.hashCode());
    Assert.assertEquals("BlockEdit two should equal itself", location2.hashCode(), location2.hashCode());
    Assert.assertEquals("BlockEdit one & two should equal each other", location.hashCode(), location2.hashCode());
    location2 = new BlockEdit(world2, 0, 0, 0);
    // Test world not equal
    Assert.assertNotSame("BlockEdit one & two should not equal each other", location.hashCode(), location2.hashCode());
    location = new BlockEdit(world, 0, 1, 0);
    // Test pos not equal
    Assert.assertNotSame("BlockEdit one & two should not equal each other", location.hashCode(), location2.hashCode());
    // Test decimal point
    for (Pos pos : new Pos[] { new Pos(1, 2.0, 3.0f), new Pos(1, 2.2, 3.1f), new Pos(1.5125412, 2.2223, 3.0f), new Pos(1.231, 2.45454, 3.23213f) }) {
        location = new BlockEdit(world, pos.x(), pos.y(), pos.z());
        location2 = new BlockEdit(world, pos.x(), pos.y(), pos.z());
        // Test would equals
        Assert.assertEquals("BlockEdit one should equal itself", location.hashCode(), location.hashCode());
        Assert.assertEquals("BlockEdit two should equal itself", location2.hashCode(), location2.hashCode());
        Assert.assertEquals("BlockEdit one & two should equal each other", location.hashCode(), location2.hashCode());
    }
    location = new BlockEdit(world, 1, 2, 3);
    location2 = new BlockEdit(world, 1.3, 2.2, 3.4);
    // Test would equals
    Assert.assertEquals("BlockEdit one should equal itself", location.hashCode(), location.hashCode());
    Assert.assertEquals("BlockEdit two should equal itself", location2.hashCode(), location2.hashCode());
    Assert.assertEquals("BlockEdit one & two should equal each other", location.hashCode(), location2.hashCode());
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) World(net.minecraft.world.World) FakeWorld(com.builtbroken.mc.testing.junit.world.FakeWorld) BlockEdit(com.builtbroken.mc.lib.world.edit.BlockEdit) AbstractTest(com.builtbroken.mc.testing.junit.AbstractTest) Test(org.junit.Test)

Example 17 with Pos

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

the class TestBlockEdit method testEquals.

@Test
public void testEquals() {
    World world = FakeWorld.newWorld("BlockEditTest");
    World world2 = FakeWorld.newWorld("BlockEditTest2");
    BlockEdit location = new BlockEdit(world, 0, 0, 0);
    BlockEdit location2 = new BlockEdit(world, 0, 0, 0);
    // Test would equals
    Assert.assertEquals("BlockEdit one should equal itself", location, location);
    Assert.assertEquals("BlockEdit two should equal itself", location2, location2);
    Assert.assertEquals("BlockEdit one & two should equal each other", location, location2);
    location2 = new BlockEdit(world2, 0, 0, 0);
    // Test world not equal
    Assert.assertNotSame("BlockEdit one & two should not equal each other", location, location2);
    location = new BlockEdit(world, 0, 1, 0);
    // Test pos not equal
    Assert.assertNotSame("BlockEdit one & two should not equal each other", location, location2);
    // Test decimal point
    for (Pos pos : new Pos[] { new Pos(1, 2.0, 3.0f), new Pos(1, 2.2, 3.1f), new Pos(1.5125412, 2.2223, 3.0f), new Pos(1.231, 2.45454, 3.23213f) }) {
        location = new BlockEdit(world, pos.x(), pos.y(), pos.z());
        location2 = new BlockEdit(world, pos.x(), pos.y(), pos.z());
        // Test would equals
        Assert.assertEquals("BlockEdit one should equal itself", location, location);
        Assert.assertEquals("BlockEdit two should equal itself", location2, location2);
        Assert.assertEquals("BlockEdit one & two should equal each other", location, location2);
    }
    location = new BlockEdit(world, 1, 2, 3);
    location2 = new BlockEdit(world, 1.3, 2.2, 3.4);
    // Test would equals
    Assert.assertEquals("BlockEdit one should equal itself", location, location);
    Assert.assertEquals("BlockEdit two should equal itself", location2, location2);
    Assert.assertEquals("BlockEdit one & two should equal each other", location, location2);
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) World(net.minecraft.world.World) FakeWorld(com.builtbroken.mc.testing.junit.world.FakeWorld) BlockEdit(com.builtbroken.mc.lib.world.edit.BlockEdit) AbstractTest(com.builtbroken.mc.testing.junit.AbstractTest) Test(org.junit.Test)

Example 18 with Pos

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

the class BlockTile method onNeighborChange.

@Override
public void onNeighborChange(IBlockAccess world, int x, int y, int z, int tileX, int tileY, int tileZ) {
    if (!(world instanceof World) || !((World) world).isRemote) {
        Tile tile = inject(world, x, y, z);
        tile.onNeighborChanged(new Pos(tileX, tileY, tileZ));
        eject();
    }
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) World(net.minecraft.world.World)

Example 19 with Pos

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

the class BlockTile method addCollisionBoxesToList.

@Override
@SuppressWarnings("unchecked")
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB aabb, List list, Entity entity) {
    Tile tile = inject(world, x, y, z);
    Iterable<Cube> bounds = tile.getCollisionBoxes(new Cube(aabb).subtract(new Pos(x, y, z)), entity);
    eject();
    if (bounds != null) {
        for (Cube cuboid : bounds) {
            AxisAlignedBB bb = cuboid.toAABB().offset(x, y, z);
            if (aabb.intersectsWith(bb)) {
                list.add(bb);
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Cube(com.builtbroken.mc.lib.transform.region.Cube) Pos(com.builtbroken.mc.lib.transform.vector.Pos)

Example 20 with Pos

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

the class CuboidTest method testCollisionCorners.

public void testCollisionCorners() {
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        for (int side = 0; side < 4; side++) {
            Pos vec = new Pos(dir).multiply(0.3);
            switch(dir) {
                case DOWN:
                case UP:
                    switch(side) {
                        case 0:
                            vec.add(0.3, 0, 0.3);
                            break;
                        case 1:
                            vec.add(-0.3, 0, 0.3);
                            break;
                        case 2:
                            vec.add(0.3, 0, -0.3);
                            break;
                        case 3:
                            vec.add(-0.3, 0, -0.3);
                            break;
                    }
                case NORTH:
                case SOUTH:
                    switch(side) {
                        case 0:
                            vec.add(0.3, 0.3, 0);
                            break;
                        case 1:
                            vec.add(-0.3, 0.3, 0);
                            break;
                        case 2:
                            vec.add(0.3, -0.3, 0);
                            break;
                        case 3:
                            vec.add(-0.3, -0.3, 0);
                            break;
                    }
                    break;
                case WEST:
                case EAST:
                    switch(side) {
                        case 0:
                            vec.add(0, 0.3, 0.3);
                            break;
                        case 1:
                            vec.add(0, -0.3, 0.3);
                            break;
                        case 2:
                            vec.add(0, 0.3, -0.3);
                            break;
                        case 3:
                            vec.add(0, -0.3, -0.3);
                            break;
                    }
                    break;
            }
            Cube c = cube.clone().add(vec);
            if (!cube.doesOverlap(c)) {
                System.out.println("Cube:  " + cube);
                System.out.println("Above: " + c.toString());
                System.out.println("Is outside X limits -> " + cube.isOutSideX(c.min().x(), c.max().x()));
                System.out.println("Is outside Y limits -> " + cube.isOutSideY(c.min().y(), c.max().y()));
                System.out.println("Is outside Z limits -> " + cube.isOutSideZ(c.min().z(), c.max().z()));
                fail("Didn't collide for side " + dir + " and corner " + side);
            }
        }
    }
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) Cube(com.builtbroken.mc.lib.transform.region.Cube) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

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