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);
}
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();
}
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));
}
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);
}
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));
}
Aggregations