Java Code Examples for com.flowpowered.math.vector.Vector2i#getY()

The following examples show how to use com.flowpowered.math.vector.Vector2i#getY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SlicedWorld.java    From BlueMap with MIT License 6 votes vote down vote up
@Override
public boolean isAreaGenerated(Vector2i chunkMin, Vector2i chunkMax) throws IOException {
	if (!isInside(chunkMin) && 
		!isInside(chunkMax) && 
		!isInside(new Vector2i(chunkMin.getX(), chunkMax.getY())) && 
		!isInside(new Vector2i(chunkMax.getX(), chunkMin.getY()))
		) return false;
	
	for (int x = chunkMin.getX(); x <= chunkMax.getX(); x++) {
		for (int z = chunkMin.getY(); z <= chunkMax.getY(); z++) {
			if (!world.isChunkGenerated(new Vector2i(x, z))) return false;
		}
	}
	
	return true;
}
 
Example 2
Source File: HiresModelManager.java    From BlueMap with MIT License 6 votes vote down vote up
/**
 * Returns all tiles that the provided chunks are intersecting
 */
public Collection<Vector2i> getTilesForChunks(Iterable<Vector2i> chunks){
	Set<Vector2i> tiles = new HashSet<>();
	for (Vector2i chunk : chunks) {
		Vector3i minBlockPos = new Vector3i(chunk.getX() * 16, 0, chunk.getY() * 16);
		
		//loop to cover the case that a tile is smaller then a chunk, should normally only add one tile (at 0, 0)
		for (int x = 0; x < 15; x += getTileSize().getX()) {
			for (int z = 0; z < 15; z += getTileSize().getY()) {
				tiles.add(posToTile(minBlockPos.add(x, 0, z)));
			}
		}
		
		tiles.add(posToTile(minBlockPos.add(0, 0, 15)));
		tiles.add(posToTile(minBlockPos.add(15, 0, 0)));
		tiles.add(posToTile(minBlockPos.add(15, 0, 15)));
	}
	
	return tiles;
}
 
Example 3
Source File: FileUtils.java    From BlueMap with MIT License 6 votes vote down vote up
public static File coordsToFile(Path root, Vector2i coords, String fileType){
	String path = "x" + coords.getX() + "z" + coords.getY();
	char[] cs = path.toCharArray();
	List<String> folders = new ArrayList<>();
	String folder = "";
	for (char c : cs){
		folder += c;
		if (c >= '0' && c <= '9'){
			folders.add(folder);
			folder = "";
		}
	}
	String fileName = folders.remove(folders.size() - 1);
	
	Path p = root;
	for (String s : folders){
		p = p.resolve(s);
	}
	
	return p.resolve(fileName + "." + fileType).toFile();
}
 
Example 4
Source File: Region.java    From Nations with MIT License 6 votes vote down vote up
public boolean isInside(Location<World> loc)
{
	Rect extr = extrema.get(loc.getExtent().getUniqueId());
	Vector2i p = new Vector2i(loc.getBlockX(), loc.getBlockZ());
	if (p.getX() < extr.getMinX() || p.getX() > extr.getMaxX() || p.getY() < extr.getMinY() || p.getY() > extr.getMaxY())
	{
		return false;
	}
	for (Rect r : rects)
	{
		if (r.isInside(p))
		{
			return true;
		}
	}
	return false;
}
 
Example 5
Source File: World.java    From BlueMap with MIT License 5 votes vote down vote up
/**
 * Returns true if and only if all chunks in the given range are fully generated and no world-generation or lighting has yet to be done.
 * @param area The area to check
 * @throws IOException 
 */
public default boolean isAreaGenerated(Vector2i chunkMin, Vector2i chunkMax) throws IOException {
	for (int x = chunkMin.getX(); x <= chunkMax.getX(); x++) {
		for (int z = chunkMin.getY(); z <= chunkMax.getY(); z++) {
			if (!isChunkGenerated(new Vector2i(x, z))) return false;
		}
	}
	
	return true;
}
 
Example 6
Source File: MapUpdateHandler.java    From BlueMap with MIT License 5 votes vote down vote up
@Override
public void onChunkFinishedGeneration(UUID world, Vector2i chunkPos) {
	int x = chunkPos.getX();
	int z = chunkPos.getY();
	
	// also update the chunks around, because they might be modified or not rendered yet due to finalizations
	for (int dx = -1; dx <= 1; dx++) {
		for (int dz = -1; dz <= 1; dz++) {
			updateChunk(world, new Vector2i(x + dx, z + dz));
		}
	}
}
 
Example 7
Source File: MapUpdateHandler.java    From BlueMap with MIT License 5 votes vote down vote up
private void updateChunk(UUID world, Vector2i chunkPos) {
	Vector3i min = new Vector3i(chunkPos.getX() * 16, 0, chunkPos.getY() * 16);
	Vector3i max = min.add(15, 255, 15);
	
	Vector3i xmin = new Vector3i(min.getX(), 0, max.getY());
	Vector3i xmax = new Vector3i(max.getX(), 255, min.getY());
	
	//update all corners so we always update all tiles containing this chunk
	synchronized (updateBuffer) {
		updateBlock(world, min);
		updateBlock(world, max);
		updateBlock(world, xmin);
		updateBlock(world, xmax);
	}
}
 
Example 8
Source File: LowresModelManager.java    From BlueMap with MIT License 4 votes vote down vote up
/**
 * Renders all points from the given highres-model onto the lowres-grid
 */
public void render(HiresModel hiresModel) {
	Vector3i min = hiresModel.getBlockMin();
	Vector3i max = hiresModel.getBlockMax();
	Vector3i size = max.sub(min).add(Vector3i.ONE);
	
	Vector2i blocksPerPoint = 
			size
			.toVector2(true)
			.div(pointsPerHiresTile);
	
	Vector2i pointMin = min
			.toVector2(true)
			.toDouble()
			.div(blocksPerPoint.toDouble())
			.floor()
			.toInt();
	
	for (int tx = 0; tx < pointsPerHiresTile.getX(); tx++){
		for (int tz = 0; tz < pointsPerHiresTile.getY(); tz++){
			
			double height = 0;
			
			Vector3d color = Vector3d.ZERO;
			double colorCount = 0;
			
			for (int x = 0; x < blocksPerPoint.getX(); x++){
				for (int z = 0; z < blocksPerPoint.getY(); z++){
					
					int rx = tx * blocksPerPoint.getX() + x + min.getX();
					int rz = tz * blocksPerPoint.getY() + z + min.getZ();
					height += hiresModel.getHeight(rx, rz);
					
					Vector4f c = hiresModel.getColor(rx, rz);
					color = color.add(c.toVector3().toDouble().mul(c.getW()));
					colorCount += c.getW();
				}
			}
			
			if (colorCount > 0) color = color.div(colorCount);
			
			int count = blocksPerPoint.getX() * blocksPerPoint.getY();
			height /= count;
			
			Vector2i point = pointMin.add(tx, tz);
			update(hiresModel.getWorld(), point, (float) height, color.toFloat());
			
		}
	}
}
 
Example 9
Source File: ModelUtils.java    From BlueMap with MIT License 4 votes vote down vote up
/**
 * Creates a plane-grid with alternating face-rotations.
 */
public static Model<Face> makeGrid(Vector2i gridSize){
	Model<Face> m = new Model<Face>();
	
	float y = 0;
	
	for (int x = 0; x < gridSize.getX(); x++){
		for (int z = 0; z < gridSize.getY(); z++){
			
			Vector3f[] p = new Vector3f[]{
				new Vector3f(x    , y, z + 1),
				new Vector3f(x + 1, y, z + 1),
				new Vector3f(x + 1, y, z    ),
				new Vector3f(x    , y, z    ),
			};
			
			Vector2f[] uv = new Vector2f[]{
					new Vector2f(0, 1),
					new Vector2f(1, 1),
					new Vector2f(1, 0),
					new Vector2f(0, 0),
				};
			
			Face f1, f2;
			if (x % 2 == z % 2){
				f1 = new Face(p[0], p[1], p[2], uv[0], uv[1], uv[2], -1);
				f2 = new Face(p[0], p[2], p[3], uv[0], uv[2], uv[3], -1);
			} else {
				f1 = new Face(p[0], p[1], p[3], uv[0], uv[1], uv[3], -1);
				f2 = new Face(p[1], p[2], p[3], uv[1], uv[2], uv[3], -1);
			}
			
			Vector3f color = Vector3f.ZERO;
			
			f1.setC1(color);
			f1.setC2(color);
			f1.setC3(color);

			f2.setC1(color);
			f2.setC2(color);
			f2.setC3(color);
			
			m.addFace(f1);
			m.addFace(f2);
		}
	}
	
	return m;
}
 
Example 10
Source File: Rect.java    From Nations with MIT License 4 votes vote down vote up
public Rect(UUID world, Vector2i point)
{
	this(world, point.getX(), point.getX(), point.getY(), point.getY());
}
 
Example 11
Source File: Rect.java    From Nations with MIT License 4 votes vote down vote up
public boolean isInside(Vector2i point)
{
	return minX <= point.getX() && point.getX() <= maxX && minY <= point.getY() && point.getY() <= maxY;
}
 
Example 12
Source File: Rect.java    From Nations with MIT License 4 votes vote down vote up
public boolean isAdjacent(Vector2i point)
{
	return this.minX - 1 <= point.getX() && point.getX() <= this.maxX + 1 && this.minY - 1 <= point.getY() && point.getY() <= this.maxY + 1;
}