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;
}
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();
}
}
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);
}
}
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;
}
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));
}
Aggregations