Search in sources :

Example 1 with Block

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

the class LocalChunkProviderTest method setUp.

@BeforeEach
public void setUp() {
    entityManager = mock(EntityManager.class);
    blockAtBlockManager = new Block();
    blockAtBlockManager.setId((short) 1);
    blockAtBlockManager.setUri(BlockManager.AIR_ID);
    blockAtBlockManager.setEntity(mock(EntityRef.class));
    blockManager = new TestBlockManager(blockAtBlockManager);
    extraDataManager = new ExtraBlockDataManager();
    blockEntityRegistry = mock(BlockEntityRegistry.class);
    worldEntity = mock(EntityRef.class);
    chunkCache = Maps.newConcurrentMap();
    storageManager = new TestStorageManager();
    generator = new TestWorldGenerator(blockManager);
    chunkProvider = new LocalChunkProvider(storageManager, entityManager, generator, blockManager, extraDataManager, chunkCache);
    chunkProvider.setBlockEntityRegistry(blockEntityRegistry);
    chunkProvider.setWorldEntity(worldEntity);
    // workaround. initialize loading pipeline
    chunkProvider.setRelevanceSystem(new RelevanceSystem(chunkProvider));
}
Also used : EntityManager(org.terasology.engine.entitySystem.entity.EntityManager) TestStorageManager(org.terasology.fixtures.TestStorageManager) TestBlockManager(org.terasology.fixtures.TestBlockManager) Block(org.terasology.engine.world.block.Block) BlockEntityRegistry(org.terasology.engine.world.BlockEntityRegistry) TestWorldGenerator(org.terasology.fixtures.TestWorldGenerator) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with Block

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

the class MapWorldProvider method getBlock.

@Override
public Block getBlock(int x, int y, int z) {
    Vector3i pos = new Vector3i(x, y, z);
    Block block = blocks.get(pos);
    if (block != null) {
        return block;
    }
    // TODO block manager
    Vector3i chunkPos = Chunks.toChunkPos(pos, new Vector3i());
    Chunk chunk = chunks.get(chunkPos);
    if (chunk == null && worldGenerator != null) {
        chunk = new ChunkImpl(chunkPos, blockManager, extraDataManager);
        worldGenerator.createChunk(chunk, entityBuffer);
        chunks.put(chunkPos, chunk);
    }
    if (chunk != null) {
        return chunk.getBlock(Chunks.toRelative(pos, pos));
    }
    return null;
}
Also used : ChunkImpl(org.terasology.engine.world.chunks.internal.ChunkImpl) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) Chunk(org.terasology.engine.world.chunks.Chunk)

Example 3 with Block

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

the class EntityAwareWorldProviderTest method setup.

@BeforeEach
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);
    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.engine.entitySystem.entity.internal.EngineEntityManager) AssetManager(org.terasology.gestalt.assets.management.AssetManager) PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) RetainedOnBlockChangeComponent(org.terasology.unittest.stubs.RetainedOnBlockChangeComponent) BlockManager(org.terasology.engine.world.block.BlockManager) Block(org.terasology.engine.world.block.Block) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) EntityAwareWorldProvider(org.terasology.engine.world.internal.EntityAwareWorldProvider) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) WorldProviderCoreStub(org.terasology.engine.testUtil.WorldProviderCoreStub) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Block

use of org.terasology.engine.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, org.joml.RoundingMode.HALF_UP);
            Vector3i climbBlockPos = new Vector3i(side, org.joml.RoundingMode.HALF_UP);
            Vector3i dir = new Vector3i(block.getDirection().direction());
            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.joml.Vector3f) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block)

Example 5 with Block

use of org.terasology.engine.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) {
    if (!oldPosition.equals(newPosition)) {
        int characterHeightInBlocks = (int) Math.ceil(characterHeight);
        // get the old position's blocks
        Block[] oldBlocks = new Block[characterHeightInBlocks];
        for (int y = 0; y < characterHeightInBlocks; y++) {
            oldBlocks[y] = worldProvider.getBlock(oldPosition.x, oldPosition.y + y, oldPosition.z);
        }
        // get the new position's blocks
        Block[] newBlocks = new Block[characterHeightInBlocks];
        for (int y = 0; y < characterHeightInBlocks; y++) {
            newBlocks[y] = worldProvider.getBlock(newPosition.x, newPosition.y + y, newPosition.z);
        }
        for (int y = 0; y < characterHeightInBlocks; y++) {
            // send a block enter/leave event for this character
            entity.send(new OnEnterBlockEvent(oldBlocks[y], newBlocks[y], new Vector3i(0, y, 0)));
        }
    }
}
Also used : Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) OnEnterBlockEvent(org.terasology.engine.logic.characters.events.OnEnterBlockEvent)

Aggregations

Block (org.terasology.engine.world.block.Block)54 Vector3i (org.joml.Vector3i)23 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)13 Vector3ic (org.joml.Vector3ic)12 Vector3f (org.joml.Vector3f)9 OnChangedBlock (org.terasology.engine.world.OnChangedBlock)9 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)7 Side (org.terasology.engine.math.Side)7 Map (java.util.Map)6 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)6 EntityManager (org.terasology.engine.entitySystem.entity.EntityManager)5 BlockComponent (org.terasology.engine.world.block.BlockComponent)5 Chunk (org.terasology.engine.world.chunks.Chunk)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)4 Maps (com.google.common.collect.Maps)3 Optional (java.util.Optional)3 ComponentSystemManager (org.terasology.engine.core.ComponentSystemManager)3 LocationComponent (org.terasology.engine.logic.location.LocationComponent)3 BlockEntityRegistry (org.terasology.engine.world.BlockEntityRegistry)3