コード例 #1
0
        public Player(GraphicsDevice graphics, InputManager inputManager, string name, World world, Skin skin, NetworkProvider networkProvider, PlayerIndex playerIndex, Camera camera) : base(name, world, networkProvider, skin.Texture)
        {
            World = world;
            //	DoRotationCalculations = false;
            PlayerIndex = playerIndex;
            Controller  = new PlayerController(graphics, world, inputManager, this, playerIndex);
            Camera      = camera;
            NoAi        = false;

            //Inventory = new Inventory(46);
            //Inventory.SelectedHotbarSlotChanged += SelectedHotbarSlotChanged;
            //base.Inventory.IsPeInventory = true;
            MovementSpeed     = 0.1f;
            BaseMovementSpeed = 0.21585;    //4.317;
            FlyingSpeed       = 0.5f;       //10.89f;

            SnapHeadYawRotationOnMovement = false;
            SnapYawRotationOnMovement     = true;
            DoRotationCalculations        = false;

            RenderEntity   = true;
            ShowItemInHand = true;

            ServerEntity = false;
        }
コード例 #2
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;
        }
コード例 #3
0
ファイル: Player.cs プロジェクト: CiviledCode/Alex
        //public Camera Camera { get; internal set; }
        public Player(GraphicsDevice graphics, InputManager inputManager, string name, World world, Skin skin, NetworkProvider networkProvider, PlayerIndex playerIndex) : base(name, world, networkProvider, skin.Texture)
        {
            //IsSpawned = true;
            //	DoRotationCalculations = false;
            PlayerIndex = playerIndex;
            Controller  = new PlayerController(graphics, world, inputManager, this, playerIndex);
            // Camera = camera;
            // NoAi = false;

            //Inventory = new Inventory(46);
            //Inventory.SelectedHotbarSlotChanged += SelectedHotbarSlotChanged;
            //base.Inventory.IsPeInventory = true;
            //MovementSpeed = 0.1f;
            //	BaseMovementSpeed = 0.21585;//4.317;
            //	FlyingSpeed = 0.5f; //10.89f;

            SnapHeadYawRotationOnMovement = false;
            SnapYawRotationOnMovement     = true;
            DoRotationCalculations        = false;

            RenderEntity   = true;
            ShowItemInHand = true;

            ServerEntity         = false;
            RequiresRealTimeTick = true;
            AlwaysTick           = true;

            IsAffectedByGravity = true;
            HasPhysics          = true;
        }
コード例 #4
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);
        }