private static <T> CommandParameterSuggester<T> optionallyCreateSuggestor( Class<? extends CommandParameterSuggester<T>> suggestorClass, Context context) { if (suggestorClass == null) { return null; } return InjectionHelper.createWithConstructorInjection(suggestorClass, context); }
void connectToEntitySystem(EngineEntityManager newEntityManager, NetworkEntitySerializer newEntitySerializer, EventSerializer newEventSerializer, BlockEntityRegistry newBlockEntityRegistry) { this.entityManager = newEntityManager; this.eventSerializer = newEventSerializer; this.entitySerializer = newEntitySerializer; this.blockEntityRegistry = newBlockEntityRegistry; blockManager = (BlockManagerImpl) CoreRegistry.get(BlockManager.class); biomeManager = CoreRegistry.get(BiomeManager.class); extraDataManager = CoreRegistry.get(ExtraBlockDataManager.class); }
/** * Cleans up all resources (similar to AutoCloseable) * * @throws Exception if something goes wrong */ public void close() throws Exception { CoreRegistry.setContext(null); context = null; }
/** * Check if the context is changed with setContext method. */ @Test public void testContextChange() { CoreRegistry.setContext(new ContextImplementation()); assertNotEquals(CoreRegistry.get(Context.class), context); }
@Test public void testShareRequiresShareAnnotation() { InjectionHelper.share(new ServiceAImplNoAnnotation()); assertThat(CoreRegistry.get(ServiceA.class), is(nullValue())); }
@Before public void setUp() { serviceA = new ServiceAImpl(); serviceB = new ServiceBImpl(); //injection helper uses the core registry, //make sure the shared classes are not used over multiple tests CoreRegistry.setContext(new ContextImpl()); }
/** * Create a Context implementation instance an assign it to CoreRegistry before testing. */ @Before public void setup() { context = new ContextImplementation(); CoreRegistry.setContext(context); }
@Share(ServiceB.class) private static class ServiceBImpl implements ServiceB { }
/** * Initialises: network system, join status, and module manager. * @param joinStatus * @param networkSystem */ public ClientConnectionHandler(JoinStatusImpl joinStatus, NetworkSystemImpl networkSystem) { this.networkSystem = networkSystem; this.joinStatus = joinStatus; // TODO: implement translation of errorMessage in messageReceived once context is available // See https://github.com/MovingBlocks/Terasology/pull/3332#discussion_r187081375 this.moduleManager = CoreRegistry.get(ModuleManager.class); }
@Share(ServiceA.class) private static class ServiceAImpl implements ServiceA { }
@Override public void initialize() { blockManager = CoreRegistry.get(BlockManager.class); }
private WorldProvider getWorldProvider() { return CoreRegistry.get(WorldProvider.class); } }
private WorldProvider getWorldProvider() { return CoreRegistry.get(WorldProvider.class); } }
@Override public boolean isAvailable() { return CoreRegistry.get(WorldRenderer.class) != null; }
private WorldProvider getWorldProvider() { return CoreRegistry.get(WorldProvider.class); } }
private BlockEntityRegistry getBlockEntityRegistry() { return CoreRegistry.get(BlockEntityRegistry.class); }
private BlockEntityRegistry getBlockEntityRegistry() { return CoreRegistry.get(BlockEntityRegistry.class); }
@Override public Matrix4f getProjectionMatrix() { RenderingStage renderingStage = CoreRegistry.get(WorldRenderer.class).getCurrentRenderStage(); if (renderingStage == RenderingStage.LEFT_EYE) { return projectionMatrixLeftEye; } else if (renderingStage == RenderingStage.RIGHT_EYE) { return projectionMatrixRightEye; } return null; }