use of com.builtbroken.mc.imp.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class SchematicMap method loadWorldSelection.
public SchematicMap loadWorldSelection(World world, IPos3D pos, IPos3D pos2) {
int deltaX, deltaY, deltaZ;
Pos start = new Pos(pos.x() > pos2.x() ? pos2.x() : pos.x(), pos.y() > pos2.y() ? pos2.y() : pos.y(), pos.z() > pos2.z() ? pos2.z() : pos.z());
SchematicMap sch = new SchematicMap();
if (pos.x() < pos2.x()) {
deltaX = (int) (pos2.x() - pos.x() + 1);
} else {
deltaX = (int) (pos.x() - pos2.x() + 1);
}
if (pos.y() < pos2.y()) {
deltaY = (int) (pos2.y() - pos.y() + 1);
} else {
deltaY = (int) (pos.y() - pos2.y() + 1);
}
if (pos.z() < pos2.z()) {
deltaZ = (int) (pos2.z() - pos.z() + 1);
} else {
deltaZ = (int) (pos.z() - pos2.z() + 1);
}
sch.schematicSize = new Pos(deltaX, deltaY, deltaZ);
for (int x = 0; x < deltaX; ++x) {
for (int y = 0; y < deltaY; ++y) {
for (int z = 0; z < deltaZ; ++z) {
Block block = world.getBlock((int) start.x() + x, (int) start.y() + y, (int) start.z() + z);
int blockMeta = world.getBlockMetadata((int) start.x() + x, (int) start.y() + y, (int) start.z() + z);
sch.block_map.put(new Pos(x, y, z), new Pair<>(block, blockMeta));
}
}
}
return sch;
}
use of com.builtbroken.mc.imp.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class SchematicMap method save.
@Override
public NBTTagCompound save(NBTTagCompound nbt) {
if (!init) {
this.init();
}
NBTTagCompound blockNBT = nbt.getCompoundTag(BLOCK_LIST_SAVE_NAME);
if (this.schematicSize != null) {
nbt.setInteger("sizeX", (int) this.schematicSize.x());
nbt.setInteger("sizeY", (int) this.schematicSize.y());
nbt.setInteger("sizeZ", (int) this.schematicSize.z());
}
if (this.schematicCenter != null) {
nbt.setInteger("centerX", (int) this.schematicCenter.x());
nbt.setInteger("centerY", (int) this.schematicCenter.y());
nbt.setInteger("centerZ", (int) this.schematicCenter.z());
}
int i = 0;
for (Entry<Pos, Pair<Block, Integer>> entry : block_map.entrySet()) {
String output = "";
Block block = entry.getValue().left();
if (block != null && SchematicMap.BLOCK_SAVE_MAP_REV.containsKey(block)) {
output += SchematicMap.BLOCK_SAVE_MAP_REV.get(block);
} else {
output += entry.getValue().left();
}
output += ":" + entry.getValue().right();
output += ":" + (entry.getKey().x()) + ":" + ((int) entry.getKey().y()) + ":" + ((int) entry.getKey().z());
blockNBT.setString("Block" + i, output);
i++;
}
blockNBT.setInteger("count", i);
nbt.setTag(BLOCK_LIST_SAVE_NAME, blockNBT);
return nbt;
}
use of com.builtbroken.mc.imp.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class AbstractTileEntityTest method testGetDistanceFrom.
@Test
public void testGetDistanceFrom() {
T tile = newTile();
FakeWorld world = FakeWorld.newWorld("testGetDistanceFrom");
tile.setWorldObj(world);
double distance = tile.getDistanceFrom(10, 14, 15);
double distance2 = new Pos(0.5).sub(10, 14, 15).magnitudeSquared();
assertTrue("Distance = " + distance + " Distance2 = " + distance2, Math.abs(distance - distance2) < .01);
}
use of com.builtbroken.mc.imp.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class SchematicMap method getBlocksToPlace.
/**
* Gets all blocks needed to build the schematic at the given location
*
* @param spot - center point of the schematic
* @param blockMap - map of blocks from the schematic file
* @param checkWorld - check if blocks are already placed
* @param checkIfWorldIsLoaded - check if the area is loaded, make sure this is true if
* checkWorld boolean is true as it effects the results if the chunk is unloaded. Setting this
* true will not load the area and is designed to prevent wasting blocks when generating
* buildings using actual blocks
*/
public void getBlocksToPlace(Location spot, List<IWorldEdit> blockMap, boolean checkWorld, boolean checkIfWorldIsLoaded) {
if (this.block_map != null) {
for (Entry<Pos, Pair<Block, Integer>> entry : this.block_map.entrySet()) {
Block block = entry.getValue().left();
int meta = entry.getValue().right();
if (block == null || block != Blocks.sponge) {
if (meta > 15) {
meta = 15;
} else if (meta < 0) {
meta = 0;
}
Pos setPos = spot.toPos().subtract(this.schematicCenter).add(entry.getKey());
if (checkWorld) {
if (checkIfWorldIsLoaded) {
Chunk chunk = spot.world.getChunkFromBlockCoords(setPos.xi(), setPos.zi());
if (!chunk.isChunkLoaded) {
continue;
}
}
Block checkID = setPos.getBlock(spot.world);
int checkMeta = setPos.getBlockMetadata(spot.world);
if (checkID == block && checkMeta == meta) {
continue;
}
}
blockMap.add(new BlockEdit(spot.world, setPos).set(block, meta));
}
}
}
}
use of com.builtbroken.mc.imp.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class MultiBlockListener method onMultiTileBroken.
@Override
public boolean onMultiTileBroken(IMultiTile tileMulti, Object source, boolean harvest) {
if (!_destroyingStructure && tileMulti instanceof TileEntity) {
Pos pos = new Pos((TileEntity) tileMulti).floor().sub(new Pos(this).floor());
if (getLayoutOfMultiBlock().containsKey(pos)) {
_destroyingStructure = true;
MultiBlockHelper.destroyMultiBlockStructure(getMultiTileHost() != null ? getMultiTileHost() : this, harvest, true, true);
_destroyingStructure = false;
return true;
}
}
return false;
}
Aggregations