/** Init. a new random world. */ public void initWorld(String title, String seed) { final FastRandom random = new FastRandom(); // Get rid of the old world if (_worldRenderer != null) { _worldRenderer.dispose(); _worldRenderer = null; } if (seed == null) { seed = random.randomCharacterString(16); } else if (seed.isEmpty()) { seed = random.randomCharacterString(16); } Terasology.getInstance() .getLogger() .log(Level.INFO, "Creating new World with seed \"{0}\"", seed); // Init. a new world _worldRenderer = new WorldRenderer(title, seed, _entityManager, _localPlayerSys); File entityDataFile = new File(Terasology.getInstance().getWorldSavePath(title), ENTITY_DATA_FILE); _entityManager.clear(); if (entityDataFile.exists()) { try { _entityManager.load(entityDataFile, EntityManager.SaveFormat.Binary); } catch (IOException e) { _logger.log(Level.SEVERE, "Failed to load entity data", e); } } LocalPlayer localPlayer = null; Iterator<EntityRef> iterator = _entityManager.iteratorEntities(LocalPlayerComponent.class).iterator(); if (iterator.hasNext()) { localPlayer = new LocalPlayer(iterator.next()); } else { PlayerFactory playerFactory = new PlayerFactory(_entityManager); localPlayer = new LocalPlayer( playerFactory.newInstance( new Vector3f(_worldRenderer.getWorldProvider().nextSpawningPoint()))); } _worldRenderer.setPlayer(localPlayer); // Create the first Portal if it doesn't exist yet _worldRenderer.initPortal(); fastForwardWorld(); CoreRegistry.put(WorldRenderer.class, _worldRenderer); CoreRegistry.put(IWorldProvider.class, _worldRenderer.getWorldProvider()); CoreRegistry.put(LocalPlayer.class, _worldRenderer.getPlayer()); CoreRegistry.put(Camera.class, _worldRenderer.getActiveCamera()); CoreRegistry.put(BulletPhysicsRenderer.class, _worldRenderer.getBulletRenderer()); for (ComponentSystem system : _componentSystemManager.iterateAll()) { system.initialise(); } }
public void init() { _hud = new UIHeadsUpDisplay(); _hud.setVisible(true); _pauseMenu = new UIPauseMenu(); _loadingScreen = new UILoadingScreen(); _statusScreen = new UIStatusScreen(); _inventoryScreen = new UIInventoryScreen(); _metrics = new UIMetrics(); _metrics.setVisible(true); _guiScreens.add(_metrics); _guiScreens.add(_hud); _guiScreens.add(_pauseMenu); _guiScreens.add(_loadingScreen); _guiScreens.add(_inventoryScreen); _guiScreens.add(_statusScreen); PojoEntityManager entityManager = new PojoEntityManager(); entityManager.registerTypeHandler(BlockFamily.class, new BlockFamilyTypeHandler()); entityManager.registerTypeHandler(Color4f.class, new Color4fTypeHandler()); entityManager.registerTypeHandler(Quat4f.class, new Quat4fTypeHandler()); entityManager.registerTypeHandler( Sound.class, new SoundTypeHandler(AudioManager.getInstance())); entityManager.registerTypeHandler(Vector3f.class, new Vector3fTypeHandler()); entityManager.registerTypeHandler(Vector2f.class, new Vector2fTypeHandler()); entityManager.registerTypeHandler(Vector3i.class, new Vector3iTypeHandler()); // TODO: Use reflection pending mod support entityManager.registerComponentClass(ExplosionActionComponent.class); entityManager.registerComponentClass(PlaySoundActionComponent.class); entityManager.registerComponentClass(TunnelActionComponent.class); entityManager.registerComponentClass(AABBCollisionComponent.class); entityManager.registerComponentClass(BlockComponent.class); entityManager.registerComponentClass(BlockItemComponent.class); entityManager.registerComponentClass(BlockParticleEffectComponent.class); entityManager.registerComponentClass(CameraComponent.class); entityManager.registerComponentClass(CharacterMovementComponent.class); entityManager.registerComponentClass(CharacterSoundComponent.class); entityManager.registerComponentClass(HealthComponent.class); entityManager.registerComponentClass(InventoryComponent.class); entityManager.registerComponentClass(ItemComponent.class); entityManager.registerComponentClass(LightComponent.class); entityManager.registerComponentClass(LocalPlayerComponent.class); entityManager.registerComponentClass(LocationComponent.class); entityManager.registerComponentClass(MeshComponent.class); entityManager.registerComponentClass(PlayerComponent.class); entityManager.registerComponentClass(SimpleAIComponent.class); entityManager.registerComponentClass(AccessInventoryActionComponent.class); _entityManager = entityManager; _entityManager.setEventSystem(new PojoEventSystem(_entityManager)); CoreRegistry.put(EntityManager.class, _entityManager); _componentSystemManager = new ComponentSystemManager(); CoreRegistry.put(ComponentSystemManager.class, _componentSystemManager); PrefabManager prefabManager = new PojoPrefabManager(); CoreRegistry.put(PrefabManager.class, prefabManager); entityManager.setPrefabManager(prefabManager); loadPrefabs(); _componentSystemManager.register(new BlockEntityRegistry()); _componentSystemManager.register(new CharacterMovementSystem()); _componentSystemManager.register(new SimpleAISystem()); _componentSystemManager.register(new ItemSystem()); _componentSystemManager.register(new CharacterSoundSystem()); _localPlayerSys = new LocalPlayerSystem(); _componentSystemManager.register(_localPlayerSys); _componentSystemManager.register(new FirstPersonRenderer()); _componentSystemManager.register(new HealthSystem()); _componentSystemManager.register(new BlockEntitySystem()); _componentSystemManager.register(new BlockParticleEmitterSystem()); _componentSystemManager.register(new BlockDamageRenderer()); _componentSystemManager.register(new InventorySystem()); _componentSystemManager.register(new MeshRenderer()); _componentSystemManager.register(new ExplosionAction()); _componentSystemManager.register(new PlaySoundAction()); _componentSystemManager.register(new TunnelAction()); _componentSystemManager.register(new AccessInventoryAction()); }