Search in sources :

Example 76 with Vector3ic

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();
        }
    }
}
Also used : BeforeChunkUnload(org.terasology.engine.world.chunks.event.BeforeChunkUnload) Vector3ic(org.joml.Vector3ic) Chunk(org.terasology.engine.world.chunks.Chunk)

Example 77 with Vector3ic

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));
}
Also used : ChunkViewCoreImpl(org.terasology.engine.world.internal.ChunkViewCoreImpl) Vector3ic(org.joml.Vector3ic) Chunk(org.terasology.engine.world.chunks.Chunk)

Example 78 with Vector3ic

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));
}
Also used : Vector3ic(org.joml.Vector3ic) Chunk(org.terasology.engine.world.chunks.Chunk) ChunkTask(org.terasology.engine.world.chunks.pipeline.stages.ChunkTask)

Example 79 with Vector3ic

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;
}
Also used : RoundingMode(org.joml.RoundingMode) Component(org.terasology.gestalt.entitysystem.component.Component) OnChangedBlock(org.terasology.engine.world.OnChangedBlock) EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) LoggerFactory(org.slf4j.LoggerFactory) UpdateSubscriberSystem(org.terasology.engine.entitySystem.systems.UpdateSubscriberSystem) Block(org.terasology.engine.world.block.Block) BeforeDeactivateComponent(org.terasology.engine.entitySystem.entity.lifecycleEvents.BeforeDeactivateComponent) Lists(com.google.common.collect.Lists) Vector3ic(org.joml.Vector3ic) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) Vector3i(org.joml.Vector3i) Map(java.util.Map) Vector3f(org.joml.Vector3f) Objects(com.google.common.base.Objects) ComponentContainer(org.terasology.engine.entitySystem.ComponentContainer) RetainComponentsComponent(org.terasology.engine.logic.common.RetainComponentsComponent) ComponentMetadata(org.terasology.engine.entitySystem.metadata.ComponentMetadata) BlockRegion(org.terasology.engine.world.block.BlockRegion) ComponentSystemManager(org.terasology.engine.core.ComponentSystemManager) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) PerformanceMonitor(org.terasology.engine.monitoring.PerformanceMonitor) FieldMetadata(org.terasology.reflection.metadata.FieldMetadata) LocationComponent(org.terasology.engine.logic.location.LocationComponent) Collection(java.util.Collection) EntityManager(org.terasology.engine.entitySystem.entity.EntityManager) NetworkComponent(org.terasology.engine.network.NetworkComponent) Set(java.util.Set) GameThread(org.terasology.engine.core.GameThread) BlockRegionComponent(org.terasology.engine.world.block.regions.BlockRegionComponent) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) List(java.util.List) Context(org.terasology.engine.context.Context) Vector3fc(org.joml.Vector3fc) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) BlockComponent(org.terasology.engine.world.block.BlockComponent) OnActivatedComponent(org.terasology.engine.entitySystem.entity.lifecycleEvents.OnActivatedComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent) Optional(java.util.Optional) BlockEntityRegistry(org.terasology.engine.world.BlockEntityRegistry) BeforeEntityCreated(org.terasology.engine.entitySystem.entity.lifecycleEvents.BeforeEntityCreated) EntityChangeSubscriber(org.terasology.engine.entitySystem.entity.internal.EntityChangeSubscriber) Collections(java.util.Collections) OnChangedComponent(org.terasology.engine.entitySystem.entity.lifecycleEvents.OnChangedComponent) Vector3ic(org.joml.Vector3ic) RetainComponentsComponent(org.terasology.engine.logic.common.RetainComponentsComponent) OnChangedBlock(org.terasology.engine.world.OnChangedBlock) Block(org.terasology.engine.world.block.Block) Component(org.terasology.gestalt.entitysystem.component.Component) BeforeDeactivateComponent(org.terasology.engine.entitySystem.entity.lifecycleEvents.BeforeDeactivateComponent) RetainComponentsComponent(org.terasology.engine.logic.common.RetainComponentsComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) NetworkComponent(org.terasology.engine.network.NetworkComponent) BlockRegionComponent(org.terasology.engine.world.block.regions.BlockRegionComponent) BlockComponent(org.terasology.engine.world.block.BlockComponent) OnActivatedComponent(org.terasology.engine.entitySystem.entity.lifecycleEvents.OnActivatedComponent) OnChangedComponent(org.terasology.engine.entitySystem.entity.lifecycleEvents.OnChangedComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 80 with Vector3ic

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);
    }
}
Also used : Vector3ic(org.joml.Vector3ic) BlockRegionComponent(org.terasology.engine.world.block.regions.BlockRegionComponent) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

Vector3ic (org.joml.Vector3ic)87 Vector3i (org.joml.Vector3i)52 Test (org.junit.jupiter.api.Test)35 BlockRegion (org.terasology.engine.world.block.BlockRegion)28 Chunk (org.terasology.engine.world.chunks.Chunk)28 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)16 Block (org.terasology.engine.world.block.Block)12 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)11 Map (java.util.Map)8 Lists (com.google.common.collect.Lists)5 List (java.util.List)5 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)5 LocationComponent (org.terasology.engine.logic.location.LocationComponent)5 BlockRegionComponent (org.terasology.engine.world.block.regions.BlockRegionComponent)5 Maps (com.google.common.collect.Maps)4 Sets (com.google.common.collect.Sets)4 ArrayList (java.util.ArrayList)4 Collections (java.util.Collections)4 Set (java.util.Set)4 Vector3f (org.joml.Vector3f)4