use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class AbstractTileTest method testGetExplosionResistance.
@Test
public void testGetExplosionResistance() {
FakeWorld world = FakeWorld.newWorld("TestGetExplosionResistance");
world.setBlock(0, 0, 0, block);
Tile tile = ((Tile) world.getTileEntity(0, 0, 0));
tile.getExplosionResistance(player);
world.setBlock(0, 0, 0, block);
tile = ((Tile) world.getTileEntity(0, 0, 0));
tile.getExplosionResistance(player, new Pos(2));
}
use of com.builtbroken.mc.lib.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));
}
use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class AbstractTileTest method testDistance.
@Test
public void testDistance() {
FakeWorld world = FakeWorld.newWorld("TestDistance");
world.setBlock(0, 0, 0, block);
Tile tile = ((Tile) world.getTileEntity(0, 0, 0));
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
Pos pos = new Pos(0.5).add(dir);
Pos center = tile.toPos();
double distance = tile.distance(pos.x(), pos.y(), pos.z());
assertTrue("Distance = " + distance + " Pos = " + pos + " Center = " + center, Math.abs(distance - 1) <= 0.01);
player.setLocationAndAngles(pos.x(), pos.y(), pos.z(), 0, 0);
distance = tile.distance(player);
assertTrue("Distance = " + distance + " Pos = " + pos + " Center = " + center, Math.abs(distance - 1) <= 0.01);
distance = tile.distance(pos);
assertTrue("Distance = " + distance + " Pos = " + pos + " Center = " + center, Math.abs(distance - 1) <= 0.01);
}
}
use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class MultiBlockHelper method destroyMultiBlockStructure.
/**
* Breaks down the multiblock stucture linked to the host
*
* @param host - host providing the layour of the structure
* @param doDrops - attempt to drop blocks?
* @param offset - offset the layout by the location of the host?
* @param killHost - destroy the host block as well?
*/
public static void destroyMultiBlockStructure(IMultiTileHost host, boolean doDrops, boolean offset, boolean killHost) {
if (host instanceof TileEntity) {
HashMap<IPos3D, String> map = host.getLayoutOfMultiBlock();
if (map != null && !map.isEmpty()) {
World world = ((TileEntity) host).getWorldObj();
int x = ((TileEntity) host).xCoord;
int y = ((TileEntity) host).yCoord;
int z = ((TileEntity) host).zCoord;
Pos center = new Pos(x, y, z);
for (Map.Entry<IPos3D, String> entry : map.entrySet()) {
Pos pos = new Pos(entry.getKey());
if (offset) {
pos = pos.add(center);
}
TileEntity tile = pos.getTileEntity(world);
if (tile instanceof IMultiTile) {
((IMultiTile) tile).setHost(null);
pos.setBlockToAir(world);
}
}
if (doDrops) {
InventoryUtility.dropBlockAsItem(world, x, y, z, killHost);
} else if (killHost) {
world.setBlockToAir(x, y, z);
}
} else {
logger.error("Tile[" + host + "]'s structure map is empty");
}
} else {
logger.error("Tile[" + host + "] is not an instanceof TileEntity");
}
}
use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.
the class MultiBlockHelper method updateStructure.
/**
* Runs a world update on all members of the structure
*
* @param world
* @param host
* @param offset - off set the location data by the center of the host
*/
public static void updateStructure(World world, IMultiTileHost host, boolean offset) {
// TODO junit test
if (!(host instanceof TileEntity)) {
Engine.error("Tile host is not an instance of TileEntity");
}
if (world == null) {
Engine.error("Tile host is not an instance of TileEntity");
}
HashMap<IPos3D, String> map = host.getLayoutOfMultiBlock();
if (map != null && !map.isEmpty()) {
int x = ((TileEntity) host).xCoord;
int y = ((TileEntity) host).yCoord;
int z = ((TileEntity) host).zCoord;
Pos center = new Pos(x, y, z);
for (Map.Entry<IPos3D, String> entry : map.entrySet()) {
Location pos = new Location(world, entry.getKey());
if (offset) {
pos = pos.add(center);
}
pos.markForUpdate();
}
center.markForUpdate(world);
} else {
logger.error("Tile[" + host + "]'s structure map is empty");
}
}
Aggregations