/** * Works out whether the given block resides inside the given chunk. * * Both positions must be given as world position, not local position. In addition, the chunk position must be * given in chunk coordinates, not in block coordinates. * * For example, using chunks of width 32, a block with x coordinate of 33 will be counted as inside a chunk with x * coordinate of 1. * * @param blockWorldPos the block to check for * @param chunkWorldPos the chunk to check in * @return whether the block is inside the chunk */ public static boolean blockInChunk(Vector3i blockWorldPos, Vector3i chunkWorldPos) { return calcChunkPos(blockWorldPos).equals(chunkWorldPos); } }
public void addChunk(Chunk value) { Preconditions.checkNotNull(value, "The parameter 'value' must not be null"); Preconditions.checkArgument(pos.equals(value.getPosition()), "Expected chunk for position {} but got position {} instead", pos, value.getPosition()); purge(); chunks.add(new WeakReference<>(value)); } }
@Override public void onChunkUnloaded(Vector3i chunkCoordinates) { if (renderableRegion.encompasses(chunkCoordinates)) { RenderableChunk chunk; Iterator<RenderableChunk> iterator = chunksInProximityOfCamera.iterator(); while (iterator.hasNext()) { chunk = iterator.next(); if (chunk.getPosition().equals(chunkCoordinates)) { chunk.disposeMesh(); iterator.remove(); break; } } } }
public void setRelevanceDistance(Vector3i distance) { if (!distance.equals(this.relevanceDistance)) { reviewRelevantChunks(distance); this.relevanceDistance.set(distance); this.currentRegion = calculateRegion(); dirty = true; } }
while (nearbyChunks.hasNext()) { chunk = nearbyChunks.next(); if (chunk.getPosition().equals(chunkPosition)) { chunk.disposeMesh(); nearbyChunks.remove();
private static void markAllChunksAsReadyExcludingPosition(final ChunkCache chunkCache, final Vector3i positionToExclude) { chunkCache.getAllChunks().stream() .filter(chunk -> !chunk.getPosition().equals(positionToExclude)) .forEach(c -> when(c.isReady()).thenReturn(true)); }
public ChunkMonitorDisplay setSelectedChunk(Vector3i chunk) { if (selectedChunk == null) { if (chunk != null) { selectedChunk = chunk; updateDisplay(true); fireChunkSelectedEvent(chunk); } } else { if (chunk == null || !selectedChunk.equals(chunk)) { selectedChunk = chunk; updateDisplay(true); fireChunkSelectedEvent(chunk); } } return this; }
public void update() { if (!isValid()) { dirty = false; } else { Vector3i newCenter = calculateCenter(); if (!newCenter.equals(center)) { dirty = true; center.set(newCenter); currentRegion = calculateRegion(); reviewRelevantChunks(relevanceDistance); } } }
private boolean unloadChunkInternal(Vector3i pos) { Chunk chunk = chunkCache.get(pos); if (!chunk.isReady()) { // Chunk hasn't been finished or changed, so just drop it. Iterator<ReadyChunkInfo> infoIterator = sortedReadyChunks.iterator(); while (infoIterator.hasNext()) { ReadyChunkInfo next = infoIterator.next(); if (next.getPos().equals(chunk.getPosition())) { infoIterator.remove(); break; } } return true; } worldEntity.send(new BeforeChunkUnload(pos)); for (ChunkRelevanceRegion region : regions.values()) { region.chunkUnloaded(pos); } storageManager.deactivateChunk(chunk); chunk.dispose(); try { unloadRequestTaskMaster.put(new ChunkUnloadRequest(chunk, this)); } catch (InterruptedException e) { logger.error("Failed to enqueue unload request for {}", chunk.getPosition(), e); } return true; }
if (!newChunkPos.equals(chunkPos) || force || pendingChunks) { Vector3i viewingDistance = config.getRendering().getViewDistance().getChunkDistance(); Region3i viewRegion = Region3i.createFromCenterExtents(newChunkPos, new Vector3i(viewingDistance.x / 2, viewingDistance.y / 2, viewingDistance.z / 2));
@ReceiveEvent(components = {PlayerCharacterComponent.class}) public void checkForBiomeChange(MovedEvent event, EntityRef entity) { final Vector3i newPos = new Vector3i(event.getPosition()); final Vector3i oldPos = new Vector3i(new Vector3f(event.getPosition()).sub(event.getDelta())); if (newPos.equals(oldPos)) { return; } final Biome oldBiome = world.getBiome(oldPos); final Biome newBiome = world.getBiome(newPos); if (!oldBiome.equals(newBiome)) { entity.send(new BiomeChangeEvent(oldBiome, newBiome)); } } }
private void checkBlockEntry(EntityRef entity, Vector3i oldPosition, Vector3i newPosition, float characterHeight) { // TODO: This will only work for tall mobs/players and single block mobs // is this a different position than previously if (!oldPosition.equals(newPosition)) { Biome oldBiome = worldProvider.getBiome(oldPosition); Biome newBiome = worldProvider.getBiome(newPosition); if (oldBiome != newBiome) { entity.send(new OnEnterBiomeEvent(oldPosition, newPosition, oldBiome, newBiome)); } // get the old position's blocks Block[] oldBlocks = new Block[(int) Math.ceil(characterHeight)]; Vector3i currentPosition = new Vector3i(oldPosition); for (int currentHeight = 0; currentHeight < oldBlocks.length; currentHeight++) { oldBlocks[currentHeight] = worldProvider.getBlock(currentPosition); currentPosition.add(0, 1, 0); } // get the new position's blocks Block[] newBlocks = new Block[(int) Math.ceil(characterHeight)]; currentPosition = new Vector3i(newPosition); for (int currentHeight = 0; currentHeight < characterHeight; currentHeight++) { newBlocks[currentHeight] = worldProvider.getBlock(currentPosition); currentPosition.add(0, 1, 0); } for (int i = 0; i < characterHeight; i++) { // send a block enter/leave event for this character entity.send(new OnEnterBlockEvent(oldBlocks[i], newBlocks[i], new Vector3i(0, i, 0))); } } }
if (targetBlockPos.equals(hitInfo.getBlockPosition())) { return false;