@Override public byte getSunlight(int x, int y, int z) { Vector3i chunkPos = ChunkMath.calcChunkPos(x, y, z); LitChunk chunk = chunkProvider.getChunk(chunkPos); if (chunk != null) { Vector3i blockPos = ChunkMath.calcBlockPos(x, y, z); return chunk.getSunlight(blockPos); } return 0; }
@Override public Block getBlock(int x, int y, int z) { CoreChunk chunk = chunkProvider.getChunk(ChunkMath.calcChunkPosX(x), ChunkMath.calcChunkPosY(y), ChunkMath.calcChunkPosZ(z)); if (chunk != null) { return chunk.getBlock(ChunkMath.calcBlockPosX(x), ChunkMath.calcBlockPosY(y), ChunkMath.calcBlockPosZ(z)); } return unloadedBlock; }
/** * Gets the index of the chunk in {@link #chunks} * * @param blockPos The position of the block in world coordinates * @return The index of the chunk in the array */ private int chunkIndexOf(Vector3i blockPos) { return ChunkMath.calcChunkPosX(blockPos.x, ChunkConstants.POWER_X) - topLeft.x + 3 * (ChunkMath.calcChunkPosY(blockPos.y, ChunkConstants.POWER_Y) - topLeft.y + 3 * (ChunkMath.calcChunkPosZ(blockPos.z, ChunkConstants.POWER_Z) - topLeft.z)); }
public static Vector3i calcBlockPos(int x, int y, int z, Vector3i chunkFilterSize) { return new Vector3i(calcBlockPosX(x, chunkFilterSize.x), calcBlockPosY(y, chunkFilterSize.y), calcBlockPosZ(z, chunkFilterSize.z)); }
/** * The method tells the chunk mesh update manager where the camera is, so that is able to prioritize chunks near the * camera. It stores the values in volatile variables so that the change is visible to the chunk updating threads * immediately. */ public void setCameraPosition(Vector3f cameraPosition) { Vector3i chunkPos = ChunkMath.calcChunkPos(cameraPosition); cameraChunkPosX = chunkPos.x; cameraChunkPosY = chunkPos.y; cameraChunkPosZ = chunkPos.z; }
public static Vector3i calcBlockPos(int x, int y, int z) { return calcBlockPos(x, y, z, ChunkConstants.INNER_CHUNK_POS_FILTER); }
@Override public void setValueAt(Vector3i pos, byte value) { setValueAt(getChunk(pos), ChunkMath.calcBlockPos(pos.x, pos.y, pos.z), value); for (Vector3i affectedChunkPos : ChunkMath.getChunkRegionAroundWorldPos(pos, 1)) { Chunk dirtiedChunk = chunkProvider.getChunk(affectedChunkPos); if (dirtiedChunk != null) { dirtiedChunk.setDirty(true); } } }
@Override public void propagateBetween(LitChunk chunk, LitChunk adjChunk, Side side, boolean propagateExternal) { IndexProvider indexProvider = createIndexProvider(side); Region3i edgeRegion = ChunkMath.getEdgeRegion(Region3i.createFromMinAndSize(Vector3i.zero(), ChunkConstants.CHUNK_SIZE), side); int edgeSize = edgeRegion.size().x * edgeRegion.size().y * edgeRegion.size().z; int[] depth = new int[edgeSize]; propagateSide(chunk, adjChunk, side, indexProvider, edgeRegion, depth); propagateDepth(adjChunk, side, propagateExternal, indexProvider, edgeRegion, depth); }
public static int calcChunkPosX(int x) { return calcChunkPosX(x, ChunkConstants.CHUNK_POWER.x); } public static int calcChunkPosY(int y) {
public static int calcBlockPosY(int blockY) { return calcBlockPosY(blockY, ChunkConstants.INNER_CHUNK_POS_FILTER.y); }
public static int calcBlockPosX(int blockX) { return calcBlockPosX(blockX, ChunkConstants.INNER_CHUNK_POS_FILTER.x); }
public static int calcBlockPosZ(int blockZ) { return calcBlockPosZ(blockZ, ChunkConstants.INNER_CHUNK_POS_FILTER.z); }
public static Vector3i calcChunkPos(int x, int y, int z) { return calcChunkPos(x, y, z, ChunkConstants.CHUNK_POWER); }
public static Vector3i calcBlockPos(Vector3i worldPos) { return calcBlockPos(worldPos.x, worldPos.y, worldPos.z, ChunkConstants.INNER_CHUNK_POS_FILTER); }
public static Vector3i calcChunkPos(int x, int y, int z, Vector3i chunkPower) { return new Vector3i(calcChunkPosX(x, chunkPower.x), calcChunkPosY(y, chunkPower.y), calcChunkPosZ(z, chunkPower.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)); }
@Test public void testGetEdgeRegion() { Region3i region = Region3i.createFromMinAndSize(new Vector3i(16, 0, 16), new Vector3i(16, 128, 16)); assertEquals(Region3i.createFromMinMax(new Vector3i(16, 0, 16), new Vector3i(16, 127, 31)), ChunkMath.getEdgeRegion(region, Side.LEFT)); }
@Override public byte getLight(int x, int y, int z) { Vector3i chunkPos = ChunkMath.calcChunkPos(x, y, z); LitChunk chunk = chunkProvider.getChunk(chunkPos); if (chunk != null) { Vector3i blockPos = ChunkMath.calcBlockPos(x, y, z); return chunk.getLight(blockPos); } return 0; }
public static Vector3i calcChunkPos(Vector3i pos) { return calcChunkPos(pos.x, pos.y, pos.z); }
@Override public byte getValueAt(Vector3i pos) { Chunk chunk = chunks[chunkIndexOf(pos)]; if (chunk != null) { return rules.getValue(chunk, ChunkMath.calcBlockPos(pos)); } return UNAVAILABLE; }