/** * 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; }
@Override public boolean isRegionRelevant(Region3i region) { for (Vector3i chunkPos : ChunkMath.calcChunkPos(region)) { if (!chunkProvider.isChunkReady(chunkPos)) { return false; } } return true; }
/** * Get's the chunk for a given position * * @param pos The position in the world * @return The chunk for that position */ private Chunk getChunk(Vector3i pos) { return chunkProvider.getChunk(ChunkMath.calcChunkPos(pos)); }
@Override public String get() { Vector3f pos = localPlayer.getPosition(); Vector3i chunkPos = ChunkMath.calcChunkPos((int) pos.x, (int) pos.y, (int) pos.z); Vector3f rotation = localPlayer.getViewDirection(); Vector3f cameraPos = localPlayer.getViewPosition(); return String.format(Locale.US, "Pos (%.2f, %.2f, %.2f), Chunk (%d, %d, %d), Eye (%.2f, %.2f, %.2f), Rot (%.2f, %.2f, %.2f)", pos.x, pos.y, pos.z, chunkPos.x, chunkPos.y, chunkPos.z, cameraPos.x, cameraPos.y, cameraPos.z, rotation.x, rotation.y, rotation.z); } });
public static Region3i getChunkRegionAroundWorldPos(Vector3i pos, int extent) { Vector3i minPos = new Vector3i(-extent, -extent, -extent); minPos.add(pos); Vector3i maxPos = new Vector3i(extent, extent, extent); maxPos.add(pos); Vector3i minChunk = calcChunkPos(minPos); Vector3i maxChunk = calcChunkPos(maxPos); return Region3i.createFromMinMax(minChunk, maxChunk); }
@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; }
@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 getBlockAt(Vector3i pos) { CoreChunk chunk = chunkProvider.getChunk(ChunkMath.calcChunkPos(pos)); if (chunk != null) { return chunk.getBlock(ChunkMath.calcBlockPos(pos)); } return null; }
private int score(Vector3i chunk) { Vector3i playerChunk = ChunkMath.calcChunkPos(new Vector3i(localPlayer.getPosition(), RoundingMode.HALF_UP)); return playerChunk.distanceSquared(chunk); } }
private Vector3i calculateCenter() { LocationComponent loc = entity.getComponent(LocationComponent.class); if (loc != null) { return ChunkMath.calcChunkPos(loc.getWorldPosition()); } return new Vector3i(); }
private Vector3i calcPlayerChunkPos() { final LocalPlayer p = CoreRegistry.get(LocalPlayer.class); if (p != null) { return ChunkMath.calcChunkPos(new Vector3i(p.getPosition())); } return null; }
@Override public byte getTotalLight(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 (byte) Math.max(chunk.getSunlight(blockPos), chunk.getLight(blockPos)); } return 0; }
@Override public void onBlockChanged(Vector3i pos, Block newBlock, Block originalBlock) { Vector3i chunkPos = ChunkMath.calcChunkPos(pos); if (relevantChunks.contains(chunkPos)) { queuedOutgoingBlockChanges.add(NetData.BlockChangeMessage.newBuilder() .setPos(NetMessageUtil.convert(pos)) .setNewBlock(newBlock.getId()) .build()); } }
@Override public void onExtraDataChanged(int i, Vector3i pos, int newData, int oldData) { Vector3i chunkPos = ChunkMath.calcChunkPos(pos); if (relevantChunks.contains(chunkPos)) { queuedOutgoingExtraDataChanges.add(NetData.ExtraDataChangeMessage.newBuilder() .setIndex(i) .setPos(NetMessageUtil.convert(pos)) .setNewData(newData) .build()); } }
@Override public void onBiomeChanged(Vector3i pos, Biome newBiome, Biome originalBiome) { Vector3i chunkPos = ChunkMath.calcChunkPos(pos); if (relevantChunks.contains(chunkPos)) { queuedOutgoingBiomeChanges.add(NetData.BiomeChangeMessage.newBuilder() .setPos(NetMessageUtil.convert(pos)) .setNewBiome(biomeManager.getBiomeShortId(newBiome)) .build()); } }
@Override public Biome getBiome(Vector3i pos) { Vector3i chunkPos = ChunkMath.calcChunkPos(pos); CoreChunk chunk = chunkProvider.getChunk(chunkPos); if (chunk != null) { Vector3i blockPos = ChunkMath.calcBlockPos(pos); return chunk.getBiome(blockPos.x, blockPos.y, blockPos.z); } return BiomeManager.getUnknownBiome(); }
@Override public void setDirtyAround(Region3i region) { Vector3i minPos = new Vector3i(region.min()); minPos.sub(1, 1, 1); Vector3i maxPos = new Vector3i(region.max()); maxPos.add(1, 1, 1); Vector3i minChunk = ChunkMath.calcChunkPos(minPos, chunkPower); Vector3i maxChunk = ChunkMath.calcChunkPos(maxPos, chunkPower); for (Vector3i pos : Region3i.createFromMinMax(minChunk, maxChunk)) { chunks[pos.x + offset.x + chunkRegion.size().x * (pos.z + offset.z)].setDirty(true); } }
public ChunkRelevanceRegion(EntityRef entity, Vector3i relevanceDistance) { this.entity = entity; this.relevanceDistance.set(relevanceDistance); LocationComponent loc = entity.getComponent(LocationComponent.class); if (loc == null) { dirty = false; } else { center.set(ChunkMath.calcChunkPos(loc.getWorldPosition())); currentRegion = calculateRegion(); dirty = true; } }
private Region3i calculateRegion() { LocationComponent loc = entity.getComponent(LocationComponent.class); if (loc != null) { Vector3i extents = new Vector3i(relevanceDistance.x / 2, relevanceDistance.y / 2, relevanceDistance.z / 2); return Region3i.createFromCenterExtents(ChunkMath.calcChunkPos(loc.getWorldPosition()), extents); } return Region3i.empty(); }
static Region3i getChunkRegionAbove(Vector3f location) { Vector3i charecterPos = new Vector3i(location); Vector3i chunkAboveCharacter = ChunkMath.calcChunkPos(charecterPos); chunkAboveCharacter.addY(1); Vector3i chunkRelativePos = ChunkMath.calcBlockPos(charecterPos); Vector3i characterChunkOriginPos = new Vector3i(charecterPos); characterChunkOriginPos.sub(chunkRelativePos); Vector3i chunkAboveOrigin = new Vector3i(characterChunkOriginPos); chunkAboveOrigin.addY(ChunkConstants.CHUNK_SIZE.getY()); return ChunkConstants.CHUNK_REGION.move(chunkAboveOrigin); }