Search in sources :

Example 36 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testEntityNotRemovedIfForceBlockActiveComponentAdded.

@Test
public void testEntityNotRemovedIfForceBlockActiveComponentAdded() {
    EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i());
    blockEntity.addComponent(new ForceBlockActiveComponent());
    worldProvider.update(1.0f);
    assertTrue(blockEntity.exists());
    assertTrue(blockEntity.isActive());
}
Also used : Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ForceBlockActiveComponent(org.terasology.unittest.stubs.ForceBlockActiveComponent) Test(org.junit.jupiter.api.Test)

Example 37 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testChangedComponentsRevertedBeforeCleanUp.

@Test
public void testChangedComponentsRevertedBeforeCleanUp() {
    worldStub.setBlock(new Vector3i(), blockWithString);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    StringComponent comp = entity.getComponent(StringComponent.class);
    comp.value = "Moo";
    entity.saveComponent(comp);
    LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class);
    worldProvider.update(1.0f);
    assertEquals(Lists.newArrayList(new EventInfo(OnChangedComponent.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 38 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testBlockEntityPrefabCorrectlyAddedOnChangeToBlockWithPrefab.

@Disabled("Failing due to #2625. TODO: fix to match new behaviour")
@Test
public void testBlockEntityPrefabCorrectlyAddedOnChangeToBlockWithPrefab() {
    worldProvider.setBlock(new Vector3i(), plainBlock);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    worldProvider.setBlock(new Vector3i(), blockWithString);
    assertEquals(blockWithString.getPrefab().get().getUrn().toString(), entity.getParentPrefab().getUrn().toString());
}
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 39 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testComponentUntouchedIfRetainRequested.

@Test
public void testComponentUntouchedIfRetainRequested() {
    worldProvider.setBlock(new Vector3i(), blockInFamilyOne);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    entity.addComponent(new IntegerComponent());
    worldProvider.setBlockRetainComponent(new Vector3i(), blockWithString, IntegerComponent.class);
    assertNotNull(entity.getComponent(IntegerComponent.class));
}
Also used : IntegerComponent(org.terasology.unittest.stubs.IntegerComponent) Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 40 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef 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)

Aggregations

EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)298 Test (org.junit.jupiter.api.Test)88 ClientComponent (org.terasology.engine.network.ClientComponent)55 Vector3f (org.joml.Vector3f)51 LocationComponent (org.terasology.engine.logic.location.LocationComponent)44 Vector3i (org.joml.Vector3i)36 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)34 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)29 StringComponent (org.terasology.unittest.stubs.StringComponent)26 NetworkComponent (org.terasology.engine.network.NetworkComponent)23 EntityData (org.terasology.protobuf.EntityData)23 Quaternionf (org.joml.Quaternionf)19 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)19 Component (org.terasology.gestalt.entitysystem.component.Component)19 CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)15 Map (java.util.Map)14 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)13 BlockComponent (org.terasology.engine.world.block.BlockComponent)13 Block (org.terasology.engine.world.block.Block)11 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)10