Search in sources :

Example 61 with Vector3i

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

the class WorldProviderCoreImpl method setLiquid.

@Override
public boolean setLiquid(int x, int y, int z, LiquidData newState, LiquidData oldState) {
    Vector3i chunkPos = ChunkMath.calcChunkPos(x, y, z);
    CoreChunk chunk = chunkProvider.getChunk(chunkPos);
    if (chunk != null) {
        Vector3i blockPos = ChunkMath.calcBlockPos(x, y, z);
        LiquidData liquidState = chunk.getLiquid(blockPos);
        if (liquidState.equals(oldState)) {
            chunk.setLiquid(blockPos, newState);
            return true;
        }
    }
    return false;
}
Also used : CoreChunk(org.terasology.world.chunks.CoreChunk) Vector3i(org.terasology.math.geom.Vector3i) LiquidData(org.terasology.world.liquid.LiquidData)

Example 62 with Vector3i

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

the class WorldProviderCoreImpl method getLight.

@Override
public byte getLight(int x, int y, int z) {
    Vector3i chunkPos = ChunkMath.calcChunkPos(x, y, z);
    LitChunk chunk = chunkProvider.getChunk(chunkPos);
    if (chunk != null) {
        Vector3i blockPos = ChunkMath.calcBlockPos(x, y, z);
        return chunk.getLight(blockPos);
    }
    return 0;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) LitChunk(org.terasology.world.chunks.LitChunk)

Example 63 with Vector3i

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

the class WorldProviderCoreImpl method setBlock.

@Override
public Block setBlock(Vector3i worldPos, Block type) {
    /*
         * Hint: This method has a benchmark available in the BenchmarkScreen, The screen can be opened ingame via the
         * command "showSCreen BenchmarkScreen".
         */
    Vector3i chunkPos = ChunkMath.calcChunkPos(worldPos);
    CoreChunk chunk = chunkProvider.getChunk(chunkPos);
    if (chunk != null) {
        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) {
                    dirtiedChunk.setDirty(true);
                }
            }
            notifyBlockChanged(worldPos, type, oldBlockType);
        }
        return oldBlockType;
    }
    return null;
}
Also used : CoreChunk(org.terasology.world.chunks.CoreChunk) BlockChange(org.terasology.world.propagation.BlockChange) Vector3i(org.terasology.math.geom.Vector3i) RenderableChunk(org.terasology.world.chunks.RenderableChunk) Block(org.terasology.world.block.Block)

Example 64 with Vector3i

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

the class WorldProviderCoreImpl method getTotalLight.

@Override
public byte getTotalLight(int x, int y, int z) {
    Vector3i chunkPos = ChunkMath.calcChunkPos(x, y, z);
    LitChunk chunk = chunkProvider.getChunk(chunkPos);
    if (chunk != null) {
        Vector3i blockPos = ChunkMath.calcBlockPos(x, y, z);
        return (byte) Math.max(chunk.getSunlight(blockPos), chunk.getLight(blockPos));
    }
    return 0;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) LitChunk(org.terasology.world.chunks.LitChunk)

Example 65 with Vector3i

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

the class StandardBatchPropagator method reviewChange.

private void reviewChange(BlockChange blockChange) {
    byte newValue = rules.getFixedValue(blockChange.getTo(), blockChange.getPosition());
    byte existingValue = world.getValueAt(blockChange.getPosition());
    if (newValue > existingValue) {
        increase(blockChange.getPosition(), newValue);
    }
    byte oldValue = rules.getFixedValue(blockChange.getFrom(), blockChange.getPosition());
    if (newValue < oldValue) {
        reduce(blockChange.getPosition(), oldValue);
    }
    for (Side side : Side.values()) {
        PropagationComparison comparison = rules.comparePropagation(blockChange.getTo(), blockChange.getFrom(), side);
        if (comparison.isRestricting() && existingValue > 0) {
            reduce(blockChange.getPosition(), existingValue);
            Vector3i adjPos = side.getAdjacentPos(blockChange.getPosition());
            byte adjValue = world.getValueAt(adjPos);
            if (adjValue == rules.propagateValue(existingValue, side, blockChange.getFrom())) {
                reduce(adjPos, adjValue);
            }
        } else if (comparison.isPermitting()) {
            if (existingValue > 0) {
                queueSpreadValue(blockChange.getPosition(), existingValue);
            }
            Vector3i adjPos = side.getAdjacentPos(blockChange.getPosition());
            byte adjValue = world.getValueAt(adjPos);
            if (adjValue != PropagatorWorldView.UNAVAILABLE) {
                queueSpreadValue(adjPos, adjValue);
            }
        }
    }
}
Also used : Side(org.terasology.math.Side) Vector3i(org.terasology.math.geom.Vector3i)

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