@Test public void testComponentsNotAlteredIfBlockInSameFamily() { 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 testComponentsAlteredIfBlockInSameFamilyWhenForced() { worldProvider.setBlock(Vector3i.zero(), blockInFamilyOne); EntityRef entity = worldProvider.getBlockEntityAt(Vector3i.zero()); entity.addComponent(new IntegerComponent()); worldProvider.setBlockForceUpdateEntity(Vector3i.zero(), blockInFamilyTwo); assertNull(entity.getComponent(IntegerComponent.class)); }
@Test public void testComponentUntouchedIfRetainRequested() { 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)); }
@Ignore("Failing due to #2625. TODO: fix to match new behaviour") @Test public void testBlockEntityPrefabCorrectlyAlteredOnChangeToDifferentPrefab() { worldProvider.setBlock(Vector3i.zero(), blockWithString); EntityRef entity = worldProvider.getBlockEntityAt(Vector3i.zero()); worldProvider.setBlock(Vector3i.zero(), blockWithDifferentString); assertEquals(blockWithDifferentString.getPrefab().get().getUrn(), entity.getParentPrefab().getUrn()); }
@Ignore("Failing due to #2625. TODO: fix to match new behaviour") @Test public void testBlockEntityPrefabCorrectlyAddedOnChangeToBlockWithPrefab() { worldProvider.setBlock(Vector3i.zero(), plainBlock); EntityRef entity = worldProvider.getBlockEntityAt(Vector3i.zero()); worldProvider.setBlock(Vector3i.zero(), blockWithString); assertEquals(blockWithString.getPrefab().get().getUrn().toString(), entity.getParentPrefab().getUrn().toString()); }
@Test public void testTwoDistanceIteration() { Set<Vector3i> iter = Sets.newHashSet(Diamond3iIterator.iterate(Vector3i.zero(), 2)); assertEquals(25, iter.size()); for (Vector3i pos : iter) { assertTrue(pos.gridDistance(new Vector3i()) <= 2); } }
@Override public void propagateBetween(LitChunk chunk, LitChunk adjChunk, Side side, boolean propagateExternal) { IndexProvider indexProvider = createIndexProvider(side); Region3i edgeRegion = ChunkMath.getEdgeRegion(Region3i.createFromMinAndSize(Vector3i.zero(), ChunkConstants.CHUNK_SIZE), side); int edgeSize = edgeRegion.size().x * edgeRegion.size().y * edgeRegion.size().z; int[] depth = new int[edgeSize]; propagateSide(chunk, adjChunk, side, indexProvider, edgeRegion, depth); propagateDepth(adjChunk, side, propagateExternal, indexProvider, edgeRegion, depth); }
@Test public void testEntityBecomesTemporaryWhenChangedFromAKeepActiveBlock() { worldProvider.setBlock(Vector3i.zero(), keepActiveBlock); EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0)); worldProvider.setBlock(Vector3i.zero(), airBlock); worldProvider.update(1.0f); assertFalse(blockEntity.isActive()); }
@Test public void testSimpleWorldView() { Chunk chunk = createChunk(0, 0, 0); chunk.setBlock(new Vector3i(0, 0, 0), solidBlock); ChunkViewCore chunkView = new ChunkViewCoreImpl(new Chunk[]{chunk}, Region3i.createFromCenterExtents(Vector3i.zero(), Vector3i.zero()), new Vector3i(), airBlock); assertEquals(solidBlock, chunkView.getBlock(0, 0, 0)); }
@Test public void testUnblockedSunlightRegenPropagation() { Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, biomeManager, extraDataManager); InternalLightProcessor.generateInternalLighting(chunk); for (Vector3i pos : Region3i.createFromMinAndSize(Vector3i.zero(), new Vector3i(ChunkConstants.SIZE_X, ChunkConstants.SIZE_Y, ChunkConstants.SIZE_Z))) { byte expectedRegen = (byte) Math.min(ChunkConstants.SIZE_Y - pos.y - 1, ChunkConstants.MAX_SUNLIGHT_REGEN); assertEquals(expectedRegen, chunk.getSunlightRegen(pos)); } }
@Ignore("Failing due to #2625. TODO: fix to match new behaviour") @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); }
@Ignore("Failing due to #2625. TODO: fix to match new behaviour") @Test public void testComponentsAddedAndActivatedWhenBlockChanged() { LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class); worldProvider.setBlock(Vector3i.zero(), blockWithString); EntityRef blockEntity = worldProvider.getBlockEntityAt(Vector3i.zero()); assertTrue(blockEntity.exists()); assertEquals(Lists.newArrayList(new EventInfo(OnAddedComponent.newInstance(), blockEntity), new EventInfo(OnActivatedComponent.newInstance(), blockEntity)), checker.receivedEvents); }
@Test public void testPrefabUpdatedWhenBlockChanged() { worldProvider.setBlock(Vector3i.zero(), blockWithString); assertEquals(blockWithString.getPrefab().get().getName(), worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0)).getParentPrefab().getName()); worldProvider.setBlock(Vector3i.zero(), blockWithDifferentString); assertEquals(blockWithDifferentString.getPrefab().get().getName(), worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0)).getParentPrefab().getName()); }
@Ignore("Failing due to #2625. TODO: fix to match new behaviour") @Test public void testComponentsDeactivatedAndRemovedWhenBlockChanged() { worldProvider.setBlock(Vector3i.zero(), blockWithString); LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class); worldProvider.setBlock(Vector3i.zero(), airBlock); EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0)); assertTrue(blockEntity.exists()); assertEquals(Lists.newArrayList(new EventInfo(BeforeDeactivateComponent.newInstance(), blockEntity), new EventInfo(BeforeRemoveComponent.newInstance(), blockEntity)), checker.receivedEvents); }
@Ignore("Failing due to #2625. TODO: fix to match new behaviour") @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 testEmptyRegion() { assertEquals(Region3i.empty().size(), Vector3i.zero()); assertTrue(Region3i.empty().isEmpty()); }
@Test public void testBlockedAtTopSunlightRegenPropagationResets() { Chunk chunk = new ChunkImpl(0, 0, 0, blockManager, biomeManager, extraDataManager); for (Vector3i pos : Region3i.createFromMinAndSize(new Vector3i(0, 63, 0), new Vector3i(ChunkConstants.SIZE_X, 1, ChunkConstants.SIZE_Z))) { chunk.setBlock(pos, solidBlock); } InternalLightProcessor.generateInternalLighting(chunk); for (Vector3i pos : Region3i.createFromMinAndSize(Vector3i.zero(), new Vector3i(ChunkConstants.SIZE_X, ChunkConstants.SIZE_Y - 1, ChunkConstants.SIZE_Z))) { byte expectedRegen = (byte) Math.min(ChunkConstants.SIZE_Y - pos.y - 2, ChunkConstants.MAX_SUNLIGHT_REGEN); assertEquals(expectedRegen, chunk.getSunlightRegen(pos)); } }
@Test public void testChangedComponentsRevertedBeforeCleanUp() { worldStub.setBlock(Vector3i.zero(), blockWithString); EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0)); StringComponent comp = entity.getComponent(StringComponent.class); comp.value = "Moo"; entity.saveComponent(comp); LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class); worldProvider.update(1.0f); assertEquals(Lists.newArrayList(new EventInfo(OnChangedComponent.newInstance(), entity)), checker.receivedEvents); }
@Test public void testEntityMissingComponentsAddedBeforeCleanUp() { worldStub.setBlock(Vector3i.zero(), blockWithString); EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0)); entity.removeComponent(StringComponent.class); LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class); worldProvider.update(1.0f); assertEquals(Lists.newArrayList(new EventInfo(OnAddedComponent.newInstance(), entity), new EventInfo(OnActivatedComponent.newInstance(), entity)), checker.receivedEvents); }
@Test public void testLocalToWorld() { Chunk chunk = createChunk(1, 0, 1); chunk.setBlock(new Vector3i(0, 0, 0), solidBlock); Chunk[] chunks = new Chunk[]{createChunk(0, 0, 0), createChunk(1, 0, 0), createChunk(2, 0, 0), createChunk(0, 0, 1), chunk, createChunk(2, 0, 1), createChunk(0, 0, 2), createChunk(1, 0, 2), createChunk(2, 0, 2)}; ChunkViewCoreImpl chunkView = new ChunkViewCoreImpl(chunks, Region3i.createFromCenterExtents(new Vector3i(1, 0, 1), new Vector3i(1, 0, 1)), new Vector3i(1, 1, 1), airBlock); assertEquals(new Vector3i(ChunkConstants.SIZE_X, ChunkConstants.SIZE_Y, ChunkConstants.SIZE_Z), chunkView.toWorldPos(Vector3i.zero())); }