Search in sources :

Example 11 with Cube

use of com.builtbroken.mc.imp.transform.region.Cube in project ICBM-Classic by BuiltBrokenModding.

the class BlastRepulsive method pushEntities.

public void pushEntities(float radius, float force, int type) {
    // Step 2: Damage all entities
    Pos minCoord = position.toPos();
    minCoord = minCoord.add(-radius - 1);
    Pos maxCoord = position.toPos();
    maxCoord = maxCoord.add(radius + 1);
    Cube region = new Cube(minCoord, maxCoord);
    List<Entity> entities = region.getEntities(this.world(), Entity.class);
    for (Entity entity : entities) {
        double var13 = entity.getDistance(position.x(), position.y(), position.z()) / radius;
        if (var13 <= 1.0D) {
            double xDifference = entity.posX - position.x();
            double yDifference = entity.posY - position.y();
            double zDifference = entity.posZ - position.z();
            double distance = MathHelper.sqrt_double(xDifference * xDifference + yDifference * yDifference + zDifference * zDifference);
            xDifference /= distance;
            yDifference /= distance;
            zDifference /= distance;
            if (type == 1) {
                double modifier = var13 * force * (entity instanceof EntityPlayer ? 0.5 : 1);
                entity.addVelocity(-xDifference * modifier, -yDifference * modifier, -zDifference * modifier);
            } else if (type == 2) {
                double modifier = (1.0D - var13) * force * (entity instanceof EntityPlayer ? 0.5 : 1);
                entity.addVelocity(xDifference * modifier, yDifference * modifier, zDifference * modifier);
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) Pos(com.builtbroken.mc.imp.transform.vector.Pos) Cube(com.builtbroken.mc.imp.transform.region.Cube) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 12 with Cube

use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.

the class PacketSelectionData method encodeInto.

@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
    //Write player's selection
    selection.writeBytes(buffer);
    //Write cubes
    buffer.writeInt(cubes.size());
    for (Cube cube : cubes) {
        cube.writeBytes(buffer);
    }
    //Write regions
    buffer.writeInt(regions.size());
    for (Cube cube : regions) {
        cube.writeBytes(buffer);
    }
}
Also used : Cube(com.builtbroken.mc.imp.transform.region.Cube)

Example 13 with Cube

use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.

the class AbstractTileTest method testGetCollisionBoxes.

@Test
public void testGetCollisionBoxes() {
    FakeWorld world = FakeWorld.newWorld("TestGetCollisionBoxes");
    world.setBlock(0, 0, 0, block);
    Tile tile = ((Tile) world.getTileEntity(0, 0, 0));
    Iterable<Cube> cubes = tile.getCollisionBoxes(new Cube(-2, -2, -2, 2, 2, 2), player);
    assertTrue(cubes != null);
    for (Cube cube : cubes) {
        assertTrue(cube != null);
    //TODO check if the cube is valid
    }
}
Also used : Cube(com.builtbroken.mc.imp.transform.region.Cube) 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 14 with Cube

use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.

the class CuboidTest method testCollisionOverlap.

public void testCollisionOverlap() {
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        Pos vec = new Pos(dir).multiply(0.3);
        Cube c = cube.add(vec);
        if (!cube.doesOverlap(c)) {
            System.out.println("Cube:  " + cube);
            System.out.println("Above: " + c.toString());
            assertEquals("x check failed", cube.isOutSideX(c.min().x(), c.max().x()), dir == ForgeDirection.EAST || dir == ForgeDirection.WEST);
            assertEquals("y check failed", cube.isOutSideY(c.min().y(), c.max().y()), dir == ForgeDirection.DOWN || dir == ForgeDirection.UP);
            assertEquals("z check failed", cube.isOutSideZ(c.min().z(), c.max().z()), dir == ForgeDirection.NORTH || dir == ForgeDirection.SOUTH);
            fail("Didn't collide for side " + dir);
        }
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) Cube(com.builtbroken.mc.imp.transform.region.Cube) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 15 with Cube

use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.

the class CuboidTest method testInsideBounds.

public void testInsideBounds() {
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        Cube above = cube.clone();
        assertEquals("Failed center collision check for side " + dir, true, cube.isInsideBounds(above));
        above = above.add(new Pos(dir));
        assertEquals("Failed collision check one for side " + dir, false, cube.isInsideBounds(above));
        above = above.add(new Pos(dir));
        assertEquals("Failed collision check two for side " + dir, false, cube.isInsideBounds(above));
    }
}
Also used : Cube(com.builtbroken.mc.imp.transform.region.Cube) Pos(com.builtbroken.mc.imp.transform.vector.Pos) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Aggregations

Cube (com.builtbroken.mc.imp.transform.region.Cube)21 Pos (com.builtbroken.mc.imp.transform.vector.Pos)8 IRadioWaveReceiver (com.builtbroken.mc.api.map.radio.IRadioWaveReceiver)5 ArrayList (java.util.ArrayList)4 Entity (net.minecraft.entity.Entity)4 PacketTile (com.builtbroken.mc.core.network.packet.PacketTile)3 BlockTile (com.builtbroken.mc.prefab.tile.BlockTile)3 Tile (com.builtbroken.mc.prefab.tile.Tile)3 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)3 TileEntity (net.minecraft.tileentity.TileEntity)3 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)3 Test (org.junit.Test)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)2 IRadioWaveSender (com.builtbroken.mc.api.map.radio.IRadioWaveSender)1 IMultiTileHost (com.builtbroken.mc.api.tile.multiblock.IMultiTileHost)1 PacketSelectionData (com.builtbroken.mc.core.network.packet.PacketSelectionData)1 RadioMap (com.builtbroken.mc.lib.world.radio.RadioMap)1 Region (com.builtbroken.mc.modflag.Region)1 EntityExplosive (icbm.classic.content.entity.EntityExplosive)1