Search in sources :

Example 71 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class LightMerger method merge.

private void merge(Chunk chunk) {
    Chunk[] localChunks = assembleLocalChunks(chunk);
    localChunks[CENTER_INDEX] = chunk;
    List<BatchPropagator> propagators = Lists.newArrayList();
    propagators.add(new StandardBatchPropagator(new LightPropagationRules(), new LocalChunkView(localChunks, lightRules)));
    PropagatorWorldView regenWorldView = new LocalChunkView(localChunks, sunlightRegenRules);
    PropagationRules sunlightRules = new SunlightPropagationRules(regenWorldView);
    PropagatorWorldView sunlightWorldView = new LocalChunkView(localChunks, sunlightRules);
    BatchPropagator sunlightPropagator = new StandardBatchPropagator(sunlightRules, sunlightWorldView);
    propagators.add(new SunlightRegenBatchPropagator(sunlightRegenRules, regenWorldView, sunlightPropagator, sunlightWorldView));
    propagators.add(sunlightPropagator);
    for (BatchPropagator propagator : propagators) {
        // Propagate Inwards
        for (Side side : Side.values()) {
            Vector3i adjChunkPos = side.getAdjacentPos(chunk.getPosition());
            LitChunk adjChunk = chunkProvider.getChunkUnready(adjChunkPos);
            if (adjChunk != null) {
                propagator.propagateBetween(adjChunk, chunk, side.reverse(), false);
            }
        }
        // Propagate Outwards
        for (Side side : Side.values()) {
            Vector3i adjChunkPos = side.getAdjacentPos(chunk.getPosition());
            LitChunk adjChunk = chunkProvider.getChunk(adjChunkPos);
            if (adjChunk != null) {
                propagator.propagateBetween(chunk, adjChunk, side, true);
            }
        }
    }
    for (BatchPropagator propagator : propagators) {
        propagator.process();
    }
    chunk.deflateSunlight();
}
Also used : StandardBatchPropagator(org.terasology.world.propagation.StandardBatchPropagator) StandardBatchPropagator(org.terasology.world.propagation.StandardBatchPropagator) SunlightRegenBatchPropagator(org.terasology.world.propagation.SunlightRegenBatchPropagator) BatchPropagator(org.terasology.world.propagation.BatchPropagator) SunlightRegenBatchPropagator(org.terasology.world.propagation.SunlightRegenBatchPropagator) LitChunk(org.terasology.world.chunks.LitChunk) Chunk(org.terasology.world.chunks.Chunk) LitChunk(org.terasology.world.chunks.LitChunk) Side(org.terasology.math.Side) PropagatorWorldView(org.terasology.world.propagation.PropagatorWorldView) Vector3i(org.terasology.math.geom.Vector3i) LocalChunkView(org.terasology.world.propagation.LocalChunkView) PropagationRules(org.terasology.world.propagation.PropagationRules)

Example 72 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class BlockSelectionSystem method onStartSelectionAtEntity.

@ReceiveEvent(components = { LocationComponent.class })
public void onStartSelectionAtEntity(SetBlockSelectionStartingPointEvent event, EntityRef entity) {
    LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
    if (null == locationComponent) {
        // entity isn't LocationComponent, which shouldn't ever be the case
        return;
    }
    BlockSelectionComponent blockSelectionComponent = event.getBlockSelectionComponent();
    if (null == blockSelectionComponent) {
        // event did not provide a BlockSelection component to modify
        return;
    }
    Vector3f worldPosition = locationComponent.getWorldPosition();
    Vector3i startPosition = new Vector3i(worldPosition.x, worldPosition.y, worldPosition.z);
    blockSelectionComponent.startPosition = startPosition;
    Vector3i endPosition = startPosition;
    blockSelectionComponent.currentSelection = Region3i.createBounded(startPosition, endPosition);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) LocationComponent(org.terasology.logic.location.LocationComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 73 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class BlockSelectionSystem method onEndSelectionAtEntity.

@ReceiveEvent(components = { LocationComponent.class })
public void onEndSelectionAtEntity(SetBlockSelectionEndingPointEvent event, EntityRef entity) {
    LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
    if (null == locationComponent) {
        // entity isn't LocationComponent, which shouldn't ever be the case
        return;
    }
    BlockSelectionComponent blockSelectionComponent = event.getBlockSelectionComponent();
    if (null == blockSelectionComponent) {
        // event did not provide a BlockSelection component to modify
        return;
    }
    Vector3f worldPosition = locationComponent.getWorldPosition();
    Vector3i endPosition = new Vector3i(worldPosition.x, worldPosition.y, worldPosition.z);
    Vector3i startPosition = blockSelectionComponent.startPosition;
    if (null == startPosition) {
        startPosition = endPosition;
    }
    blockSelectionComponent.currentSelection = Region3i.createBounded(startPosition, endPosition);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) LocationComponent(org.terasology.logic.location.LocationComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 74 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class SubSampledNoise method determineRequiredRegion.

private Region3i determineRequiredRegion(Region3i region) {
    int newMinX = region.minX() - IntMath.mod(region.minX(), sampleRate);
    int newMinY = region.minY() - IntMath.mod(region.minY(), sampleRate);
    int newMinZ = region.minZ() - IntMath.mod(region.minZ(), sampleRate);
    int newMaxX = region.maxX() + 4 - IntMath.mod(region.maxX(), sampleRate) - 1;
    int newMaxY = region.maxY() + 4 - IntMath.mod(region.maxY(), sampleRate) - 1;
    int newMaxZ = region.maxZ() + 4 - IntMath.mod(region.maxZ(), sampleRate) - 1;
    return Region3i.createFromMinMax(new Vector3i(newMinX, newMinY, newMinZ), new Vector3i(newMaxX, newMaxY, newMaxZ));
}
Also used : Vector3i(org.terasology.math.geom.Vector3i)

Example 75 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class BlockEntitySystem method defaultDropsHandling.

@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void defaultDropsHandling(CreateBlockDropsEvent event, EntityRef entity, BlockComponent blockComponent) {
    Vector3i location = blockComponent.getPosition();
    commonDefaultDropsHandling(event, entity, location, blockComponent.getBlock());
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

Vector3i (org.terasology.math.geom.Vector3i)246 Test (org.junit.Test)91 EntityRef (org.terasology.entitySystem.entity.EntityRef)34 Block (org.terasology.world.block.Block)32 Chunk (org.terasology.world.chunks.Chunk)30 Vector3f (org.terasology.math.geom.Vector3f)21 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)17 ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)17 Region3i (org.terasology.math.Region3i)15 BaseVector3i (org.terasology.math.geom.BaseVector3i)15 LocationComponent (org.terasology.logic.location.LocationComponent)14 BlockComponent (org.terasology.world.block.BlockComponent)10 Side (org.terasology.math.Side)9 ChunkViewCoreImpl (org.terasology.world.internal.ChunkViewCoreImpl)8 Before (org.junit.Before)7 Biome (org.terasology.world.biomes.Biome)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 CoreChunk (org.terasology.world.chunks.CoreChunk)6 RenderableChunk (org.terasology.world.chunks.RenderableChunk)6