コード例 #1
0
 @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());
 }
コード例 #2
0
 @Test
 public void testBlockEntityPrefabCorrectlyRemovedOnChangeToBlockWithNoPrefab() {
   worldProvider.setBlock(Vector3i.zero(), blockWithString);
   EntityRef entity = worldProvider.getBlockEntityAt(Vector3i.zero());
   worldProvider.setBlock(Vector3i.zero(), plainBlock);
   assertEquals(null, entity.getParentPrefab());
 }
コード例 #3
0
 @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());
 }
コード例 #4
0
 @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));
 }
コード例 #5
0
 @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());
 }
コード例 #6
0
  @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);
  }
コード例 #7
0
 @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));
 }
コード例 #8
0
  @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);
  }
コード例 #9
0
 @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());
 }
コード例 #10
0
  @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));
  }