com.flowpowered.math.vector.Vector2i Java Examples
The following examples show how to use
com.flowpowered.math.vector.Vector2i.
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: DataHandler.java From Nations with MIT License | 6 votes |
public static void addToWorldChunks(Nation nation) { for (Rect r : nation.getRegion().getRects()) { if (!worldChunks.containsKey(r.getWorld())) { worldChunks.put(r.getWorld(), new Hashtable<Vector2i, ArrayList<Nation>>()); } Hashtable<Vector2i, ArrayList<Nation>> chunks = worldChunks.get(r.getWorld()); for (int i = IntMath.divide(r.getMinX(), 16, RoundingMode.FLOOR); i < IntMath.divide(r.getMaxX(), 16, RoundingMode.FLOOR) + 1; i++) { for (int j = IntMath.divide(r.getMinY(), 16, RoundingMode.FLOOR); j < IntMath.divide(r.getMaxY(), 16, RoundingMode.FLOOR) + 1; j++) { Vector2i vect = new Vector2i(i, j); if (!chunks.containsKey(vect)) { chunks.put(vect, new ArrayList<Nation>()); } if (!chunks.get(vect).contains(nation)) { chunks.get(vect).add(nation); } } } } }
Example #2
Source File: MCAWorld.java From BlueMap with MIT License | 6 votes |
@Override public Block getBlock(Vector3i pos) { if (pos.getY() < getMinY()) { return new Block(this, BlockState.AIR, LightData.ZERO, Biome.DEFAULT, BlockProperties.TRANSPARENT, pos); } if (pos.getY() > getMaxY()) { return new Block(this, BlockState.AIR, LightData.SKY, Biome.DEFAULT, BlockProperties.TRANSPARENT, pos); } try { Vector2i chunkPos = blockToChunk(pos); Chunk chunk = getChunk(chunkPos); BlockState blockState = getExtendedBlockState(chunk, pos); LightData lightData = chunk.getLightData(pos); Biome biome = chunk.getBiome(pos); BlockProperties properties = blockPropertiesMapper.get(blockState); return new Block(this, blockState, lightData, biome, properties, pos); } catch (IOException ex) { throw new RuntimeException("Unexpected IO-Exception trying to read world-data!", ex); } }
Example #3
Source File: WebSettings.java From BlueMap with MIT License | 6 votes |
public void setFrom(TileRenderer tileRenderer, String mapId) { Vector2i hiresTileSize = tileRenderer.getHiresModelManager().getTileSize(); Vector2i gridOrigin = tileRenderer.getHiresModelManager().getGridOrigin(); Vector2i lowresTileSize = tileRenderer.getLowresModelManager().getTileSize(); Vector2i lowresPointsPerHiresTile = tileRenderer.getLowresModelManager().getPointsPerHiresTile(); set(hiresTileSize.getX(), "maps", mapId, "hires", "tileSize", "x"); set(hiresTileSize.getY(), "maps", mapId, "hires", "tileSize", "z"); set(1, "maps", mapId, "hires", "scale", "x"); set(1, "maps", mapId, "hires", "scale", "z"); set(gridOrigin.getX(), "maps", mapId, "hires", "translate", "x"); set(gridOrigin.getY(), "maps", mapId, "hires", "translate", "z"); Vector2i pointSize = hiresTileSize.div(lowresPointsPerHiresTile); Vector2i tileSize = pointSize.mul(lowresTileSize); set(tileSize.getX(), "maps", mapId, "lowres", "tileSize", "x"); set(tileSize.getY(), "maps", mapId, "lowres", "tileSize", "z"); set(pointSize.getX(), "maps", mapId, "lowres", "scale", "x"); set(pointSize.getY(), "maps", mapId, "lowres", "scale", "z"); set(pointSize.getX() / 2, "maps", mapId, "lowres", "translate", "x"); set(pointSize.getY() / 2, "maps", mapId, "lowres", "translate", "z"); }
Example #4
Source File: Region.java From Nations with MIT License | 6 votes |
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: RenderTask.java From BlueMap with MIT License | 6 votes |
public void write(DataOutputStream out) throws IOException { synchronized (renderTiles) { pause(); out.writeUTF(name); out.writeUTF(mapType.getId()); out.writeLong(additionalRunTime); out.writeInt(renderedTiles); out.writeInt(renderTiles.size()); for (Vector2i tile : renderTiles) { out.writeInt(tile.getX()); out.writeInt(tile.getY()); } } }
Example #6
Source File: SlicedWorld.java From BlueMap with MIT License | 6 votes |
@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 #7
Source File: MCAWorld.java From BlueMap with MIT License | 5 votes |
public Chunk getChunk(Vector2i chunkPos) throws IOException { try { Chunk chunk = CHUNK_CACHE.get(new WorldChunkHash(this, chunkPos), () -> this.loadChunk(chunkPos)); return chunk; } catch (UncheckedExecutionException | ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof IOException) { throw (IOException) cause; } else throw new IOException(cause); } }
Example #8
Source File: MCAWorld.java From BlueMap with MIT License | 5 votes |
private Chunk loadChunk(Vector2i chunkPos) throws IOException { Vector2i regionPos = chunkToRegion(chunkPos); Path regionPath = getMCAFilePath(regionPos); try (RandomAccessFile raf = new RandomAccessFile(regionPath.toFile(), "r")) { int xzChunk = Math.floorMod(chunkPos.getY(), 32) * 32 + Math.floorMod(chunkPos.getX(), 32); raf.seek(xzChunk * 4); int offset = raf.read() << 16; offset |= (raf.read() & 0xFF) << 8; offset |= raf.read() & 0xFF; offset *= 4096; int size = raf.readByte() * 4096; if (size == 0) { return Chunk.empty(this, chunkPos); } raf.seek(offset + 4); // +4 skip chunk size byte compressionTypeByte = raf.readByte(); CompressionType compressionType = CompressionType.getFromID(compressionTypeByte); if (compressionType == null) { throw new IOException("invalid compression type " + compressionTypeByte); } DataInputStream dis = new DataInputStream(new BufferedInputStream(compressionType.decompress(new FileInputStream(raf.getFD())))); Tag<?> tag = Tag.deserialize(dis, Tag.DEFAULT_MAX_DEPTH); if (tag instanceof CompoundTag) { return Chunk.create(this, (CompoundTag) tag, ignoreMissingLightData); } else { throw new IOException("invalid data tag: " + (tag == null ? "null" : tag.getClass().getName())); } } }
Example #9
Source File: RenderTask.java From BlueMap with MIT License | 5 votes |
public RenderTicket poll() { synchronized (renderTiles) { Vector2i tile = renderTiles.poll(); if (tile != null) { renderedTiles++; if (firstTileTime < 0) firstTileTime = System.currentTimeMillis(); return new RenderTicket(mapType, tile); } else { return null; } } }
Example #10
Source File: World.java From BlueMap with MIT License | 5 votes |
/** * 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 #11
Source File: Region.java From Nations with MIT License | 5 votes |
public float distance(Location<World> loc) { float dist = Float.MAX_VALUE; for (Rect r : rects) { if (loc.getExtent().getUniqueId().equals(r.getWorld())) { dist = Math.min(dist, r.distance(new Vector2i(loc.getBlockX(), loc.getBlockZ()))); } } return dist; }
Example #12
Source File: CommandHelper.java From BlueMap with MIT License | 5 votes |
public void createMapRenderTask(CommandSource source, MapType map, Vector2i center, long blockRadius) { source.sendMessage(Text.of(TextColor.GOLD, "Creating render-task for map: " + map.getId())); source.sendMessage(Text.of(TextColor.GOLD, "Collecting chunks...")); String taskName = "world-render"; Predicate<Vector2i> filter; if (center == null || blockRadius < 0) { filter = c -> true; } else { filter = c -> c.mul(16).distanceSquared(center) <= blockRadius * blockRadius; taskName = "radius-render"; } Collection<Vector2i> chunks = map.getWorld().getChunkList(filter); source.sendMessage(Text.of(TextColor.GREEN, chunks.size() + " chunks found!")); source.sendMessage(Text.of(TextColor.GOLD, "Collecting tiles...")); HiresModelManager hmm = map.getTileRenderer().getHiresModelManager(); Collection<Vector2i> tiles = hmm.getTilesForChunks(chunks); RenderTask task = new RenderTask(taskName, map); task.addTiles(tiles); task.optimizeQueue(); plugin.getRenderManager().addRenderTask(task); source.sendMessage(Text.of(TextColor.GREEN, tiles.size() + " tiles found! Task created.")); }
Example #13
Source File: MapUpdateHandler.java From BlueMap with MIT License | 5 votes |
@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 #14
Source File: RenderTask.java From BlueMap with MIT License | 5 votes |
public void optimizeQueue() { //Find a good grid size to match the MCAWorlds chunk-cache size of 500 Vector2d sortGridSize = new Vector2d(20, 20).div(mapType.getTileRenderer().getHiresModelManager().getTileSize().toDouble().div(16)).ceil().max(1, 1); synchronized (renderTiles) { Vector2i[] array = renderTiles.toArray(new Vector2i[renderTiles.size()]); Arrays.sort(array, (v1, v2) -> { Vector2i v1SortGridPos = v1.toDouble().div(sortGridSize).floor().toInt(); Vector2i v2SortGridPos = v2.toDouble().div(sortGridSize).floor().toInt(); if (v1SortGridPos != v2SortGridPos){ int v1Dist = v1SortGridPos.distanceSquared(Vector2i.ZERO); int v2Dist = v2SortGridPos.distanceSquared(Vector2i.ZERO); if (v1Dist < v2Dist) return -1; if (v1Dist > v2Dist) return 1; if (v1SortGridPos.getY() < v2SortGridPos.getY()) return -1; if (v1SortGridPos.getY() > v2SortGridPos.getY()) return 1; if (v1SortGridPos.getX() < v2SortGridPos.getX()) return -1; if (v1SortGridPos.getX() > v2SortGridPos.getX()) return 1; } if (v1.getY() < v2.getY()) return -1; if (v1.getY() > v2.getY()) return 1; if (v1.getX() < v2.getX()) return -1; if (v1.getX() > v2.getX()) return 1; return 0; }); renderTiles.clear(); for (Vector2i tile : array) { renderTiles.add(tile); } } }
Example #15
Source File: MapUpdateHandler.java From BlueMap with MIT License | 5 votes |
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 #16
Source File: VersionHelper7.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Override public Inventory newInventory(int size, String name) { return Inventory.builder().of(InventoryArchetypes.DOUBLE_CHEST) .property(InventoryDimension.of(new Vector2i(9, size / 9))) .property(InventoryTitle.of(RedProtect.get().getUtil().toText(name))) .build(RedProtect.get().container); }
Example #17
Source File: RenderManager.java From BlueMap with MIT License | 5 votes |
public void readState(DataInputStream in, Collection<MapType> mapTypes) throws IOException { //read renderTickets int mapCount = in.readInt(); for (int i = 0; i < mapCount; i++) { String mapId = in.readUTF(); MapType mapType = null; for (MapType map : mapTypes) { if (map.getId().equals(mapId)) { mapType = map; break; } } if (mapType == null) { Logger.global.logWarning("Some render-tickets can not be loaded because the map (id: '" + mapId + "') does not exist anymore. They will be discarded."); } int tileCount = in.readInt(); List<Vector2i> tiles = new ArrayList<>(); for (int j = 0; j < tileCount; j++) { int x = in.readInt(); int y = in.readInt(); Vector2i tile = new Vector2i(x, y); tiles.add(tile); } createTickets(mapType, tiles); } //read tasks int taskCount = in.readInt(); for (int i = 0; i < taskCount; i++) { try { RenderTask task = RenderTask.read(in, mapTypes); addRenderTask(task); } catch (IOException ex) { Logger.global.logWarning("A render-task can not be loaded. It will be discared. (Error message: " + ex.toString() + ")"); } } }
Example #18
Source File: Nation.java From Nations with MIT License | 5 votes |
public Zone getZone(Location<World> loc) { Vector2i p = new Vector2i(loc.getBlockX(), loc.getBlockZ()); for (Zone zone : zones.values()) { if (zone.getRect().isInside(p)) { return zone; } } return null; }
Example #19
Source File: LowresModelManager.java From BlueMap with MIT License | 5 votes |
private Vector2i pointToTile(Vector2i point){ return point .toDouble() .div(gridSize.toDouble()) .floor() .toInt(); }
Example #20
Source File: MCAWorld.java From BlueMap with MIT License | 5 votes |
@Override public Biome getBiome(Vector3i pos) { try { Vector2i chunkPos = blockToChunk(pos); Chunk chunk = getChunk(chunkPos); return chunk.getBiome(pos); } catch (IOException ex) { throw new RuntimeException("Unexpected IO-Exception trying to read world-data!", ex); } }
Example #21
Source File: MCAWorld.java From BlueMap with MIT License | 5 votes |
public BlockState getBlockState(Vector3i pos) { try { Vector2i chunkPos = blockToChunk(pos); Chunk chunk = getChunk(chunkPos); return chunk.getBlockState(pos); } catch (Exception ex) { return BlockState.MISSING; } }
Example #22
Source File: BlockColorCalculator.java From BlueMap with MIT License | 5 votes |
private Vector3f getColorFromMap(Biome biome, int blocksAboveSeaLevel, BufferedImage map){ Vector2i pixel = getColorMapPosition(biome, blocksAboveSeaLevel).mul(map.getWidth(), map.getHeight()).floor().toInt(); int cValue = map.getRGB(GenericMath.clamp(pixel.getX(), 0, map.getWidth() - 1), GenericMath.clamp(pixel.getY(), 0, map.getHeight() - 1)); Color color = new Color(cValue, false); return new Vector3f(color.getRed(), color.getGreen(), color.getBlue()).div(0xff); }
Example #23
Source File: HiresModelManager.java From BlueMap with MIT License | 5 votes |
/** * Converts a block-position to a map-tile-coordinate */ public Vector2i posToTile(Vector3d pos){ pos = pos.sub(new Vector3d(gridOrigin.getX(), 0.0, gridOrigin.getY())); return Vector2i.from( (int) Math.floor(pos.getX() / getTileSize().getX()), (int) Math.floor(pos.getZ() / getTileSize().getY()) ); }
Example #24
Source File: LowresModel.java From BlueMap with MIT License | 5 votes |
public LowresModel(UUID world, Vector2i tilePos, Vector2i gridSize) { this( world, tilePos, ModelUtils.makeGrid(gridSize).toBufferGeometry() ); }
Example #25
Source File: LowresModel.java From BlueMap with MIT License | 5 votes |
public LowresModel(UUID world, Vector2i tilePos, BufferGeometry model) { this.world = world; this.tilePos = tilePos; this.model = model; this.changes = new ConcurrentHashMap<>(); this.hasUnsavedChanges = true; }
Example #26
Source File: VersionHelper8.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Override public Inventory newInventory(int size, String name) { return Inventory.builder().of(InventoryArchetypes.DOUBLE_CHEST) .property(InventoryDimension.of(new Vector2i(9, size / 9))) .property(InventoryTitle.of(RedProtect.get().getUtil().toText(name))) .build(RedProtect.get().container); }
Example #27
Source File: POIMarkerImpl.java From BlueMap with MIT License | 5 votes |
public POIMarkerImpl(String id, BlueMapMap map, Vector3d position) { super(id, map, position); this.iconAddress = "assets/poi.svg"; this.anchor = new Vector2i(25, 45); this.hasUnsavedChanges = true; }
Example #28
Source File: HiresModel.java From BlueMap with MIT License | 5 votes |
public HiresModel(UUID world, Vector2i tile, Vector3i blockMin, Vector3i blockMax) { this.world = world; this.tile = tile; this.blockMin = blockMin; this.blockMax = blockMax; this.blockSize = blockMax.sub(blockMin).add(Vector3i.ONE); heights = new int[blockSize.getX()][blockSize.getZ()]; colors = new Vector4f[blockSize.getX()][blockSize.getZ()]; }
Example #29
Source File: Chunk.java From BlueMap with MIT License | 5 votes |
protected Chunk(MCAWorld world, CompoundTag chunkTag) { this.world = world; CompoundTag levelData = chunkTag.getCompoundTag("Level"); chunkPos = new Vector2i( levelData.getInt("xPos"), levelData.getInt("zPos") ); dataVersion = chunkTag.getInt("DataVersion"); }
Example #30
Source File: Region.java From Nations with MIT License | 5 votes |
public boolean isAdjacent(Vector2i point) { for (Rect r : rects) { if (r.isAdjacent(point)) { return true; } } return false; }