use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class RemoteChunkProvider method checkForUnload.
private void checkForUnload() {
List<Vector3ic> positions = Lists.newArrayListWithCapacity(invalidateChunks.size());
invalidateChunks.drainTo(positions);
for (Vector3ic pos : positions) {
Chunk removed = chunkCache.remove(pos);
if (removed != null && !removed.isReady()) {
worldEntity.send(new BeforeChunkUnload(pos));
removed.dispose();
}
}
}
use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class RemoteChunkProvider method getSubview.
@Override
public ChunkViewCore getSubview(BlockRegionc region, Vector3ic offset) {
Chunk[] chunks = new Chunk[region.getSizeX() * region.getSizeY() * region.getSizeZ()];
for (Vector3ic chunkPos : region) {
Chunk chunk = chunkCache.get(chunkPos);
int index = (chunkPos.x() - region.minX()) + region.getSizeX() * ((chunkPos.z() - region.minZ()) + region.getSizeZ() * (chunkPos.y() - region.minY()));
chunks[index] = chunk;
}
return new ChunkViewCoreImpl(chunks, region, offset, blockManager.getBlock(BlockManager.AIR_ID));
}
use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class ChunkProcessingPipeline method processChunkInfo.
private void processChunkInfo(ChunkProcessingInfo info) {
if (info.getChunkTask() == null) {
return;
}
if (info.getCurrentFuture() != null) {
return;
}
ChunkTask chunkTask = info.getChunkTask();
List<Vector3ic> requirements = chunkTask.getRequirements();
List<Chunk> requiredChunks = Lists.newArrayListWithCapacity(requirements.size());
for (Vector3ic pos : requirements) {
Chunk chunk = getChunkBy(info.getChunkTaskProvider(), pos);
if (chunk != null) {
requiredChunks.add(chunk);
} else {
return;
}
}
info.setCurrentFuture(runTask(chunkTask, requiredChunks));
}
use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class EntityAwareWorldProvider method setBlocks.
// SetBlocks, not SetBlock, is currently triggered by the engine whenever a player places a block.
// This allows for several useful features, such as quickly synchronizing placement across networks.
// However, this means that even if only one block is placed, this is the method being called.
// It must be overridden here to allow an OnChangedBlock event to be properly sent for placed blocks.
@Override
public Map<Vector3ic, Block> setBlocks(Map<? extends Vector3ic, Block> blocks) {
if (GameThread.isCurrentThread()) {
Map<Vector3ic, Block> oldBlocks = super.setBlocks(blocks);
for (Vector3ic vec : oldBlocks.keySet()) {
if (oldBlocks.get(vec) != null) {
EntityRef blockEntity = getBlockEntityAt(vec);
// check for components to be retained when updating the block entity
final Set<Class<? extends Component>> retainComponents = Optional.ofNullable(blockEntity.getComponent(RetainComponentsComponent.class)).map(retainComponentsComponent -> retainComponentsComponent.components).orElse(Collections.emptySet());
updateBlockEntity(blockEntity, vec, oldBlocks.get(vec), blocks.get(vec), false, retainComponents);
}
}
return oldBlocks;
}
return null;
}
use of org.joml.Vector3ic in project Terasology by MovingBlocks.
the class EntityAwareWorldProvider method onBlockRegionChanged.
@ReceiveEvent(components = BlockRegionComponent.class)
public void onBlockRegionChanged(OnChangedComponent event, EntityRef entity) {
BlockRegion oldRegion = blockRegions.get(entity);
for (Vector3ic pos : oldRegion) {
blockRegionLookup.remove(pos);
}
BlockRegionComponent regionComp = entity.getComponent(BlockRegionComponent.class);
blockRegions.put(entity, regionComp.region);
for (Vector3ic pos : regionComp.region) {
blockRegionLookup.put(new Vector3i(pos), entity);
}
}
Aggregations