@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()); }
@Override public EntityRef getBlockEntityAt(Vector3i blockPosition) { if (GameThread.isCurrentThread()) { EntityRef blockEntity = getExistingBlockEntityAt(blockPosition); if ((!blockEntity.exists() || !blockEntity.hasComponent(NetworkComponent.class)) && isBlockRelevant(blockPosition.x, blockPosition.y, blockPosition.z)) { Block block = getBlock(blockPosition.x, blockPosition.y, blockPosition.z); blockEntity = createBlockEntity(blockPosition, block); } return blockEntity; } logger.error("Attempted to get block entity off-thread"); return EntityRef.NULL; }
@Override public EntityRef getEntityAt(Vector3i blockPosition) { if (GameThread.isCurrentThread()) { EntityRef entity = getExistingEntityAt(blockPosition); if (!entity.exists()) { return getBlockEntityAt(blockPosition); } return entity; } logger.error("Attempted to get block entity off-thread"); return EntityRef.NULL; }
@Override public Block setBlockForceUpdateEntity(Vector3i pos, Block type) { if (GameThread.isCurrentThread()) { EntityRef blockEntity = getBlockEntityAt(pos); Block oldType = super.setBlock(pos, type); if (oldType != null) { updateBlockEntity(blockEntity, pos, oldType, type, true, Collections.<Class<? extends Component>>emptySet()); } return oldType; } return null; }
@Ignore("Failing due to #2625. TODO: fix to match new behaviour") @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 testEntityBecomesTemporaryIfForceBlockActiveComponentRemoved() { EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0)); blockEntity.addComponent(new ForceBlockActiveComponent()); worldProvider.update(1.0f); blockEntity.removeComponent(ForceBlockActiveComponent.class); worldProvider.update(1.0f); assertFalse(blockEntity.exists()); assertFalse(blockEntity.isActive()); }
public void setupWorldProvider(WorldGenerator generator) { generator.initialize(); WorldProviderCore stub = new MapWorldProvider(generator, context.get(BlockManager.class), Mockito.mock(BiomeManager.class), context.get(ExtraBlockDataManager.class)); WorldProvider world = new WorldProviderWrapper(stub, context.get(ExtraBlockDataManager.class)); CoreRegistry.put(WorldProvider.class, world); CoreRegistry.put(BlockEntityRegistry.class, new EntityAwareWorldProvider(stub, context)); }
@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)); }
@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(); }
@Override public EntityRef getBlockEntityAt(Vector3f position) { Vector3i pos = new Vector3i(position, RoundingMode.HALF_UP); return getBlockEntityAt(pos); }
@Override public void onEntityComponentRemoved(EntityRef entity, Class<? extends Component> component) { if (entityManager.getComponentLibrary().getMetadata(component).isForceBlockActive()) { BlockComponent blockComp = entity.getComponent(BlockComponent.class); if (blockComp != null) { Block block = getBlock(blockComp.position.x, blockComp.position.y, blockComp.position.z); if (isTemporaryBlock(entity, block, component)) { temporaryBlockEntities.add(entity); } } } }
@Override public EntityRef getExistingEntityAt(Vector3i blockPosition) { if (GameThread.isCurrentThread()) { EntityRef result = blockRegionLookup.get(blockPosition); if (result == null) { return getExistingBlockEntityAt(blockPosition); } return result; } logger.error("Attempted to get block entity off-thread"); return EntityRef.NULL; }
public EntityAwareWorldProvider(WorldProviderCore base, Context context) { super(base); entityManager = (EngineEntityManager) context.get(EntityManager.class); context.get(ComponentSystemManager.class).register(getTime()); }
copyIntoPrefab(blockEntity, comp, retainComponents);
@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 testEntityNotRemovedIfForceBlockActiveComponentAdded() { EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i(0, 0, 0)); blockEntity.addComponent(new ForceBlockActiveComponent()); worldProvider.update(1.0f); assertTrue(blockEntity.exists()); assertTrue(blockEntity.isActive()); }
Block unloadedBlock = blockManager.getBlock(BlockManager.UNLOADED_ID); WorldProviderCoreImpl worldProviderCore = new WorldProviderCoreImpl(worldInfo, chunkProvider, unloadedBlock, context); EntityAwareWorldProvider entityWorldProvider = new EntityAwareWorldProvider(worldProviderCore, context); WorldProvider worldProvider = new WorldProviderWrapper(entityWorldProvider, extraDataManager); context.put(WorldProvider.class, worldProvider);
@Override public Block setBlock(Vector3i pos, Block type) { if (GameThread.isCurrentThread()) { EntityRef blockEntity = getBlockEntityAt(pos); Block oldType = super.setBlock(pos, type); if (oldType != null) { updateBlockEntity(blockEntity, pos, oldType, type, false, Collections.<Class<? extends Component>>emptySet()); } return oldType; } return null; }
@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)); }