Search in sources :

Example 1 with RetainedOnBlockChangeComponent

use of org.terasology.entitySystem.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(0, 0, 0));
    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.network.NetworkComponent) RetainedOnBlockChangeComponent(org.terasology.entitySystem.stubs.RetainedOnBlockChangeComponent) Vector3i(org.terasology.math.geom.Vector3i) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 2 with RetainedOnBlockChangeComponent

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

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

the class EntityAwareWorldProviderTest method testAllComponentsNotMarkedAsRetainedRemovedOnBlockChange.

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

Example 4 with RetainedOnBlockChangeComponent

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

the class EntityAwareWorldProviderTest method testNetworkComponentRemovedWhenTemporaryCleanedUp.

@Test
public void testNetworkComponentRemovedWhenTemporaryCleanedUp() {
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0));
    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.entitySystem.stubs.RetainedOnBlockChangeComponent) Vector3i(org.terasology.math.geom.Vector3i) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 5 with RetainedOnBlockChangeComponent

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

the class EntityAwareWorldProviderTest method testRetainedComponentsNotAltered.

@Test
public void testRetainedComponentsNotAltered() {
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0));
    entity.addComponent(new RetainedOnBlockChangeComponent(2));
    worldProvider.setBlock(Vector3i.zero(), blockWithRetainedComponent);
    assertEquals(2, entity.getComponent(RetainedOnBlockChangeComponent.class).value);
}
Also used : RetainedOnBlockChangeComponent(org.terasology.entitySystem.stubs.RetainedOnBlockChangeComponent) Vector3i(org.terasology.math.geom.Vector3i) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Aggregations

RetainedOnBlockChangeComponent (org.terasology.entitySystem.stubs.RetainedOnBlockChangeComponent)5 Test (org.junit.Test)4 EntityRef (org.terasology.entitySystem.entity.EntityRef)4 Vector3i (org.terasology.math.geom.Vector3i)4 Before (org.junit.Before)1 ResourceUrn (org.terasology.assets.ResourceUrn)1 AssetManager (org.terasology.assets.management.AssetManager)1 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)1 Prefab (org.terasology.entitySystem.prefab.Prefab)1 PrefabData (org.terasology.entitySystem.prefab.PrefabData)1 ForceBlockActiveComponent (org.terasology.entitySystem.stubs.ForceBlockActiveComponent)1 NetworkComponent (org.terasology.network.NetworkComponent)1 WorldProviderCoreStub (org.terasology.testUtil.WorldProviderCoreStub)1 Block (org.terasology.world.block.Block)1 BlockManager (org.terasology.world.block.BlockManager)1 BlockFamily (org.terasology.world.block.family.BlockFamily)1 EntityAwareWorldProvider (org.terasology.world.internal.EntityAwareWorldProvider)1