public void setBlockAt(Vector3i pos, Block block) { if (!relevantRegion.encompasses(pos)) { throw new IllegalArgumentException("Position out of bounds: " + pos); } blockData.put(pos, block); } }
@Override public Block getBlockAt(Vector3i pos) { if (!relevantRegion.encompasses(pos)) { throw new IllegalArgumentException("Position out of bounds: " + pos); } Block result = blockData.get(pos); if (result == null) { return defaultBlock; } return result; }
private void updateNext() { while (innerIterator.hasNext()) { next = innerIterator.next(); if (!other.encompasses(next)) { return; } } next = null; }
@Override public byte getValueAt(Vector3i pos) { if (ChunkConstants.CHUNK_REGION.encompasses(pos)) { return rules.getValue(chunk, pos); } return UNAVAILABLE; }
/** * @throws IllegalArgumentException if not within bounds */ protected void checkWorldCoords(int x, int y, int z) { if (!worldRegion.encompasses(x, y, z)) { String text = "Out of bounds: (%d, %d, %d) for region %s"; String msg = String.format(text, x, y, z, worldRegion.toString()); throw new IllegalArgumentException(msg); } }
@Override public byte getValueAt(Vector3i pos) { if (!relevantRegion.encompasses(pos)) { return UNAVAILABLE; } return lightData.get(pos); }
/** * Checks if the position is within the boundaries of the chunk represented by this class * * @param pos The position to check, in world coordinates */ public boolean isInBounds(Vector3i pos) { return chunkView.getWorldRegion().encompasses(pos); } }
protected void safelySetBlock(CoreChunk chunk, int x, int y, int z, Block block) { if (ChunkConstants.CHUNK_REGION.encompasses(x, y, z)) { chunk.setBlock(x, y, z, block); } } }
@Override public void onChunkLoaded(Vector3i chunkCoordinates) { if (renderableRegion.encompasses(chunkCoordinates)) { Chunk chunk = chunkProvider.getChunk(chunkCoordinates); if (chunk != null) { chunksInProximityOfCamera.add(chunk); Collections.sort(chunksInProximityOfCamera, new ChunkFrontToBackComparator()); } else { logger.warn("Warning: onChunkLoaded called for a null chunk!"); } } }
private void reviewRelevantChunks(Vector3i distance) { Vector3i extents = new Vector3i(distance.x / 2, distance.y / 2, distance.z / 2); Region3i retainRegion = Region3i.createFromCenterExtents(center, extents); Iterator<Vector3i> iter = relevantChunks.iterator(); while (iter.hasNext()) { Vector3i pos = iter.next(); if (!retainRegion.encompasses(pos)) { sendChunkIrrelevant(pos); iter.remove(); } } }
@Override public void setBiome(int blockX, int blockY, int blockZ, Biome biome) { if (blockRegion.encompasses(blockX, blockY, blockZ)) { int chunkIndex = relChunkIndex(blockX, blockY, blockZ); Vector3i pos = ChunkMath.calcBlockPos(blockX, blockY, blockZ, chunkFilterSize); chunks[chunkIndex].setBiome(pos.x, pos.y, pos.z, biome); } else { logger.warn("Attempt to modify biome outside of the view"); } }
@Override public void setLight(int blockX, int blockY, int blockZ, byte light) { if (blockRegion.encompasses(blockX, blockY, blockZ)) { int chunkIndex = relChunkIndex(blockX, blockY, blockZ); chunks[chunkIndex].setLight(ChunkMath.calcBlockPos(blockX, blockY, blockZ, chunkFilterSize), light); } else { logger.warn("Attempted to set light at a position not encompassed by the view"); } }
@Override public void setSunlight(int blockX, int blockY, int blockZ, byte light) { if (blockRegion.encompasses(blockX, blockY, blockZ)) { int chunkIndex = relChunkIndex(blockX, blockY, blockZ); chunks[chunkIndex].setSunlight(ChunkMath.calcBlockPos(blockX, blockY, blockZ, chunkFilterSize), light); } else { throw new IllegalStateException("Attempted to modify sunlight though an unlocked view"); } }
@Override public void setExtraData(int index, int blockX, int blockY, int blockZ, int value) { if (blockRegion.encompasses(blockX, blockY, blockZ)) { int chunkIndex = relChunkIndex(blockX, blockY, blockZ); chunks[chunkIndex].setExtraData(index, ChunkMath.calcBlockPos(blockX, blockY, blockZ, chunkFilterSize), value); } else { throw new IllegalStateException("Attempted to modify extra data though an unlocked view"); } }
/** * @param pos * @return Whether this region includes pos */ public boolean encompasses(BaseVector3i pos) { return encompasses(pos.getX(), pos.getY(), pos.getZ()); }
@Override public int getExtraData(int index, int blockX, int blockY, int blockZ) { if (!blockRegion.encompasses(blockX, blockY, blockZ)) { return 0; } int chunkIndex = relChunkIndex(blockX, blockY, blockZ); return chunks[chunkIndex].getExtraData(index, ChunkMath.calcBlockPos(blockX, blockY, blockZ, chunkFilterSize)); }
@Override public byte getSunlight(int blockX, int blockY, int blockZ) { if (!blockRegion.encompasses(blockX, blockY, blockZ)) { return 0; } int chunkIndex = relChunkIndex(blockX, blockY, blockZ); return chunks[chunkIndex].getSunlight(ChunkMath.calcBlockPos(blockX, blockY, blockZ, chunkFilterSize)); }
@Override public byte getLight(int blockX, int blockY, int blockZ) { if (!blockRegion.encompasses(blockX, blockY, blockZ)) { return 0; } int chunkIndex = relChunkIndex(blockX, blockY, blockZ); return chunks[chunkIndex].getLight(ChunkMath.calcBlockPos(blockX, blockY, blockZ, chunkFilterSize)); }
@Override public Biome getBiome(int blockX, int blockY, int blockZ) { if (!blockRegion.encompasses(blockX, blockY, blockZ)) { return BiomeManager.getUnknownBiome(); } int chunkIndex = relChunkIndex(blockX, blockY, blockZ); Vector3i blockPos = ChunkMath.calcBlockPos(blockX, blockY, blockZ, chunkFilterSize); return chunks[chunkIndex].getBiome(blockPos.x, blockPos.y, blockPos.z); }
@Override public Block getBlock(int blockX, int blockY, int blockZ) { if (!blockRegion.encompasses(blockX, blockY, blockZ)) { return defaultBlock; } int chunkIndex = relChunkIndex(blockX, blockY, blockZ); return chunks[chunkIndex].getBlock( ChunkMath.calcBlockPosX(blockX, chunkFilterSize.x), ChunkMath.calcBlockPosY(blockY, chunkFilterSize.y), ChunkMath.calcBlockPosZ(blockZ, chunkFilterSize.z)); }