Search in sources :

Example 6 with Pos

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

the class Schematic method getBox.

/**
	 * Creates a map of vectors in the shape of a square
	 *
	 * @param center - center to create the box around, controls offset for later if needed
	 * @param block  - block to make the box out of
	 * @param meta   - meta value of the block for placement
	 * @param sizeX  - size from the center to the edge, half of the side
	 * @param sizeZ  - size from the center to the edge, half of the side
	 * @return hash map of vectors to placement data
	 */
public HashMap<Pos, Pair<Block, Integer>> getBox(final Pos center, Block block, int meta, int sizeX, int sizeZ) {
    HashMap<Pos, Pair<Block, Integer>> returnMap = new HashMap();
    //zero zero corner of the square
    Pos start = new Pos(-sizeX, 0, -sizeZ).add(center);
    if (sizeX != sizeZ) {
        // X sides
        for (int x = 0; x <= sizeX * 2; x++) {
            returnMap.put(new Pos(x, 0, 0).add(start), new Pair<>(block, meta));
            returnMap.put(new Pos(x, 0, sizeZ * 2).add(start), new Pair<>(block, meta));
        }
        // Z sides
        for (int z = 0; z <= sizeZ * 2; z++) {
            returnMap.put(new Pos(0, 0, z).add(start), new Pair<>(block, meta));
            returnMap.put(new Pos(sizeX * 2, 0, z).add(start), new Pair<>(block, meta));
        }
    } else {
        // All sides, used verses the other way as it cuts the time in half
        for (int s = 0; s <= sizeX * 2; s++) {
            returnMap.put(new Pos(s, 0, 0).add(start), new Pair<>(block, meta));
            returnMap.put(new Pos(s, 0, sizeZ * 2).add(start), new Pair<>(block, meta));
            returnMap.put(new Pos(0, 0, s).add(start), new Pair<>(block, meta));
            returnMap.put(new Pos(sizeZ * 2, 0, s).add(start), new Pair<>(block, meta));
        }
    }
    return returnMap;
}
Also used : HashMap(java.util.HashMap) Pos(com.builtbroken.mc.imp.transform.vector.Pos) Pair(com.builtbroken.jlib.type.Pair)

Example 7 with Pos

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

the class SchematicMap method load.

@Override
public void load(NBTTagCompound nbt) {
    schematicSize = new Pos(nbt.getInteger("sizeX"), nbt.getInteger("sizeY"), nbt.getInteger("sizeZ"));
    schematicCenter = new Pos(nbt.getInteger("centerX"), nbt.getInteger("centerY"), nbt.getInteger("centerZ"));
    NBTTagCompound blockDataSave = nbt.getCompoundTag(BLOCK_LIST_SAVE_NAME);
    for (int blockCount = 0; blockCount < blockDataSave.getInteger("count"); blockCount++) {
        String blockString = blockDataSave.getString("Block" + blockCount);
        String[] blockData = blockString.split(":");
        //int blockID = 0;
        Block block = null;
        int blockMeta = 0;
        Pos blockPostion = new Pos();
        if (blockData != null) {
            try {
                if (blockData.length > 0) {
                    if (SchematicMap.BLOCK_SAVE_MAP.containsKey(blockData[0])) {
                        block = SchematicMap.BLOCK_SAVE_MAP.get(blockData[0]);
                    } else {
                        //TODO: Fix up, wrong implementation
                        block = Block.getBlockById(Integer.parseInt(blockData[0]));
                    }
                }
                if (blockData.length > 1) {
                    blockMeta = Integer.parseInt(blockData[1]);
                }
                int x = 0;
                int y = 0;
                int z = 0;
                if (blockData.length > 2) {
                    x = Integer.parseInt(blockData[2]);
                }
                if (blockData.length > 3) {
                    y = Integer.parseInt(blockData[3]);
                }
                if (blockData.length > 4) {
                    z = Integer.parseInt(blockData[4]);
                }
                blockPostion = new Pos(x, y, z);
            } catch (Exception e) {
                e.printStackTrace();
            }
            this.block_map.put(blockPostion, new Pair<>(block, blockMeta));
        }
    }
    if (!init) {
        this.init();
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Block(net.minecraft.block.Block)

Example 8 with Pos

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

the class SchematicMap method init.

public void init() {
    if (this.schematicSize != null) {
        this.init = true;
        this.schematicCenter = new Pos(this.schematicSize.x() / 2, 0, this.schematicSize.z() / 2);
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos)

Example 9 with Pos

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

the class Selection method getLocationsWithin.

/**
     * Grabs all blocks near the point and within the distance.
     * <p/>
     * Note this search pattern does start at most negative corner
     * TODO replace search pattern with same code the blasts use
     * to select blocks in a bubble
     *
     * @param location - center point of the search
     * @param size     - number of items to return
     * @param distance - distance to search
     * @return list of locations of non air blocks sorted to closest to location
     */
public List<Pos> getLocationsWithin(Location location, int size, int distance) {
    List<Pos> list = new LinkedList<>();
    if (distance > 0) {
        int min_y = (int) Math.max(min().yi(), location.y() - distance);
        int max_y = (int) Math.min(max().yi(), location.y() + distance);
        int min_x = (int) Math.max(min().xi(), location.x() - distance);
        int max_x = (int) Math.min(max().xi(), location.x() + distance);
        int min_z = (int) Math.max(min().zi(), location.z() - distance);
        int max_z = (int) Math.min(max().zi(), location.z() + distance);
        for (int y = min_y; y <= max_y; y++) {
            for (int x = min_x; x <= max_x; x++) {
                for (int z = min_z; z <= max_z; z++) {
                    if (size > 0 && list.size() >= size) {
                        Collections.sort(list, new Vector3DistanceComparator(location));
                        return list;
                    }
                    Pos pos = new Pos(x, y, z);
                    if (location.distance(pos) <= distance) {
                        Block b = pos.getBlock(location.world());
                        if (b != null && !pos.isAirBlock(location.world()) && pos.getHardness(location.world()) >= 0) {
                            list.add(pos);
                        }
                    }
                }
            }
        }
    }
    return list;
}
Also used : Vector3DistanceComparator(com.builtbroken.mc.imp.transform.sorting.Vector3DistanceComparator) Pos(com.builtbroken.mc.imp.transform.vector.Pos) Block(net.minecraft.block.Block) LinkedList(java.util.LinkedList)

Example 10 with Pos

use of com.builtbroken.mc.imp.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.imp.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)

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