Search in sources :

Example 31 with Vector3i

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

the class NetClient method sendChunkInvalidations.

private void sendChunkInvalidations(NetData.NetMessage.Builder message) {
    Iterator<Vector3i> i = invalidatedChunks.iterator();
    while (i.hasNext()) {
        Vector3i pos = i.next();
        i.remove();
        relevantChunks.remove(pos);
        message.addInvalidateChunk(NetData.InvalidateChunkMessage.newBuilder().setPos(NetMessageUtil.convert(pos)));
    }
    invalidatedChunks.clear();
}
Also used : Vector3i(org.terasology.math.geom.Vector3i)

Example 32 with Vector3i

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

the class ServerImpl method processBiomeChanges.

private void processBiomeChanges(NetData.NetMessage message) {
    for (NetData.BiomeChangeMessage biomeChange : message.getBiomeChangeList()) {
        logger.debug("Received block change to {}", blockManager.getBlock((short) biomeChange.getNewBiome()));
        // TODO: Store changes to blocks that aren't ready to be modified (the surrounding chunks aren't available)
        WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
        Vector3i pos = NetMessageUtil.convert(biomeChange.getPos());
        if (worldProvider.isBlockRelevant(pos)) {
            Biome newBiome = biomeManager.getBiomeByShortId((short) biomeChange.getNewBiome());
            worldProvider.setBiome(pos, newBiome);
        } else {
            awaitingChunkReadyBiomeUpdates.put(ChunkMath.calcChunkPos(pos), biomeChange);
        }
    }
}
Also used : Biome(org.terasology.world.biomes.Biome) NetData(org.terasology.protobuf.NetData) WorldProvider(org.terasology.world.WorldProvider) Vector3i(org.terasology.math.geom.Vector3i)

Example 33 with Vector3i

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

the class ServerImpl method processBlockChanges.

private void processBlockChanges(NetData.NetMessage message) {
    for (NetData.BlockChangeMessage blockChange : message.getBlockChangeList()) {
        Block newBlock = blockManager.getBlock((short) blockChange.getNewBlock());
        logger.debug("Received block change to {}", newBlock);
        // TODO: Store changes to blocks that aren't ready to be modified (the surrounding chunks aren't available)
        WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
        Vector3i pos = NetMessageUtil.convert(blockChange.getPos());
        if (worldProvider.isBlockRelevant(pos)) {
            worldProvider.setBlock(pos, newBlock);
        } else {
            awaitingChunkReadyBlockUpdates.put(ChunkMath.calcChunkPos(pos), blockChange);
        }
    }
}
Also used : NetData(org.terasology.protobuf.NetData) WorldProvider(org.terasology.world.WorldProvider) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block)

Example 34 with Vector3i

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

the class NetEntityRefTypeHandler method deserialize.

@Override
public EntityRef deserialize(PersistedData data, DeserializationContext context) {
    if (data.isArray()) {
        PersistedDataArray array = data.getAsArray();
        if (array.isNumberArray() && array.size() == 3) {
            TIntList items = data.getAsArray().getAsIntegerArray();
            Vector3i pos = new Vector3i(items.get(0), items.get(1), items.get(2));
            return blockEntityRegistry.getBlockEntityAt(pos);
        }
    }
    if (data.isNumber()) {
        return networkSystem.getEntity(data.getAsInteger());
    }
    return EntityRef.NULL;
}
Also used : PersistedDataArray(org.terasology.persistence.typeHandling.PersistedDataArray) Vector3i(org.terasology.math.geom.Vector3i) TIntList(gnu.trove.list.TIntList)

Example 35 with Vector3i

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

the class NetEntityRefTypeHandler method serializeCollection.

@Override
public PersistedData serializeCollection(Collection<EntityRef> value, SerializationContext context) {
    List<PersistedData> items = Lists.newArrayList();
    for (EntityRef ref : value) {
        BlockComponent blockComponent = ref.getComponent(BlockComponent.class);
        if (blockComponent != null) {
            Vector3i blockPos = blockComponent.getPosition();
            items.add(context.create(blockPos.x, blockPos.y, blockPos.z));
        } else {
            NetworkComponent netComponent = ref.getComponent(NetworkComponent.class);
            if (netComponent != null) {
                items.add(context.create(netComponent.getNetworkId()));
            } else {
                items.add(context.createNull());
            }
        }
    }
    return context.create(items);
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) NetworkComponent(org.terasology.network.NetworkComponent) Vector3i(org.terasology.math.geom.Vector3i) PersistedData(org.terasology.persistence.typeHandling.PersistedData) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Aggregations

Vector3i (org.terasology.math.geom.Vector3i)249 Test (org.junit.Test)94 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