Search in sources :

Example 46 with Block

use of org.terasology.world.block.Block in project Terasology by MovingBlocks.

the class EntityAwareWorldProvider method setBlock.

@Override
public Block setBlock(Vector3i pos, Block type) {
    if (GameThread.isCurrentThread()) {
        EntityRef blockEntity = getBlockEntityAt(pos);
        Block oldType = super.setBlock(pos, type);
        if (oldType != null) {
            updateBlockEntity(blockEntity, pos, oldType, type, false, Collections.<Class<? extends Component>>emptySet());
        }
        return oldType;
    }
    return null;
}
Also used : Block(org.terasology.world.block.Block) OnChangedBlock(org.terasology.world.OnChangedBlock) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 47 with Block

use of org.terasology.world.block.Block in project Terasology by MovingBlocks.

the class EntityAwareWorldProvider method setBlockForceUpdateEntity.

@Override
public Block setBlockForceUpdateEntity(Vector3i pos, Block type) {
    if (GameThread.isCurrentThread()) {
        EntityRef blockEntity = getBlockEntityAt(pos);
        Block oldType = super.setBlock(pos, type);
        if (oldType != null) {
            updateBlockEntity(blockEntity, pos, oldType, type, true, Collections.<Class<? extends Component>>emptySet());
        }
        return oldType;
    }
    return null;
}
Also used : Block(org.terasology.world.block.Block) OnChangedBlock(org.terasology.world.OnChangedBlock) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 48 with Block

use of org.terasology.world.block.Block in project Terasology by MovingBlocks.

the class WorldProviderCoreImpl method setBlocks.

@Override
public Map<Vector3i, Block> setBlocks(Map<Vector3i, Block> blocks) {
    /*
         * Hint: This method has a benchmark available in the BenchmarkScreen, The screen can be opened ingame via the
         * command "showSCreen BenchmarkScreen".
         */
    Set<RenderableChunk> dirtiedChunks = new HashSet<>();
    Set<BlockChange> changedBlocks = new HashSet<>();
    Map<Vector3i, Block> result = new HashMap<>(blocks.size());
    for (Map.Entry<Vector3i, Block> entry : blocks.entrySet()) {
        Vector3i worldPos = entry.getKey();
        Vector3i chunkPos = ChunkMath.calcChunkPos(worldPos);
        CoreChunk chunk = chunkProvider.getChunk(chunkPos);
        if (chunk != null) {
            Block type = entry.getValue();
            Vector3i blockPos = ChunkMath.calcBlockPos(worldPos);
            Block oldBlockType = chunk.setBlock(blockPos, type);
            if (oldBlockType != type) {
                BlockChange oldChange = blockChanges.get(worldPos);
                if (oldChange == null) {
                    blockChanges.put(worldPos, new BlockChange(worldPos, oldBlockType, type));
                } else {
                    oldChange.setTo(type);
                }
                for (Vector3i pos : ChunkMath.getChunkRegionAroundWorldPos(worldPos, 1)) {
                    RenderableChunk dirtiedChunk = chunkProvider.getChunk(pos);
                    if (dirtiedChunk != null) {
                        dirtiedChunks.add(dirtiedChunk);
                    }
                }
                changedBlocks.add(new BlockChange(worldPos, oldBlockType, type));
            }
            result.put(worldPos, oldBlockType);
        } else {
            result.put(worldPos, null);
        }
    }
    for (RenderableChunk chunk : dirtiedChunks) {
        chunk.setDirty(true);
    }
    for (BlockChange change : changedBlocks) {
        notifyBlockChanged(change.getPosition(), change.getTo(), change.getFrom());
    }
    return result;
}
Also used : CoreChunk(org.terasology.world.chunks.CoreChunk) BlockChange(org.terasology.world.propagation.BlockChange) HashMap(java.util.HashMap) RenderableChunk(org.terasology.world.chunks.RenderableChunk) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 49 with Block

use of org.terasology.world.block.Block in project Terasology by MovingBlocks.

the class StandardBatchPropagator method propagateSide.

private void propagateSide(LitChunk chunk, LitChunk adjChunk, Side side, IndexProvider indexProvider, Region3i edgeRegion, int[] depths) {
    Vector3i adjPos = new Vector3i();
    for (int x = edgeRegion.minX(); x <= edgeRegion.maxX(); ++x) {
        for (int y = edgeRegion.minY(); y <= edgeRegion.maxY(); ++y) {
            for (int z = edgeRegion.minZ(); z <= edgeRegion.maxZ(); ++z) {
                int depthIndex = indexProvider.getIndexFor(x, y, z);
                adjPos.set(x, y, z);
                adjPos.add(chunkEdgeDeltas.get(side));
                byte expectedValue = (byte) (rules.getValue(chunk, x, y, z) - 1);
                if (expectedValue < 1) {
                    continue;
                }
                int depth = 0;
                Block lastBlock = chunk.getBlock(x, y, z);
                byte adjValue = rules.getValue(adjChunk, adjPos);
                while (expectedValue > adjValue && adjValue != PropagatorWorldView.UNAVAILABLE && rules.canSpreadOutOf(lastBlock, side)) {
                    lastBlock = adjChunk.getBlock(adjPos);
                    if (rules.canSpreadInto(lastBlock, side.reverse())) {
                        rules.setValue(adjChunk, adjPos, expectedValue);
                        adjPos.add(side.getVector3i());
                        depth++;
                        expectedValue--;
                        adjValue = rules.getValue(adjChunk, adjPos);
                    } else {
                        break;
                    }
                }
                depths[depthIndex] = depth;
            }
        }
    }
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block)

Example 50 with Block

use of org.terasology.world.block.Block in project Terasology by MovingBlocks.

the class SunlightRegenBatchPropagator method push.

private void push(Vector3i pos, byte value) {
    byte regenValue = value;
    Block block = regenWorld.getBlockAt(pos);
    Vector3i position = new Vector3i(pos);
    while (regenRules.canSpreadOutOf(block, Side.BOTTOM)) {
        regenValue = regenRules.propagateValue(regenValue, Side.BOTTOM, block);
        position.y -= 1;
        byte adjValue = regenWorld.getValueAt(position);
        if (adjValue < regenValue && adjValue != PropagatorWorldView.UNAVAILABLE) {
            block = regenWorld.getBlockAt(position);
            if (regenRules.canSpreadInto(block, Side.TOP)) {
                regenWorld.setValueAt(position, regenValue);
                reduceQueues[adjValue].remove(position);
                byte sunlightValue = (byte) (regenValue - ChunkConstants.SUNLIGHT_REGEN_THRESHOLD);
                if (sunlightValue > 0) {
                    byte prevValue = sunlightWorld.getValueAt(position);
                    if (prevValue < sunlightValue) {
                        sunlightWorld.setValueAt(position, sunlightValue);
                        sunlightPropagator.propagateFrom(new Vector3i(position), sunlightValue);
                    }
                }
            } else {
                break;
            }
        } else {
            break;
        }
    }
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block)

Aggregations

Block (org.terasology.world.block.Block)67 Vector3i (org.terasology.math.geom.Vector3i)32 EntityRef (org.terasology.entitySystem.entity.EntityRef)16 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)11 Side (org.terasology.math.Side)11 Vector3f (org.terasology.math.geom.Vector3f)9 LocationComponent (org.terasology.logic.location.LocationComponent)7 BlockUri (org.terasology.world.block.BlockUri)7 BlockFamily (org.terasology.world.block.family.BlockFamily)7 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)6 OnChangedBlock (org.terasology.world.OnChangedBlock)6 BlockComponent (org.terasology.world.block.BlockComponent)5 BlockManager (org.terasology.world.block.BlockManager)5 BlockRegionComponent (org.terasology.world.block.regions.BlockRegionComponent)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Before (org.junit.Before)3 ResourceUrn (org.terasology.assets.ResourceUrn)3 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)3 DoDamageEvent (org.terasology.logic.health.DoDamageEvent)3