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; }
@Override public BehaviorTreeData load(ResourceUrn resourceUrn, List<AssetDataFile> list) throws IOException { BehaviorTreeBuilder builder = CoreRegistry.get(BehaviorTreeBuilder.class); if (builder == null) { builder = new BehaviorTreeBuilder(); CoreRegistry.put(BehaviorTreeBuilder.class, builder); } try (InputStream stream = list.get(0).openStream()) { return load(stream); } }
/** * Check if CoreRegistry returns null on its methods when the context is not defined. */ @Test public void testNullReturnOnMissingContext() { CoreRegistry.setContext(null); assertEquals(CoreRegistry.put(Integer.class, 10), null); assertEquals(CoreRegistry.get(Integer.class), null); }
/** * Check if the context is changed with setContext method. */ @Test public void testContextChange() { CoreRegistry.setContext(new ContextImplementation()); assertNotEquals(CoreRegistry.get(Context.class), context); }
@BeforeClass public static void setUpClass() throws Exception { Config config = new Config(new MockContext()); CoreRegistry.setContext(new ContextImpl()); CoreRegistry.put(Config.class, config); }
public static void share(Object object) { Share share = object.getClass().getAnnotation(Share.class); if (share != null && share.value() != null) { for (Class interfaceType : share.value()) { CoreRegistry.put(interfaceType, object); } } }
/** * Check if the CoreRegistry is calling the methods of its Context */ @Test public void testContextMethodsCalled() { // Load value in context Integer value = 10; CoreRegistry.put(Integer.class, value); assertEquals(value, context.get(Integer.class)); assertEquals(context.get(Integer.class), CoreRegistry.get(Integer.class)); // Change context CoreRegistry.setContext(new ContextImplementation()); assertNotEquals(CoreRegistry.get(Context.class), context); assertEquals(CoreRegistry.get(Integer.class), null); // Restore first context CoreRegistry.setContext(context); assertEquals(CoreRegistry.get(Integer.class), value); }
@Test public void testRegionPositions() { CoreRegistry.setContext(new ContextImpl()); CoreRegistry.put(Config.class, new Config(new MockContext())); assertEquals(1, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(0, 0, 0))).length); assertEquals(1, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(31, 63, 31))).length); assertEquals(2, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(32, 63, 31))).length); assertEquals(4, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(32, 63, 32))).length); assertEquals(8, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(32, 64, 32))).length); assertEquals(12, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(-1, 0, 0), new Vector3i(32, 64, 32))).length); Vector3i[] chunks = ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(32, 63, 31))); assertEquals(new Vector3i(0, 0, 0), chunks[0]); assertEquals(new Vector3i(1, 0, 0), chunks[1]); } }
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)); }
/** * 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); }
public BehaviorTreeData load(InputStream stream) { BehaviorTreeBuilder builder = CoreRegistry.get(BehaviorTreeBuilder.class); if (builder == null) { builder = new BehaviorTreeBuilder(); CoreRegistry.put(BehaviorTreeBuilder.class, builder); } BehaviorNode node = builder.fromJson(stream); BehaviorTreeData data = new BehaviorTreeData(); data.setRoot(node); return data; } }
/** * Create a Context implementation instance an assign it to CoreRegistry before testing. */ @Before public void setup() { context = new ContextImplementation(); CoreRegistry.setContext(context); }
@Test public void testStoreAndRestoreChunkStore() { Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, biomeManager, extraDataManager); chunk.setBlock(0, 0, 0, testBlock); chunk.markReady(); ChunkProvider chunkProvider = mock(ChunkProvider.class); when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk)); CoreRegistry.put(ChunkProvider.class, chunkProvider); esm.waitForCompletionOfPreviousSaveAndStartSaving(); esm.finishSavingAndShutdown(); ChunkStore restored = esm.loadChunkStore(CHUNK_POS); assertNotNull(restored); assertEquals(CHUNK_POS, restored.getChunkPosition()); assertNotNull(restored.getChunk()); assertEquals(testBlock, restored.getChunk().getBlock(0, 0, 0)); }
@Override public void initialize() { blockManager = CoreRegistry.get(BlockManager.class); }
@Before public void setup() { ContextImpl context = new ContextImpl(); CoreRegistry.setContext(context); // Needed only as long as #1536 is unresolved context.put(Config.class, new Config(new MockContext())); blockManager = Mockito.mock(BlockManager.class); Block air = blockManager.getBlock(BlockManager.AIR_ID); biomeManager = Mockito.mock(BiomeManager.class); extraDataManager = new ExtraBlockDataManager(); Mockito.when(blockManager.getBlock(Matchers.<BlockUri>any())).thenReturn(air); Mockito.when(blockManager.getBlock(Matchers.<String>any())).thenReturn(air); context.put(BlockManager.class, blockManager); }
private WorldProvider getWorldProvider() { return CoreRegistry.get(WorldProvider.class); } }
@Before public void setup() throws IOException { AssetManager assetManager = CoreRegistry.get(AssetManager.class); blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager); CoreRegistry.put(BlockManager.class, blockManager); airBlock = blockManager.getBlock(BlockManager.AIR_ID); biomeManager = Mockito.mock(BiomeManager.class); extraDataManager = new ExtraBlockDataManager(); BlockFamilyDefinitionData solidData = new BlockFamilyDefinitionData(); solidData.getBaseSection().setDisplayName("Stone"); solidData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get()); solidData.getBaseSection().setTranslucent(false); solidData.setBlockFamily(SymmetricFamily.class); assetManager.loadAsset(new ResourceUrn("engine:stone"), solidData, BlockFamilyDefinition.class); solidBlock = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone"))); }
@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()); }