Search in sources :

Example 56 with Block

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

the class ServerImpl method onChunkReady.

@Override
public void onChunkReady(Vector3i chunkPos) {
    WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
    List<NetData.BlockChangeMessage> updateBlockMessages = awaitingChunkReadyBlockUpdates.removeAll(chunkPos);
    for (NetData.BlockChangeMessage message : updateBlockMessages) {
        Vector3i pos = NetMessageUtil.convert(message.getPos());
        Block newBlock = blockManager.getBlock((short) message.getNewBlock());
        worldProvider.setBlock(pos, newBlock);
    }
    List<NetData.BiomeChangeMessage> updateBiomeMessages = awaitingChunkReadyBiomeUpdates.removeAll(chunkPos);
    for (NetData.BiomeChangeMessage message : updateBiomeMessages) {
        Vector3i pos = NetMessageUtil.convert(message.getPos());
        Biome newBiome = biomeManager.getBiomeByShortId((short) message.getNewBiome());
        worldProvider.setBiome(pos, newBiome);
    }
}
Also used : Biome(org.terasology.world.biomes.Biome) NetData(org.terasology.protobuf.NetData) WorldProvider(org.terasology.world.WorldProvider) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block)

Example 57 with Block

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

the class LocalChunkProviderTest method registerBlockWithIdAndEntity.

private static void registerBlockWithIdAndEntity(final short blockId, final EntityRef blockEntity, final BlockManager blockManager) {
    final Block block = new Block();
    block.setEntity(blockEntity);
    when(blockManager.getBlock(eq(blockId))).thenReturn(block);
}
Also used : Block(org.terasology.world.block.Block)

Example 58 with Block

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

the class EntityAwareWorldProviderTest method setup.

@Before
public void setup() throws Exception {
    super.setup();
    GameThread.setToCurrentThread();
    this.entityManager = context.get(EngineEntityManager.class);
    AssetManager assetManager = context.get(AssetManager.class);
    BlockManager blockManager = context.get(BlockManager.class);
    airBlock = blockManager.getBlock(BlockManager.AIR_ID);
    worldStub = new WorldProviderCoreStub(airBlock, null);
    worldProvider = new EntityAwareWorldProvider(worldStub, context);
    plainBlock = createBlock("test:plainblock", assetManager, blockManager);
    prefabWithString = createPrefabWithString("test:prefabWithString", "Test", assetManager);
    blockWithString = createBlockWithPrefab("test:blockWithString", prefabWithString, false, assetManager, blockManager);
    keepActiveBlock = createBlockWithPrefab("test:keepActiveBlock", prefabWithString, true, assetManager, blockManager);
    Prefab prefabWithDifferentString = createPrefabWithString("test:prefabWithDifferentString", "Test2", assetManager);
    blockWithDifferentString = createBlockWithPrefab("test:prefabWithDifferentString", prefabWithDifferentString, false, assetManager, blockManager);
    BlockFamily blockFamily = createBlockFamily("test:blockFamily", prefabWithString, assetManager, blockManager);
    Iterator<Block> iterator = blockFamily.getBlocks().iterator();
    blockInFamilyOne = iterator.next();
    blockInFamilyTwo = iterator.next();
    PrefabData retainedPrefabData = new PrefabData();
    retainedPrefabData.addComponent(new RetainedOnBlockChangeComponent(3));
    Prefab retainedPrefab = assetManager.loadAsset(new ResourceUrn("test:retainedPrefab"), retainedPrefabData, Prefab.class);
    blockWithRetainedComponent = createBlockWithPrefab("test:blockWithRetainedComponent", retainedPrefab, false, assetManager, blockManager);
    worldProvider.initialise();
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) AssetManager(org.terasology.assets.management.AssetManager) PrefabData(org.terasology.entitySystem.prefab.PrefabData) RetainedOnBlockChangeComponent(org.terasology.entitySystem.stubs.RetainedOnBlockChangeComponent) BlockManager(org.terasology.world.block.BlockManager) Block(org.terasology.world.block.Block) BlockFamily(org.terasology.world.block.family.BlockFamily) EntityAwareWorldProvider(org.terasology.world.internal.EntityAwareWorldProvider) ResourceUrn(org.terasology.assets.ResourceUrn) Prefab(org.terasology.entitySystem.prefab.Prefab) WorldProviderCoreStub(org.terasology.testUtil.WorldProviderCoreStub) Before(org.junit.Before)

Example 59 with Block

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

the class KinematicCharacterMover method checkBlockEntry.

/*
    * Figure out if our position has put us into a new set of blocks and fire the appropriate events.
    */
private void checkBlockEntry(EntityRef entity, Vector3i oldPosition, Vector3i newPosition, float characterHeight) {
    // is this a different position than previously
    if (!oldPosition.equals(newPosition)) {
        Biome oldBiome = worldProvider.getBiome(oldPosition);
        Biome newBiome = worldProvider.getBiome(newPosition);
        if (oldBiome != newBiome) {
            entity.send(new OnEnterBiomeEvent(oldPosition, newPosition, oldBiome, newBiome));
        }
        // get the old position's blocks
        Block[] oldBlocks = new Block[(int) Math.ceil(characterHeight)];
        Vector3i currentPosition = new Vector3i(oldPosition);
        for (int currentHeight = 0; currentHeight < oldBlocks.length; currentHeight++) {
            oldBlocks[currentHeight] = worldProvider.getBlock(currentPosition);
            currentPosition.add(0, 1, 0);
        }
        // get the new position's blocks
        Block[] newBlocks = new Block[(int) Math.ceil(characterHeight)];
        currentPosition = new Vector3i(newPosition);
        for (int currentHeight = 0; currentHeight < characterHeight; currentHeight++) {
            newBlocks[currentHeight] = worldProvider.getBlock(currentPosition);
            currentPosition.add(0, 1, 0);
        }
        for (int i = 0; i < characterHeight; i++) {
            // send a block enter/leave event for this character
            entity.send(new OnEnterBlockEvent(oldBlocks[i], newBlocks[i], new Vector3i(0, i, 0)));
        }
    }
}
Also used : Biome(org.terasology.world.biomes.Biome) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) OnEnterBiomeEvent(org.terasology.logic.characters.events.OnEnterBiomeEvent) OnEnterBlockEvent(org.terasology.logic.characters.events.OnEnterBlockEvent)

Example 60 with Block

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

the class KinematicCharacterMover method findClimbable.

private Vector3i findClimbable(CharacterMovementComponent movementComp, Vector3f worldPos, boolean swimming, boolean diving) {
    Vector3i finalDir = null;
    Vector3f[] sides = { new Vector3f(worldPos), new Vector3f(worldPos), new Vector3f(worldPos), new Vector3f(worldPos), new Vector3f(worldPos) };
    float factor = 1.0f;
    sides[0].x += factor * movementComp.radius;
    sides[1].x -= factor * movementComp.radius;
    sides[2].z += factor * movementComp.radius;
    sides[3].z -= factor * movementComp.radius;
    sides[4].y -= movementComp.height;
    float distance = 100f;
    for (Vector3f side : sides) {
        Block block = worldProvider.getBlock(side);
        if (block.isClimbable()) {
            // If any of our sides are near a climbable block, check if we are near to the side
            Vector3i myPos = new Vector3i(worldPos, RoundingMode.HALF_UP);
            Vector3i climbBlockPos = new Vector3i(side, RoundingMode.HALF_UP);
            Vector3i dir = new Vector3i(block.getDirection().getVector3i());
            float currentDistance = 10f;
            if (dir.x != 0 && Math.abs(worldPos.x - climbBlockPos.x + dir.x * .5f) < movementComp.radius + 0.1f) {
                if (myPos.x < climbBlockPos.x) {
                    dir.x = -dir.x;
                }
                currentDistance = Math.abs(climbBlockPos.z - worldPos.z);
            } else if (dir.z != 0 && Math.abs(worldPos.z - climbBlockPos.z + dir.z * .5f) < movementComp.radius + 0.1f) {
                if (myPos.z < climbBlockPos.z) {
                    dir.z = -dir.z;
                }
                currentDistance = Math.abs(climbBlockPos.z - worldPos.z);
            }
            // adjacent ledges around a corner.
            if (currentDistance < distance) {
                distance = currentDistance;
                finalDir = dir;
            }
        }
    }
    return finalDir;
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) 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