Search in sources :

Example 1 with RetainedOnBlockChangeComponent

use of org.terasology.unittest.stubs.RetainedOnBlockChangeComponent 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 2 with RetainedOnBlockChangeComponent

use of org.terasology.unittest.stubs.RetainedOnBlockChangeComponent 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 3 with RetainedOnBlockChangeComponent

use of org.terasology.unittest.stubs.RetainedOnBlockChangeComponent in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testAllComponentsNotMarkedAsRetainedRemovedOnBlockChange.

@Test
public void testAllComponentsNotMarkedAsRetainedRemovedOnBlockChange() {
    worldStub.setBlock(new Vector3i(), blockWithString);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    entity.addComponent(new ForceBlockActiveComponent());
    entity.addComponent(new RetainedOnBlockChangeComponent(2));
    worldProvider.setBlock(new Vector3i(), airBlock);
    assertTrue(entity.hasComponent(RetainedOnBlockChangeComponent.class));
    assertFalse(entity.hasComponent(ForceBlockActiveComponent.class));
}
Also used : RetainedOnBlockChangeComponent(org.terasology.unittest.stubs.RetainedOnBlockChangeComponent) Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ForceBlockActiveComponent(org.terasology.unittest.stubs.ForceBlockActiveComponent) Test(org.junit.jupiter.api.Test)

Example 4 with RetainedOnBlockChangeComponent

use of org.terasology.unittest.stubs.RetainedOnBlockChangeComponent in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testRetainedComponentsNotAltered.

@Test
public void testRetainedComponentsNotAltered() {
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    entity.addComponent(new RetainedOnBlockChangeComponent(2));
    worldProvider.setBlock(new Vector3i(), blockWithRetainedComponent);
    assertEquals(2, entity.getComponent(RetainedOnBlockChangeComponent.class).value);
}
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 5 with RetainedOnBlockChangeComponent

use of org.terasology.unittest.stubs.RetainedOnBlockChangeComponent in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testMetworkComponentAddedWhenChangedToNonTemporary.

@Test
public void testMetworkComponentAddedWhenChangedToNonTemporary() {
    LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), NetworkComponent.class);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    entity.addComponent(new RetainedOnBlockChangeComponent(2));
    assertEquals(Lists.newArrayList(new EventInfo(OnAddedComponent.newInstance(), entity), new EventInfo(OnActivatedComponent.newInstance(), entity)), checker.receivedEvents);
    assertTrue(entity.hasComponent(NetworkComponent.class));
}
Also used : NetworkComponent(org.terasology.engine.network.NetworkComponent) RetainedOnBlockChangeComponent(org.terasology.unittest.stubs.RetainedOnBlockChangeComponent) Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Aggregations

RetainedOnBlockChangeComponent (org.terasology.unittest.stubs.RetainedOnBlockChangeComponent)5 Vector3i (org.joml.Vector3i)4 Test (org.junit.jupiter.api.Test)4 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)4 BeforeEach (org.junit.jupiter.api.BeforeEach)1 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)1 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)1 PrefabData (org.terasology.engine.entitySystem.prefab.PrefabData)1 NetworkComponent (org.terasology.engine.network.NetworkComponent)1 WorldProviderCoreStub (org.terasology.engine.testUtil.WorldProviderCoreStub)1 Block (org.terasology.engine.world.block.Block)1 BlockManager (org.terasology.engine.world.block.BlockManager)1 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)1 EntityAwareWorldProvider (org.terasology.engine.world.internal.EntityAwareWorldProvider)1 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)1 AssetManager (org.terasology.gestalt.assets.management.AssetManager)1 ForceBlockActiveComponent (org.terasology.unittest.stubs.ForceBlockActiveComponent)1