Search in sources :

Example 81 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class EntityAwareWorldProvider method setBlock.

@Override
public Block setBlock(Vector3ic pos, Block type) {
    if (GameThread.isCurrentThread()) {
        EntityRef blockEntity = getBlockEntityAt(pos);
        Block oldType = super.setBlock(pos, type);
        final Set<Class<? extends Component>> retainComponents = Optional.ofNullable(blockEntity.getComponent(RetainComponentsComponent.class)).map(retainComponentsComponent -> retainComponentsComponent.components).orElse(Collections.emptySet());
        if (oldType != null) {
            updateBlockEntity(blockEntity, pos, oldType, type, false, retainComponents);
        }
        return oldType;
    }
    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) 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 82 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class StandardBatchPropagator method processReduction.

/**
 * Process all reducing propagation requests This is done from the largest value through the smallest.
 */
private void processReduction() {
    for (int depth = 0; depth < rules.getMaxValue(); depth++) {
        byte oldValue = (byte) (rules.getMaxValue() - depth);
        while (!reduceQueues[depth].isEmpty()) {
            Set<Vector3ic> toProcess = reduceQueues[depth];
            reduceQueues[depth] = Sets.newLinkedHashSetWithExpectedSize(toProcess.size());
            /* This step will add any new reductions to to the `reduceQueues` set */
            for (Vector3ic pos : toProcess) {
                purge(pos, oldValue);
            }
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic)

Example 83 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class StandardBatchPropagator method propagateDepth.

private void propagateDepth(Chunk adjChunk, Side side, boolean propagateExternal, Function<Vector3ic, Integer> indexProvider, BlockRegion edgeRegion, int[] depths) {
    Vector3i adjPos = new Vector3i();
    int[] adjDepth = new int[depths.length];
    int dimA = (side == Side.LEFT || side == Side.RIGHT) ? Chunks.SIZE_Y : Chunks.SIZE_X;
    int dimB = (side == Side.FRONT || side == Side.BACK) ? Chunks.SIZE_Y : Chunks.SIZE_Z;
    BatchPropagator.populateMinAdjacent2D(depths, adjDepth, dimA, dimB, !propagateExternal);
    if (propagateExternal) {
        for (int y = 0; y < dimB; ++y) {
            adjDepth[y * dimA] = 0;
            adjDepth[dimA - 1 + y * dimA] = 0;
        }
        for (int x = 0; x < dimA; ++x) {
            adjDepth[x] = 0;
            adjDepth[x + dimA * (dimB - 1)] = 0;
        }
    }
    for (Vector3ic pos : edgeRegion) {
        int depthIndex = indexProvider.apply(pos);
        int adjacentDepth = adjDepth[depthIndex];
        for (int i = adjacentDepth; i < depths[depthIndex]; ++i) {
            adjPos.set(side.direction());
            adjPos.mul(i + 1);
            adjPos.add(pos);
            adjPos.add(chunkEdgeDeltas.get(side));
            byte value = rules.getValue(adjChunk, adjPos);
            if (value > 1) {
                queueSpreadValue(adjChunk.chunkToWorldPosition(adjPos, new Vector3i()), value);
            }
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i)

Example 84 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class SunlightRegenBatchPropagator method reviewChangeToTop.

private void reviewChangeToTop(BlockChange blockChange) {
    PropagationComparison comparison = regenRules.comparePropagation(blockChange.getTo(), blockChange.getFrom(), Side.TOP);
    Vector3ic blockChangePosition = blockChange.getPosition();
    if (comparison.isPermitting()) {
        Vector3i adjPos = Side.TOP.getAdjacentPos(blockChangePosition, new Vector3i());
        byte adjValue = regenWorld.getValueAt(adjPos);
        if (adjValue != PropagatorWorldView.UNAVAILABLE) {
            queueSpreadRegen(adjPos, adjValue);
        }
    } else if (comparison.isRestricting()) {
        byte existingValue = regenWorld.getValueAt(blockChangePosition);
        reduce(blockChangePosition, existingValue);
    }
}
Also used : Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i)

Example 85 with Vector3ic

use of org.joml.Vector3ic in project Terasology by MovingBlocks.

the class SunlightRegenBatchPropagator method reviewChangeToBottom.

private void reviewChangeToBottom(BlockChange blockChange) {
    PropagationComparison comparison = regenRules.comparePropagation(blockChange.getTo(), blockChange.getFrom(), Side.BOTTOM);
    Vector3ic blockChangePosition = blockChange.getPosition();
    if (comparison.isPermitting()) {
        byte existingValue = regenWorld.getValueAt(blockChangePosition);
        queueSpreadRegen(blockChangePosition, existingValue);
    } else if (comparison.isRestricting()) {
        Vector3i adjPos = Side.BOTTOM.getAdjacentPos(blockChangePosition, new Vector3i());
        byte existingValue = regenWorld.getValueAt(adjPos);
        reduce(adjPos, existingValue);
    }
}
Also used : Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i)

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