コード例 #1
0
        public World(IServiceProvider serviceProvider, GraphicsDevice graphics, AlexOptions options, Camera camera,
                     INetworkProvider networkProvider)
        {
            Graphics = graphics;
            Camera   = camera;
            Options  = options;

            PhysicsEngine = new PhysicsManager(this);
            ChunkManager  = new ChunkManager(serviceProvider, graphics, this);
            EntityManager = new EntityManager(graphics, this, networkProvider);
            Ticker        = new TickManager();
            PlayerList    = new PlayerList();

            ChunkManager.Start();
            var settings       = serviceProvider.GetRequiredService <IOptionsProvider>();
            var profileService = serviceProvider.GetRequiredService <IPlayerProfileService>();
            var resources      = serviceProvider.GetRequiredService <ResourceManager>();

            EventDispatcher = serviceProvider.GetRequiredService <IEventDispatcher>();

            string username = string.Empty;
            Skin   skin     = profileService?.CurrentProfile?.Skin;

            if (skin == null)
            {
                resources.ResourcePack.TryGetBitmap("entity/alex", out var rawTexture);
                var t = TextureUtils.BitmapToTexture2D(graphics, rawTexture);
                skin = new Skin()
                {
                    Texture = t,
                    Slim    = true
                };
            }

            if (!string.IsNullOrWhiteSpace(profileService?.CurrentProfile?.Username))
            {
                username = profileService.CurrentProfile.Username;
            }

            Player = new Player(graphics, serviceProvider.GetRequiredService <Alex>().InputManager, username, this, skin, networkProvider, PlayerIndex.One, camera);

            Player.KnownPosition = new PlayerLocation(GetSpawnPoint());
            Camera.MoveTo(Player.KnownPosition, Vector3.Zero);

            Options.FieldOfVision.ValueChanged += FieldOfVisionOnValueChanged;
            Camera.FOV = Options.FieldOfVision.Value;

            PhysicsEngine.AddTickable(Player);

            if (networkProvider is BedrockClient)
            {
                Player.SetInventory(new BedrockInventory(46));
            }
            //	Player.Inventory.IsPeInventory = true;

            /*if (ItemFactory.TryGetItem("minecraft:diamond_sword", out var sword))
             * {
             *      Player.Inventory[Player.Inventory.SelectedSlot] = sword;
             *      Player.Inventory.MainHand = sword;
             * }
             * else
             * {
             *      Log.Warn($"Could not get diamond sword!");
             * }*/

            EventDispatcher.RegisterEvents(this);

            FormManager = new BedrockFormManager(networkProvider, serviceProvider.GetRequiredService <GuiManager>(), serviceProvider.GetService <Alex>().InputManager);

            SkyRenderer = new SkyBox(serviceProvider, graphics, this);
            //SkyLightCalculations = new SkyLightCalculations();

            UseDepthMap = options.VideoOptions.Depthmap;
            options.VideoOptions.Depthmap.Bind((old, newValue) => { UseDepthMap = newValue; });

            ServerType = (networkProvider is BedrockClient) ? ServerType.Bedrock : ServerType.Java;
        }
コード例 #2
0
ファイル: World.cs プロジェクト: PocketGold-MP/Alex
        public World(IServiceProvider serviceProvider, GraphicsDevice graphics, AlexOptions options,
                     NetworkProvider networkProvider)
        {
            Graphics = graphics;
            Options  = options;

            PhysicsEngine = new PhysicsManager(this);
            ChunkManager  = new ChunkManager(serviceProvider, graphics, this);
            EntityManager = new EntityManager(graphics, this, networkProvider);
            Ticker        = new TickManager();
            PlayerList    = new PlayerList();

            Ticker.RegisterTicked(this);
            Ticker.RegisterTicked(EntityManager);
            //Ticker.RegisterTicked(PhysicsEngine);
            Ticker.RegisterTicked(ChunkManager);

            ChunkManager.Start();
            var profileService = serviceProvider.GetRequiredService <IPlayerProfileService>();
            var resources      = serviceProvider.GetRequiredService <ResourceManager>();

            EventDispatcher = serviceProvider.GetRequiredService <IEventDispatcher>();

            string          username = string.Empty;
            PooledTexture2D texture;

            if (Alex.PlayerTexture != null)
            {
                texture = TextureUtils.BitmapToTexture2D(graphics, Alex.PlayerTexture);
            }
            else
            {
                resources.ResourcePack.TryGetBitmap("entity/alex", out var rawTexture);
                texture = TextureUtils.BitmapToTexture2D(graphics, rawTexture);
            }

            Skin skin = profileService?.CurrentProfile?.Skin;

            if (skin == null)
            {
                skin = new Skin()
                {
                    Texture = texture,
                    Slim    = true
                };
            }

            if (!string.IsNullOrWhiteSpace(profileService?.CurrentProfile?.Username))
            {
                username = profileService.CurrentProfile.Username;
            }

            Player = new Player(graphics, serviceProvider.GetRequiredService <Alex>().InputManager, username, this, skin, networkProvider, PlayerIndex.One);
            Camera = new EntityCamera(Player);

            if (Alex.PlayerModel != null)
            {
                EntityModelRenderer modelRenderer = new EntityModelRenderer(Alex.PlayerModel, texture);

                if (modelRenderer.Valid)
                {
                    Player.ModelRenderer = modelRenderer;
                }
            }

            Player.KnownPosition = new PlayerLocation(GetSpawnPoint());

            Options.FieldOfVision.ValueChanged += FieldOfVisionOnValueChanged;
            Camera.FOV = Options.FieldOfVision.Value;

            PhysicsEngine.AddTickable(Player);

            EventDispatcher.RegisterEvents(this);

            var guiManager = serviceProvider.GetRequiredService <GuiManager>();

            InventoryManager = new InventoryManager(guiManager);

            SkyRenderer = new SkyBox(serviceProvider, graphics, this);

            options.VideoOptions.RenderDistance.Bind(
                (old, newValue) =>
            {
                Camera.SetRenderDistance(newValue);
            });
            Camera.SetRenderDistance(options.VideoOptions.RenderDistance);
        }