@Test public void testBlockEntityPrefabCorrectlyAddedOnChangeToBlockWithPrefab() { worldProvider.setBlock(Vector3i.zero(), plainBlock); EntityRef entity = worldProvider.getBlockEntityAt(Vector3i.zero()); worldProvider.setBlock(Vector3i.zero(), blockWithString); assertEquals(blockWithString.getPrefab(), entity.getParentPrefab().getURI().toSimpleString()); }
@Test public void testBlockEntityPrefabCorrectlyRemovedOnChangeToBlockWithNoPrefab() { worldProvider.setBlock(Vector3i.zero(), blockWithString); EntityRef entity = worldProvider.getBlockEntityAt(Vector3i.zero()); worldProvider.setBlock(Vector3i.zero(), plainBlock); assertEquals(null, entity.getParentPrefab()); }
@Test public void testEntityBecomesTemporaryWhenChangedFromAKeepActiveBlock() { worldProvider.setBlock(Vector3i.zero(), keepActiveBlock); EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0)); worldProvider.setBlock(Vector3i.zero(), BlockManager.getAir()); worldProvider.update(1.0f); assertFalse(blockEntity.isActive()); }
@Test public void componentsNotAlteredIfBlockInSameFamily() { worldProvider.setBlock(Vector3i.zero(), blockInFamilyOne); EntityRef entity = worldProvider.getBlockEntityAt(Vector3i.zero()); entity.addComponent(new IntegerComponent()); worldProvider.setBlock(Vector3i.zero(), blockInFamilyTwo); assertNotNull(entity.getComponent(IntegerComponent.class)); }
@Test public void testPrefabUpdatedWhenBlockChanged() { worldProvider.setBlock(Vector3i.zero(), blockWithString); assertEquals( blockWithString.getPrefab(), worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0)).getParentPrefab().getName()); worldProvider.setBlock(Vector3i.zero(), blockWithDifferentString); assertEquals( blockWithDifferentString.getPrefab(), worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0)).getParentPrefab().getName()); }
@Test public void testComponentsUpdatedWhenBlockChanged() { worldProvider.setBlock(Vector3i.zero(), blockWithString); LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class); worldProvider.setBlock(Vector3i.zero(), blockWithDifferentString); EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0)); assertTrue(blockEntity.exists()); assertEquals( Lists.newArrayList(new EventInfo(OnChangedComponent.newInstance(), blockEntity)), checker.receivedEvents); }
@Test public void componentUntouchedIfRetainRequested() { worldProvider.setBlock(Vector3i.zero(), blockInFamilyOne); EntityRef entity = worldProvider.getBlockEntityAt(Vector3i.zero()); entity.addComponent(new IntegerComponent()); worldProvider.setBlockRetainComponent(Vector3i.zero(), blockWithString, IntegerComponent.class); assertNotNull(entity.getComponent(IntegerComponent.class)); }
@Test public void retainedComponentsNotAltered() { 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); }
@Test public void testEntityCeasesToBeTemporaryIfBlockChangedToKeepActive() { worldProvider.setBlock(Vector3i.zero(), keepActiveBlock); worldProvider.update(1.0f); LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class); worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0)); assertTrue(checker.receivedEvents.isEmpty()); }
@Test public void allComponentsNotMarkedAsRetainedRemovedOnBlockChange() { 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(), BlockManager.getAir()); assertTrue(entity.hasComponent(RetainedOnBlockChangeComponent.class)); assertFalse(entity.hasComponent(ForceBlockActiveComponent.class)); }