Search in sources :

Example 61 with Vector3i

use of org.joml.Vector3i in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testEntityExtraComponentsRemovedBeforeCleanUp.

@Test
public void testEntityExtraComponentsRemovedBeforeCleanUp() {
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    entity.addComponent(new StringComponent("test"));
    LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class);
    worldProvider.update(1.0f);
    assertEquals(Lists.newArrayList(new EventInfo(BeforeDeactivateComponent.newInstance(), entity), new EventInfo(BeforeRemoveComponent.newInstance(), entity)), checker.receivedEvents);
}
Also used : StringComponent(org.terasology.unittest.stubs.StringComponent) Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 62 with Vector3i

use of org.joml.Vector3i in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testGetTemporaryBlockSendsNoEvent.

@Test
public void testGetTemporaryBlockSendsNoEvent() {
    BlockEventChecker checker = new BlockEventChecker();
    entityManager.getEventSystem().registerEventHandler(checker);
    EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i());
    assertTrue(blockEntity.exists());
    assertFalse(checker.addedReceived);
    assertFalse(checker.activateReceived);
    assertFalse(checker.deactivateReceived);
    assertFalse(checker.removedReceived);
}
Also used : Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 63 with Vector3i

use of org.joml.Vector3i in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testNetworkComponentRemovedWhenTemporaryCleanedUp.

@Test
public void testNetworkComponentRemovedWhenTemporaryCleanedUp() {
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    entity.addComponent(new RetainedOnBlockChangeComponent(2));
    LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), NetworkComponent.class);
    entity.removeComponent(RetainedOnBlockChangeComponent.class);
    worldProvider.update(1.0f);
    assertEquals(Lists.newArrayList(new EventInfo(BeforeDeactivateComponent.newInstance(), entity), new EventInfo(BeforeRemoveComponent.newInstance(), entity)), checker.receivedEvents);
}
Also used : RetainedOnBlockChangeComponent(org.terasology.unittest.stubs.RetainedOnBlockChangeComponent) Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 64 with Vector3i

use of org.joml.Vector3i in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testComponentsAddedAndActivatedWhenBlockChanged.

@Disabled("Failing due to #2625. TODO: fix to match new behaviour")
@Test
public void testComponentsAddedAndActivatedWhenBlockChanged() {
    LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class);
    worldProvider.setBlock(new Vector3i(), blockWithString);
    EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i());
    assertTrue(blockEntity.exists());
    assertEquals(Lists.newArrayList(new EventInfo(OnAddedComponent.newInstance(), blockEntity), new EventInfo(OnActivatedComponent.newInstance(), blockEntity)), checker.receivedEvents);
}
Also used : Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 65 with Vector3i

use of org.joml.Vector3i 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)

Aggregations

Vector3i (org.joml.Vector3i)203 Test (org.junit.jupiter.api.Test)87 Vector3ic (org.joml.Vector3ic)54 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)38 Chunk (org.terasology.engine.world.chunks.Chunk)36 BlockRegion (org.terasology.engine.world.block.BlockRegion)30 Block (org.terasology.engine.world.block.Block)22 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)21 Vector3f (org.joml.Vector3f)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 Map (java.util.Map)11 BeforeEach (org.junit.jupiter.api.BeforeEach)10 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)10 ChunkViewCoreImpl (org.terasology.engine.world.internal.ChunkViewCoreImpl)8 OnChunkLoaded (org.terasology.engine.world.chunks.event.OnChunkLoaded)7 Lists (com.google.common.collect.Lists)6 Maps (com.google.common.collect.Maps)6 List (java.util.List)6 ExecutionException (java.util.concurrent.ExecutionException)6 Future (java.util.concurrent.Future)6