Ejemplo n.º 1
0
        private void ScheduleLightingUpdate(BlockCoordinates coordinates, bool blockLight = false)
        {
            var chunkCoords = new ChunkCoordinates(coordinates.X >> 4, coordinates.Z >> 4);

            ChunkColumn chunk;

            if (ChunkManager.TryGetChunk(chunkCoords, out chunk))
            {
                var cx = coordinates.X & 0xf;
                var cy = coordinates.Y & 0xff;
                var cz = coordinates.Z & 0xf;

                if (blockLight)
                {
                    chunk.ScheduleBlocklightUpdate(cx, cy, cz);
                }
                else
                {
                    chunk.ScheduleSkylightUpdate(cx, cy, cz);
                }
            }
        }
Ejemplo n.º 2
0
        public void SetBlock(Block block)
        {
            var x = block.Coordinates.X;
            var y = block.Coordinates.Y;
            var z = block.Coordinates.Z;

            var chunkCoords = new ChunkCoordinates(x >> 4, z >> 4);

            IChunkColumn chunk;

            if (ChunkManager.TryGetChunk(chunkCoords, out chunk))
            {
                var cx = x & 0xf;
                var cy = y & 0xff;
                var cz = z & 0xf;

                chunk.SetBlock(cx, cy, cz, block);
                ChunkManager.ScheduleChunkUpdate(new ChunkCoordinates(x >> 4, z >> 4), ScheduleType.Scheduled | ScheduleType.Lighting, true);

                UpdateNeighbors(x, y, z);
                CheckForUpdate(chunkCoords, cx, cz);
            }
        }
Ejemplo n.º 3
0
        public void SetBlockLight(BlockCoordinates coordinates, byte value)
        {
            var         chunkCoords = new ChunkCoordinates(coordinates);
            ChunkColumn chunk;

            if (ChunkManager.TryGetChunk(chunkCoords, out chunk))
            {
                if (chunk.SetBlocklight(coordinates.X & 0xf, coordinates.Y & 0xff, coordinates.Z & 0xf, value))
                {
                    var x = coordinates.X;
                    var y = coordinates.Y;
                    var z = coordinates.Z;

                    ScheduleLightingUpdate(new BlockCoordinates(x + 1, y, z), true);
                    ScheduleLightingUpdate(new BlockCoordinates(x + -1, y, z), true);

                    ScheduleLightingUpdate(new BlockCoordinates(x, y, z + 1), true);
                    ScheduleLightingUpdate(new BlockCoordinates(x, y, z + -1), true);

                    ScheduleLightingUpdate(new BlockCoordinates(x, y + 1, z), true);
                    ScheduleLightingUpdate(new BlockCoordinates(x, y + -1, z), true);
                }
            }
        }
Ejemplo n.º 4
0
        public void SetSkyLight(BlockCoordinates coordinates, byte p1)
        {
            var         chunkCoords = new ChunkCoordinates(coordinates);
            ChunkColumn chunk;

            if (ChunkManager.TryGetChunk(chunkCoords, out chunk))
            {
                if (chunk.SetSkyLight(coordinates.X & 0xf, coordinates.Y & 0xff, coordinates.Z & 0xf, p1))
                {
                    var x = coordinates.X;
                    var y = coordinates.Y;
                    var z = coordinates.Z;

                    ScheduleLightingUpdate(new BlockCoordinates(x + 1, y, z));
                    ScheduleLightingUpdate(new BlockCoordinates(x - 1, y, z));

                    ScheduleLightingUpdate(new BlockCoordinates(x, y, z + 1));
                    ScheduleLightingUpdate(new BlockCoordinates(x, y, z - 1));

                    ScheduleLightingUpdate(new BlockCoordinates(x, y + 1, z));
                    ScheduleLightingUpdate(new BlockCoordinates(x, y - 1, z));
                }
            }
        }
Ejemplo n.º 5
0
 public void ChunkUpdate(IChunkColumn chunkColumn, ScheduleType type = ScheduleType.Lighting)
 {
     ChunkManager.ScheduleChunkUpdate(new ChunkCoordinates(chunkColumn.X, chunkColumn.Z), type);
 }
Ejemplo n.º 6
0
 public BlockCoordinates FindBlockPosition(BlockCoordinates coords, out IChunkColumn chunk)
 {
     ChunkManager.TryGetChunk(new ChunkCoordinates(coords.X >> 4, coords.Z >> 4), out chunk);
     return(new BlockCoordinates(coords.X & 0xf, coords.Y & 0xff, coords.Z & 0xf));
 }
Ejemplo n.º 7
0
 public void RebuildChunks()
 {
     ChunkManager.RebuildAll();
 }
Ejemplo n.º 8
0
 public void ResetChunks()
 {
     ChunkManager.ClearChunks();
 }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
0
 public void UnloadChunk(ChunkCoordinates coordinates)
 {
     ChunkManager.RemoveChunk(coordinates);
     EntityManager.UnloadEntities(coordinates);
 }
Ejemplo n.º 11
0
 public void ClearChunksAndEntities()
 {
     EntityManager.ClearEntities();
     ChunkManager.ClearChunks();
 }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
 public SkyLightBlockAccess(ChunkManager worldProvider, ChunkColumn chunk) : this(worldProvider, -1)
 {
     _chunk = chunk;
     _coord = new ChunkCoordinates(chunk.X, chunk.Z);
 }
Ejemplo n.º 14
0
 public SkyLightBlockAccess(ChunkManager worldProvider, int heightForUnloadedChunk = 255)
 {
     _worldProvider          = worldProvider;
     _heightForUnloadedChunk = heightForUnloadedChunk;
 }