use of org.terasology.world.biomes.BiomeManager in project Terasology by MovingBlocks.
the class ReadWriteStorageManager method addGameManifestToSaveTransaction.
private void addGameManifestToSaveTransaction(SaveTransactionBuilder saveTransactionBuilder) {
BlockManager blockManager = CoreRegistry.get(BlockManager.class);
BiomeManager biomeManager = CoreRegistry.get(BiomeManager.class);
WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
Time time = CoreRegistry.get(Time.class);
Game game = CoreRegistry.get(Game.class);
GameManifest gameManifest = new GameManifest(game.getName(), game.getSeed(), time.getGameTimeInMs());
for (Module module : CoreRegistry.get(ModuleManager.class).getEnvironment()) {
gameManifest.addModule(module.getId(), module.getVersion());
}
List<String> registeredBlockFamilies = Lists.newArrayList();
for (BlockFamily family : blockManager.listRegisteredBlockFamilies()) {
registeredBlockFamilies.add(family.getURI().toString());
}
gameManifest.setRegisteredBlockFamilies(registeredBlockFamilies);
gameManifest.setBlockIdMap(blockManager.getBlockIdMap());
List<Biome> biomes = biomeManager.getBiomes();
Map<String, Short> biomeIdMap = new HashMap<>(biomes.size());
for (Biome biome : biomes) {
short shortId = biomeManager.getBiomeShortId(biome);
String id = biomeManager.getBiomeId(biome);
biomeIdMap.put(id, shortId);
}
gameManifest.setBiomeIdMap(biomeIdMap);
gameManifest.addWorld(worldProvider.getWorldInfo());
saveTransactionBuilder.setGameManifest(gameManifest);
}
use of org.terasology.world.biomes.BiomeManager in project Terasology by MovingBlocks.
the class TreeTests method setup.
@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);
Mockito.when(blockManager.getBlock(Matchers.<BlockUri>any())).thenReturn(air);
Mockito.when(blockManager.getBlock(Matchers.<String>any())).thenReturn(air);
context.put(BlockManager.class, blockManager);
}
use of org.terasology.world.biomes.BiomeManager in project Terasology by MovingBlocks.
the class InitialiseWorld method step.
@Override
public boolean step() {
BlockManager blockManager = context.get(BlockManager.class);
BiomeManager biomeManager = context.get(BiomeManager.class);
ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
context.put(WorldGeneratorPluginLibrary.class, new DefaultWorldGeneratorPluginLibrary(environment, context));
WorldInfo worldInfo = gameManifest.getWorldInfo(TerasologyConstants.MAIN_WORLD);
if (worldInfo.getSeed() == null || worldInfo.getSeed().isEmpty()) {
FastRandom random = new FastRandom();
worldInfo.setSeed(random.nextString(16));
}
logger.info("World seed: \"{}\"", worldInfo.getSeed());
// TODO: Separate WorldRenderer from world handling in general
WorldGeneratorManager worldGeneratorManager = context.get(WorldGeneratorManager.class);
WorldGenerator worldGenerator;
try {
worldGenerator = WorldGeneratorManager.createGenerator(worldInfo.getWorldGenerator(), context);
// setting the world seed will create the world builder
worldGenerator.setWorldSeed(worldInfo.getSeed());
context.put(WorldGenerator.class, worldGenerator);
} catch (UnresolvedWorldGeneratorException e) {
logger.error("Unable to load world generator {}. Available world generators: {}", worldInfo.getWorldGenerator(), worldGeneratorManager.getWorldGenerators());
context.get(GameEngine.class).changeState(new StateMainMenu("Failed to resolve world generator."));
// We need to return true, otherwise the loading state will just call us again immediately
return true;
}
// Init. a new world
EngineEntityManager entityManager = (EngineEntityManager) context.get(EntityManager.class);
boolean writeSaveGamesEnabled = context.get(Config.class).getSystem().isWriteSaveGamesEnabled();
Path savePath = PathManager.getInstance().getSavePath(gameManifest.getTitle());
StorageManager storageManager;
try {
storageManager = writeSaveGamesEnabled ? new ReadWriteStorageManager(savePath, environment, entityManager, blockManager, biomeManager) : new ReadOnlyStorageManager(savePath, environment, entityManager, blockManager, biomeManager);
} catch (IOException e) {
logger.error("Unable to create storage manager!", e);
context.get(GameEngine.class).changeState(new StateMainMenu("Unable to create storage manager!"));
// We need to return true, otherwise the loading state will just call us again immediately
return true;
}
context.put(StorageManager.class, storageManager);
LocalChunkProvider chunkProvider = new LocalChunkProvider(storageManager, entityManager, worldGenerator, blockManager, biomeManager);
context.get(ComponentSystemManager.class).register(new RelevanceSystem(chunkProvider), "engine:relevanceSystem");
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);
context.put(WorldProvider.class, worldProvider);
chunkProvider.setBlockEntityRegistry(entityWorldProvider);
context.put(BlockEntityRegistry.class, entityWorldProvider);
context.get(ComponentSystemManager.class).register(entityWorldProvider, "engine:BlockEntityRegistry");
DefaultCelestialSystem celestialSystem = new DefaultCelestialSystem(new BasicCelestialModel(), context);
context.put(CelestialSystem.class, celestialSystem);
context.get(ComponentSystemManager.class).register(celestialSystem);
Skysphere skysphere = new Skysphere(context);
BackdropProvider backdropProvider = skysphere;
BackdropRenderer backdropRenderer = skysphere;
context.put(BackdropProvider.class, backdropProvider);
context.put(BackdropRenderer.class, backdropRenderer);
RenderingSubsystemFactory engineSubsystemFactory = context.get(RenderingSubsystemFactory.class);
WorldRenderer worldRenderer = engineSubsystemFactory.createWorldRenderer(context);
context.put(WorldRenderer.class, worldRenderer);
// TODO: These shouldn't be done here, nor so strongly tied to the world renderer
context.put(LocalPlayer.class, new LocalPlayer());
context.put(Camera.class, worldRenderer.getActiveCamera());
return true;
}
use of org.terasology.world.biomes.BiomeManager in project Terasology by MovingBlocks.
the class StorageManagerTest method setup.
@Before
public void setup() throws Exception {
super.setup();
JavaArchive homeArchive = ShrinkWrap.create(JavaArchive.class);
FileSystem vfs = ShrinkWrapFileSystems.newFileSystem(homeArchive);
PathManager.getInstance().useOverrideHomePath(temporaryFolder.getRoot().toPath());
savePath = PathManager.getInstance().getSavePath("testSave");
assert !Files.isRegularFile(vfs.getPath("global.dat"));
entityManager = context.get(EngineEntityManager.class);
moduleEnvironment = context.get(ModuleEnvironment.class);
blockManager = context.get(BlockManager.class);
biomeManager = context.get(BiomeManager.class);
esm = new ReadWriteStorageManager(savePath, moduleEnvironment, entityManager, blockManager, biomeManager, false);
context.put(StorageManager.class, esm);
this.character = entityManager.create();
Client client = createClientMock(PLAYER_ID, character);
NetworkSystem networkSystem = mock(NetworkSystem.class);
when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
when(networkSystem.getPlayers()).thenReturn(Arrays.asList(client));
context.put(NetworkSystem.class, networkSystem);
AssetManager assetManager = context.get(AssetManager.class);
BlockFamilyDefinitionData data = new BlockFamilyDefinitionData();
data.setFamilyFactory(new SymmetricBlockFamilyFactory());
assetManager.loadAsset(new ResourceUrn("test:testblock"), data, BlockFamilyDefinition.class);
assetManager.loadAsset(new ResourceUrn("test:testblock2"), data, BlockFamilyDefinition.class);
testBlock = context.get(BlockManager.class).getBlock("test:testblock");
testBlock2 = context.get(BlockManager.class).getBlock("test:testblock2");
context.put(ChunkProvider.class, mock(ChunkProvider.class));
BiomeManager mockBiomeManager = mock(BiomeManager.class);
when(mockBiomeManager.getBiomes()).thenReturn(Collections.<Biome>emptyList());
context.put(BiomeManager.class, mockBiomeManager);
WorldProvider worldProvider = mock(WorldProvider.class);
when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
context.put(WorldProvider.class, worldProvider);
}
use of org.terasology.world.biomes.BiomeManager in project Terasology by MovingBlocks.
the class RegisterBiomes method step.
@Override
public boolean step() {
NetworkSystem networkSystem = context.get(NetworkSystem.class);
ModuleEnvironment moduleEnvironment = context.get(ModuleManager.class).getEnvironment();
BiomeManager biomeManager;
if (networkSystem.getMode().isAuthority()) {
biomeManager = new BiomeManager(moduleEnvironment, gameManifest.getBiomeIdMap());
// biomeManager.subscribe(CoreRegistry.get(NetworkSystem.class));
// TODO figure out what this does
} else {
biomeManager = new BiomeManager(moduleEnvironment, gameManifest.getBiomeIdMap());
}
context.put(BiomeManager.class, biomeManager);
// This registration is for other modules
context.put(BiomeRegistry.class, biomeManager);
return true;
}
Aggregations