Exemplo n.º 1
0
 public static void SaveChunkToAnvil(ChunkColumn chunk)
 {
     lock (_basePath)
     {
         AnvilWorldProvider.SaveChunk(chunk, _basePath);
     }
 }
Exemplo n.º 2
0
        public void SaveOneAnvilChunkTest()
        {
            int width = 32;
            int depth = 32;

            int cx = (width * 4) + 3;
            int cz = (depth * 25) + 0;

            AnvilWorldProvider anvil = new AnvilWorldProvider(@"D:\Development\Worlds\KingsLanding\");

            anvil.Initialize();

            ChunkCoordinates coordinates = new ChunkCoordinates(cx, cz);
            ChunkColumn      chunk       = anvil.GenerateChunkColumn(coordinates);

            Assert.NotNull(chunk);

            Stopwatch sw = new Stopwatch();

            sw.Start();

            anvil.SaveChunks();

            Assert.Less(sw.ElapsedMilliseconds, 1);
        }
Exemplo n.º 3
0
        public OpenLevel LoadLevel(string levelDirectory, string levelId)
        {
            var newLevelId = GetLevelId(levelId);

            /*	var worldProvider = new WrappedAnvilWorldProvider(Api, levelDirectory)
             *      {
             *              MissingChunkProvider = new FlatlandWorldProvider(),
             *              ReadSkyLight = !Config.GetProperty("CalculateLights", false),
             *              ReadBlockLight = !Config.GetProperty("CalculateLights", false),
             *      };*/
            var worldProvider = new AnvilWorldProvider(levelDirectory)
            {
                MissingChunkProvider = new SuperflatGenerator(Dimension.Overworld)
            };

            var openLevel = new OpenLevel(Api /*, Api.EventDispatcher*/, this, newLevelId, worldProvider, EntityManager, _gameMode, _difficulty, _viewDistance)
            {
                EnableBlockTicking = _enableBlockTicking,
                EnableChunkTicking = _enableChunkTicking,
                //	IsWorldTimeStarted = _isWorldTimeStarted
            };

            LoadLevel(openLevel);

            return(openLevel);
        }
Exemplo n.º 4
0
        public virtual Level GetLevel(Player player, string name)
        {
            Level level = Levels.FirstOrDefault(l => l.LevelId.Equals(name, StringComparison.InvariantCultureIgnoreCase));

            if (level == null)
            {
                AnvilWorldProvider worldProvider = new AnvilWorldProvider
                {
                    MissingChunkProvider = new FlatLandWorldGenerator(),
                    ReadSkyLight         = !Config.GetProperty("CalculateLights", false),
                    ReadBlockLight       = !Config.GetProperty("CalculateLights", false),
                };

                level = new Level(this, name, worldProvider, EntityManager, _gameMode, _difficulty, _viewDistance)
                {
                    EnableBlockTicking = _enableBlockTicking,
                    EnableChunkTicking = _enableChunkTicking,
                    IsWorldTimeStarted = _isWorldTimeStarted
                };
                level.Initialize();

                Levels.Add(level);

                OnLevelCreated(new LevelEventArgs(null, level));
            }

            return(level);
        }
Exemplo n.º 5
0
        public void OffsetFileExistPerformance()
        {
            var basePath = @"D:\Development\Repos\MapsPE\hub";
            var provider = new AnvilWorldProvider(basePath);

            provider.Initialize();

            var coordinates = new ChunkCoordinates(new PlayerLocation(-1021, 18, 2385));

            for (int i = 0; i < 10000; i++)
            {
                var chunk = provider.GenerateChunkColumn(coordinates);

                int rx = coordinates.X >> 5;
                int rz = coordinates.Z >> 5;

                string filePath = Path.Combine(basePath, string.Format(@"region{2}r.{0}.{1}.mca", rx, rz, Path.DirectorySeparatorChar));
                Assert.True(File.Exists(filePath));

                Assert.AreEqual(-2, rx, "X");
                Assert.AreEqual(4, rz, "Z");
                Assert.IsNull(chunk, $"Region Coord: {rx}, {rz}");
                //Assert.IsNotNull(chunk);
            }
        }
Exemplo n.º 6
0
        public void LoadFullAnvilRegionLoadTest()
        {
            int width = 32;
            int depth = 32;

            int regionX = 5;
            int regionZ = 25;

            string basePath  = @"D:\Downloads\KingsLanding1\KingsLanding1";
            var    generator = new FlatlandWorldProvider();

            Stopwatch sw = new Stopwatch();

            sw.Start();
            int noChunksRead = 0;

            for (int x = 1; x < 32; x++)
            {
                for (int z = 1; z < 32; z++)
                {
                    noChunksRead++;
                    int cx = (width * regionX) + x;
                    int cz = (depth * regionZ) + z;

                    ChunkCoordinates coordinates = new ChunkCoordinates(cx, cz);
                    ChunkColumn      chunk       = new AnvilWorldProvider().GetChunk(coordinates, basePath, null, 0);
                    Assert.NotNull(chunk, $"Expected chunk at {x}, {z}");
                }
            }
            Console.WriteLine("Read {0} chunks in {1}ms", noChunksRead, sw.ElapsedMilliseconds);
        }
Exemplo n.º 7
0
        public override Level GetLevel(MiNET.Player player, string levelId)
        {
            OpenLevel level;

            if (_levels.TryGetValue(levelId, out level))
            {
                return(level);
            }

            string newLevelid;

            if (levelId.Equals(_defaultLevel, StringComparison.InvariantCultureIgnoreCase))
            {
                newLevelid = levelId;
            }
            else
            {
                newLevelid = GetLevelId(levelId);
            }

            var worldProvider = new AnvilWorldProvider();
            var openLevel     = new OpenLevel(Api, this, newLevelid, worldProvider, EntityManager, _gameMode, _difficulty, _viewDistance)
            {
                EnableBlockTicking = _enableBlockTicking,
                EnableChunkTicking = _enableChunkTicking
            };

            LoadLevel(openLevel);

            return(openLevel);
        }
Exemplo n.º 8
0
        private static void InsulateChunks(AnvilWorldProvider provider, int radius = 3)
        {
            var spawn = new ChunkCoordinates(provider.GetSpawnPoint());

            for (var x = -radius; x < radius; x++)
            {
                for (var z = -radius; z < radius; z++)
                {
                    var location = new ChunkCoordinates(spawn.X + x, spawn.Z + z);

                    provider._chunkCache.TryGetValue(location, out var column);

                    if (column != null)
                    {
                        continue;
                    }

                    column = new ChunkColumn
                    {
                        isAllAir = true,
                        x        = location.X,
                        z        = location.Z
                    };

                    column.GetBatch();

                    provider._chunkCache[location] = column;
                }
            }
        }
Exemplo n.º 9
0
        public override Level GetLevel(Player player, string name)
        {
            Level level = Levels.FirstOrDefault(l => l.LevelId.Equals(name, StringComparison.InvariantCultureIgnoreCase));

            if (level == null)
            {
                int  viewDistance       = Config.GetProperty("ViewDistance", 11);
                bool isWorldTimeStarted = Config.GetProperty("IsWorldTimeStarted", false);

                string basePath = Config.GetProperty("PCWorldFolder", "World").Trim();

                var worldProvider = new AnvilWorldProvider(basePath)
                {
                    MissingChunkProvider = new PlotWorldGenerator(),
                    ReadSkyLight         = !Config.GetProperty("CalculateLights", false),
                    ReadBlockLight       = !Config.GetProperty("CalculateLights", false),
                };

                level = new Level(this, name, worldProvider, EntityManager, GameMode.Creative, Difficulty.Normal, viewDistance)
                {
                    IsWorldTimeStarted = isWorldTimeStarted
                };
                level.Initialize();

                Levels.Add(level);
                OnLevelCreated(new LevelEventArgs(null, level));
            }


            return(level);
        }
Exemplo n.º 10
0
        public void LoadFullAnvilRegionLoadTest()
        {
            int width = 32;
            int depth = 32;

            int regionX = -1;
            int regionZ = 0;

            string basePath = @"D:\Development\Worlds\UHC\UHCr1000";

            Stopwatch sw = new Stopwatch();

            sw.Start();
            int noChunksRead       = 0;
            var anvilWorldProvider = new AnvilWorldProvider();

            for (int x = 1; x < 32; x++)
            {
                for (int z = 1; z < 32; z++)
                {
                    noChunksRead++;
                    int cx = (width * regionX) + x;
                    int cz = (depth * regionZ) + z;

                    ChunkCoordinates coordinates = new ChunkCoordinates(cx, cz);
                    ChunkColumn      chunk       = anvilWorldProvider.GetChunk(coordinates, basePath, null);
                    Assert.NotNull(chunk, $"Expected chunk at {x}, {z}");
                }
            }

            sw.Stop();
            Console.WriteLine("Read {0} chunks in {1}ms", noChunksRead, sw.ElapsedMilliseconds);
        }
Exemplo n.º 11
0
        public virtual Level GetDimension(Level level, Dimension dimension)
        {
            if (dimension == Dimension.Overworld)
            {
                throw new Exception($"Can not get level for '{dimension}' from the LevelManager");
            }
            if (dimension == Dimension.Nether && !level.WorldProvider.HaveNether())
            {
                return(null);
            }
            if (dimension == Dimension.TheEnd && !level.WorldProvider.HaveTheEnd())
            {
                return(null);
            }

            AnvilWorldProvider overworld = level.WorldProvider as AnvilWorldProvider;

            if (overworld == null)
            {
                return(null);
            }

            var worldProvider = new AnvilWorldProvider(overworld.BasePath)
            {
                ReadBlockLight       = overworld.ReadBlockLight,
                ReadSkyLight         = overworld.ReadSkyLight,
                Dimension            = dimension,
                MissingChunkProvider = new AirWorldGenerator(),
            };

            Level newLevel = new Level(level.LevelManager, level.LevelId + "_" + dimension, worldProvider, EntityManager, level.GameMode, level.Difficulty, level.ViewDistance)
            {
                OverworldLevel     = level,
                Dimension          = dimension,
                EnableBlockTicking = level.EnableBlockTicking,
                EnableChunkTicking = level.EnableChunkTicking,
                IsWorldTimeStarted = level.IsWorldTimeStarted
            };

            newLevel.Initialize();

            if (Config.GetProperty("CalculateLights", false))
            {
                SkyLightCalculations.Calculate(newLevel);

                int count = worldProvider.LightSources.Count;
                Log.Debug($"Recalculating block light for {count} light sources.");
                Stopwatch sw = new Stopwatch();
                sw.Start();
                RecalculateBlockLight(newLevel, worldProvider);

                var chunkCount = worldProvider._chunkCache.Where(chunk => chunk.Value != null).ToArray().Length;
                Log.Debug($"Recalc sky and block light for {chunkCount} chunks, {chunkCount*16*16*256} blocks and {count} light sources. Time {sw.ElapsedMilliseconds}ms");
            }

            return(newLevel);
        }
Exemplo n.º 12
0
        public void Save(Player player)
        {
            AnvilWorldProvider provider = player.Level.WorldProvider as AnvilWorldProvider;

            if (provider != null)
            {
                provider.SaveChunks();
            }
        }
Exemplo n.º 13
0
 public void RecalculateLight(Level level, AnvilWorldProvider wp)
 {
     while (wp.LightSources.Count > 0)
     {
         var block = wp.LightSources.Dequeue();
         block = level.GetBlock(block.Coordinates);
         BlockLightCalculations.Calculate(level, block);
     }
 }
Exemplo n.º 14
0
        internal void SetDefaultByConfig()
        {
            var missingGenerator = new SuperflatGenerator(Dimension.Overworld);

            IWorldProvider worldProvider;

            switch (Config.GetProperty("WorldProvider", "anvil").ToLower().Trim())
            {
            case "leveldb":
                worldProvider = new LevelDbProvider()
                {
                    MissingChunkProvider = missingGenerator
                };
                break;

            case "anvil":
            default:
                worldProvider = new AnvilWorldProvider()
                {
                    MissingChunkProvider = missingGenerator,
                    ReadSkyLight         = !Config.GetProperty("CalculateLights", false),
                    ReadBlockLight       = !Config.GetProperty("CalculateLights", false)
                };
                break;
            }

            var lvl = new OpenLevel(Api, this, Dimension.Overworld.ToString(), worldProvider, EntityManager, _gameMode, _difficulty, _viewDistance)
            {
                EnableBlockTicking = Config.GetProperty("EnableBlockTicking", false),
                EnableChunkTicking = Config.GetProperty("EnableChunkTicking", false),
                SaveInterval       = Config.GetProperty("Save.Interval", 300),
                UnloadInterval     = Config.GetProperty("Unload.Interval", -1),

                DrowningDamage     = Config.GetProperty("GameRule.DrowningDamage", true),
                CommandblockOutput = Config.GetProperty("GameRule.CommandblockOutput", true),
                DoTiledrops        = Config.GetProperty("GameRule.DoTiledrops", true),
                DoMobloot          = Config.GetProperty("GameRule.DoMobloot", true),
                KeepInventory      = Config.GetProperty("GameRule.KeepInventory", true),
                DoDaylightcycle    = Config.GetProperty("GameRule.DoDaylightcycle", true),
                DoMobspawning      = Config.GetProperty("GameRule.DoMobspawning", true),
                DoEntitydrops      = Config.GetProperty("GameRule.DoEntitydrops", true),
                DoFiretick         = Config.GetProperty("GameRule.DoFiretick", true),
                DoWeathercycle     = Config.GetProperty("GameRule.DoWeathercycle", true),
                Pvp                 = Config.GetProperty("GameRule.Pvp", true),
                Falldamage          = Config.GetProperty("GameRule.Falldamage", true),
                Firedamage          = Config.GetProperty("GameRule.Firedamage", true),
                Mobgriefing         = Config.GetProperty("GameRule.Mobgriefing", true),
                ShowCoordinates     = Config.GetProperty("GameRule.ShowCoordinates", true),
                NaturalRegeneration = Config.GetProperty("GameRule.NaturalRegeneration", true),
                TntExplodes         = Config.GetProperty("GameRule.TntExplodes", true),
                SendCommandfeedback = Config.GetProperty("GameRule.SendCommandfeedback", true),
                RandomTickSpeed     = Config.GetProperty("GameRule.RandomTickSpeed", 3)
            };

            SetDefaultLevel((OpenLevel)lvl);
        }
Exemplo n.º 15
0
        public static void RecalculateLight(Level level, AnvilWorldProvider anvilWorldProvider)
        {
            SkyLightCalculations.Calculate(level);

            while (anvilWorldProvider.LightSources.Count > 0)
            {
                var block = anvilWorldProvider.LightSources.Dequeue();
                BlockLightCalculations.Calculate(level, block.Coordinates);
            }
        }
Exemplo n.º 16
0
        public override Level GetLevel(Player player, string name)
        {
            Level level = Levels.FirstOrDefault(l => l.LevelId.Equals(name, StringComparison.InvariantCultureIgnoreCase));

            if (level == null)
            {
                int viewDistance = Config.GetProperty("ViewDistance", 11);

                string basePath = Config.GetProperty("PCWorldFolder", "World").Trim();

                var worldProvider = new AnvilWorldProvider(basePath)
                {
                    MissingChunkProvider = new PlotWorldGenerator(),
                    ReadSkyLight         = !Config.GetProperty("CalculateLights", false),
                    ReadBlockLight       = !Config.GetProperty("CalculateLights", false),
                };

                level = new Level(this, name, worldProvider, EntityManager, GameMode.Creative, Difficulty.Normal, viewDistance)
                {
                    EnableBlockTicking = Config.GetProperty("EnableBlockTicking", false),
                    EnableChunkTicking = Config.GetProperty("EnableChunkTicking", false),
                    SaveInterval       = Config.GetProperty("Save.Interval", 300),
                    UnloadInterval     = Config.GetProperty("Unload.Interval", 30),

                    DrowningDamage     = Config.GetProperty("GameRule.DrowningDamage", true),
                    CommandblockOutput = Config.GetProperty("GameRule.CommandblockOutput", true),
                    DoTiledrops        = Config.GetProperty("GameRule.DoTiledrops", true),
                    DoMobloot          = Config.GetProperty("GameRule.DoMobloot", true),
                    KeepInventory      = Config.GetProperty("GameRule.KeepInventory", true),
                    DoDaylightcycle    = Config.GetProperty("GameRule.DoDaylightcycle", true),
                    DoMobspawning      = Config.GetProperty("GameRule.DoMobspawning", true),
                    DoEntitydrops      = Config.GetProperty("GameRule.DoEntitydrops", true),
                    DoFiretick         = Config.GetProperty("GameRule.DoFiretick", true),
                    DoWeathercycle     = Config.GetProperty("GameRule.DoWeathercycle", true),
                    Pvp                 = Config.GetProperty("GameRule.Pvp", true),
                    Falldamage          = Config.GetProperty("GameRule.Falldamage", true),
                    Firedamage          = Config.GetProperty("GameRule.Firedamage", true),
                    Mobgriefing         = Config.GetProperty("GameRule.Mobgriefing", true),
                    ShowCoordinates     = Config.GetProperty("GameRule.ShowCoordinates", true),
                    NaturalRegeneration = Config.GetProperty("GameRule.NaturalRegeneration", true),
                    TntExplodes         = Config.GetProperty("GameRule.TntExplodes", true),
                    SendCommandfeedback = Config.GetProperty("GameRule.SendCommandfeedback", true),
                    RandomTickSpeed     = Config.GetProperty("GameRule.RandomTickSpeed", 3),
                };
                level.Initialize();

                Levels.Add(level);
                OnLevelCreated(new LevelEventArgs(null, level));
            }


            return(level);
        }
Exemplo n.º 17
0
        public override Level GetLevel(Player player, string name)
        {
            Level level2 = Levels.FirstOrDefault(l => l.LevelId.Equals(name, StringComparison.InvariantCultureIgnoreCase));

            if (level2 == null)
            {
                AnvilWorldProvider _provider = null;
                for (int i = 0; i <= 4; i++)
                {
                    string name2;
                    if (i == 0)
                    {
                        name2 = "overworld";
                    }
                    else
                    {
                        name2 = "overworld" + i;
                    }
                    GameMode           gameMode     = Config.GetProperty("GameMode", GameMode.Survival);
                    Difficulty         difficulty   = Config.GetProperty("Difficulty", Difficulty.Normal);
                    int                viewDistance = Config.GetProperty("ViewDistance", 7);
                    AnvilWorldProvider world        = _provider;
                    if (world == null)
                    {
                        world = new AnvilWorldProvider();
                    }
                    var level = new xCoreLevelLobby(name2, world, EntityManager, xCore);
                    level.ViewDistance  = 8;
                    level.isGlobalLobby = true;
                    level.Initialize();
                    if (_provider == null)
                    {
                        world.MakeAirChunksAroundWorldToCompensateForBadRendering();
                        _provider = world;
                    }
                    level.Id = i + 1;
                    Levels.Add(level);
                    return(null);
                }
                return(null);
            }
            else
            {
                foreach (Level l in Levels)
                {
                    if (l.PlayerCount < 50)
                    {
                        return(l);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 18
0
        public BedrockClientPacketHandler(BedrockClient client, Alex alex, CancellationToken cancellationToken) :
            base(client)
        {
            BaseClient        = client;
            AlexInstance      = alex;
            CancellationToken = cancellationToken;

            AnvilWorldProvider.LoadBlockConverter();

            ChunkProcessor = new ChunkProcessor(4,
                                                alex.Services.GetService <IOptionsProvider>().AlexOptions.MiscelaneousOptions.ServerSideLighting,
                                                cancellationToken);
        }
Exemplo n.º 19
0
        public void SaveAnvilChunkTest()
        {
            int width = 32;
            int depth = 32;

            int regionX = 5;
            int regionZ = 24;

            AnvilWorldProvider anvil = new AnvilWorldProvider(@"D:\Development\Worlds\KingsLanding\");

            anvil.Initialize();
            Stopwatch sw = new Stopwatch();

            sw.Start();
            for (int x = 0; x < 32; x++)
            {
                for (int z = 0; z < 32; z++)
                {
                    int cx = (width * regionX) + x;
                    int cz = (depth * regionZ) + z;

                    ChunkCoordinates coordinates = new ChunkCoordinates(cx, cz);
                    ChunkColumn      chunk       = anvil.GenerateChunkColumn(coordinates, false);
                    Assert.NotNull(chunk);
                }
            }

            Console.WriteLine("Read {0} chunks in {1}ms", anvil.NumberOfCachedChunks(), sw.ElapsedMilliseconds);

            sw.Restart();

            anvil.SaveChunks();

            Console.WriteLine("Saved {0} chunks in {1}ms", anvil.NumberOfCachedChunks(), sw.ElapsedMilliseconds);


            for (int x = 0; x < 32; x++)
            {
                for (int z = 0; z < 32; z++)
                {
                    int cx = (width * regionX) + x;
                    int cz = (depth * regionZ) + z;

                    ChunkCoordinates coordinates = new ChunkCoordinates(cx, cz);
                    anvil.GenerateChunkColumn(coordinates, false);
                }
            }
        }
Exemplo n.º 20
0
        public void LoadAnvilChunkLoadTest()
        {
            int width = 32;
            int depth = 32;

            string basePath = @"D:\Development\Worlds\KingsLanding";
            int    regionX  = 4;
            int    regionZ  = 25;
            //string basePath = @"D:\Temp\TestSave130";
            //int regionX = 0;
            //int regionZ = 0;

            int cx = (width * regionX) + 3;
            int cz = (depth * regionZ) + 0;

            ChunkCoordinates coordinates = new ChunkCoordinates(cx, cz);

            int rx = coordinates.X >> 5;
            int rz = coordinates.Z >> 5;

            Assert.AreEqual(regionX, rx);
            Assert.AreEqual(regionZ, rz);

            //IWorldGenerator generator = new AirWorldGenerator();
            IWorldGenerator generator = null;

            Stopwatch sw = new Stopwatch();

            sw.Start();

            AnvilWorldProvider wp = new AnvilWorldProvider(basePath);

            int         iterations = 1000;
            ChunkColumn chunk      = null;

            for (int i = 0; i < iterations; i++)
            {
                chunk = wp.GetChunk(coordinates, basePath, generator);
            }

            long ticks = sw.ElapsedTicks;
            long ms    = sw.ElapsedMilliseconds;

            Console.WriteLine($"Read {iterations} chunk-columns in {ticks}ns ({ms}ms) at a rate of {ticks/iterations}ticks/col. 1ms={TimeSpan.TicksPerMillisecond}");

            Assert.NotNull(chunk);
            Assert.Less(ticks / iterations, 100);
        }
Exemplo n.º 21
0
        public static void RecalculateBlockLight(Level level, AnvilWorldProvider wp)
        {
            Queue <Block> sources = new Queue <Block>(wp.LightSources);

            while (sources.Count > 0)
            {
                var block = sources.Dequeue();
                if (block == null)
                {
                    continue;
                }

                block = level.GetBlock(block.Coordinates);
                BlockLightCalculations.Calculate(level, block);
            }
        }
Exemplo n.º 22
0
        public virtual Level GetLevel(Player player, string name)
        {
            Level level = Levels.FirstOrDefault(l => l.LevelId.Equals(name, StringComparison.InvariantCultureIgnoreCase));

            if (level == null)
            {
                GameMode   gameMode     = Config.GetProperty("GameMode", GameMode.Survival);
                Difficulty difficulty   = Config.GetProperty("Difficulty", Difficulty.Peaceful);
                int        viewDistance = Config.GetProperty("ViewDistance", 250);

                IWorldProvider worldProvider = null;

                switch (Config.GetProperty("WorldProvider", "flat").ToLower().Trim())
                {
                case "flat":
                case "flatland":
                    worldProvider = new FlatlandWorldProvider();
                    break;

                case "cool":
                    worldProvider = new CoolWorldProvider();
                    break;

                case "experimental":
                    worldProvider = new ExperimentalWorldProvider();
                    break;

                case "anvil":
                    worldProvider = new AnvilWorldProvider();
                    break;

                default:
                    worldProvider = new FlatlandWorldProvider();
                    break;
                }

                level = new Level(name, worldProvider, gameMode, difficulty, viewDistance);
                level.Initialize();
                Levels.Add(level);

                OnLevelCreated(new LevelEventArgs(null, level));
            }

            return(level);
        }
Exemplo n.º 23
0
        private void InitializeGame(IProgressReceiver progressReceiver)
        {
            progressReceiver.UpdateProgress(0, "Initializing...");
            API.Extensions.Init(GraphicsDevice);
            MCPacketFactory.Load();
            //ConfigureServices();

            var eventDispatcher = Services.GetRequiredService <IEventDispatcher>() as EventDispatcher;

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                eventDispatcher.LoadFrom(assembly);
            }

            //var options = Services.GetService<IOptionsProvider>();

            //	Log.Info($"Loading resources...");
            if (!Resources.CheckResources(GraphicsDevice, progressReceiver,
                                          OnResourcePackPreLoadCompleted))
            {
                Console.WriteLine("Press enter to exit...");
                Console.ReadLine();
                Exit();
                return;
            }

            var profileManager = Services.GetService <ProfileManager>();

            profileManager.LoadProfiles(progressReceiver);

            //GuiRenderer.LoadResourcePack(Resources.ResourcePack, null);
            AnvilWorldProvider.LoadBlockConverter();

            PluginManager.EnablePlugins();

            var storage = Services.GetRequiredService <IStorageSystem>();

            if (storage.TryReadJson("skin.json", out EntityModel model))
            {
                PlayerModel = model;
            }

            if (storage.TryReadBytes("skin.png", out byte[] skinBytes))
Exemplo n.º 24
0
        private Level GetDimensionForAnvilProvider(Level level, Dimension dimension, AnvilWorldProvider overworld)
        {
            var worldProvider = new AnvilWorldProvider(overworld.BasePath)
            {
                ReadBlockLight       = overworld.ReadBlockLight,
                ReadSkyLight         = overworld.ReadSkyLight,
                Dimension            = dimension,
                MissingChunkProvider = new SuperflatGenerator(dimension),
            };

            Level newLevel = new Level(level.LevelManager, level.LevelId + "_" + dimension, worldProvider, EntityManager, level.GameMode, level.Difficulty, level.ViewDistance)
            {
                OverworldLevel     = level,
                Dimension          = dimension,
                EnableBlockTicking = level.EnableBlockTicking,
                EnableChunkTicking = level.EnableChunkTicking,
                SaveInterval       = level.SaveInterval,
                UnloadInterval     = level.UnloadInterval,
                DrowningDamage     = level.DrowningDamage,
                CommandblockOutput = level.CommandblockOutput,
                DoTiledrops        = level.DoTiledrops,
                DoMobloot          = level.DoMobloot,
                KeepInventory      = level.KeepInventory,
                DoDaylightcycle    = level.DoDaylightcycle,
                DoMobspawning      = level.DoMobspawning,
                DoEntitydrops      = level.DoEntitydrops,
                DoFiretick         = level.DoFiretick,
                DoWeathercycle     = level.DoWeathercycle,
                Pvp                 = level.Pvp,
                Falldamage          = level.Falldamage,
                Firedamage          = level.Firedamage,
                Mobgriefing         = level.Mobgriefing,
                ShowCoordinates     = level.ShowCoordinates,
                NaturalRegeneration = level.NaturalRegeneration,
                TntExplodes         = level.TntExplodes,
                SendCommandfeedback = level.SendCommandfeedback,
                RandomTickSpeed     = level.RandomTickSpeed,
            };

            newLevel.Initialize();

            return(newLevel);
        }
Exemplo n.º 25
0
        public OpenLevel LoadLevel(string levelDirectory, string levelId)
        {
            var newLevelId = GetLevelId(levelId);

            var worldProvider = new AnvilWorldProvider(levelDirectory)
            {
                MissingChunkProvider = new SuperflatGenerator(Dimension.Overworld)
            };

            var openLevel = new OpenLevel(Api, this, newLevelId, worldProvider, EntityManager, _gameMode, _difficulty, _viewDistance)
            {
                EnableBlockTicking = _enableBlockTicking,
                EnableChunkTicking = _enableChunkTicking,
                //	IsWorldTimeStarted = _isWorldTimeStarted
            };

            LoadLevel(openLevel);

            return(openLevel);
        }
Exemplo n.º 26
0
        public virtual Level GetDimension(Level level, Dimension dimension)
        {
            if (dimension == Dimension.Overworld)
            {
                throw new Exception($"Can not get level for '{dimension}' from the LevelManager");
            }
            if (dimension == Dimension.Nether && !level.WorldProvider.HaveNether())
            {
                return(null);
            }
            if (dimension == Dimension.TheEnd && !level.WorldProvider.HaveTheEnd())
            {
                return(null);
            }

            if (!(level.WorldProvider is AnvilWorldProvider overworld))
            {
                return(null);
            }

            var worldProvider = new AnvilWorldProvider(overworld.BasePath)
            {
                ReadBlockLight       = overworld.ReadBlockLight,
                ReadSkyLight         = overworld.ReadSkyLight,
                Dimension            = dimension,
                MissingChunkProvider = new AirWorldGenerator(),
            };

            Level newLevel = new Level(level.LevelManager, level.LevelId + "_" + dimension, worldProvider, EntityManager, level.GameMode, level.Difficulty, level.ViewDistance)
            {
                OverworldLevel     = level,
                Dimension          = dimension,
                EnableBlockTicking = level.EnableBlockTicking,
                EnableChunkTicking = level.EnableChunkTicking,
                IsWorldTimeStarted = level.IsWorldTimeStarted
            };

            newLevel.Initialize();

            return(newLevel);
        }
Exemplo n.º 27
0
        public OpenLevel GetLevel(string basepath, string levelId, ChunkColumn[] chunks)
        {
            var newLevelId = GetLevelId(levelId);

            var worldProvider = new AnvilWorldProvider(basepath);

            foreach (var chunk in chunks)
            {
                worldProvider._chunkCache.TryAdd(new ChunkCoordinates(chunk.X, chunk.Z), chunk);
            }

            var openLevel = new OpenLevel(Api, this, newLevelId, worldProvider, EntityManager, _gameMode, _difficulty, _viewDistance)
            {
                EnableBlockTicking = _enableBlockTicking,
                EnableChunkTicking = _enableChunkTicking
            };

            LoadLevel(openLevel);

            return(openLevel);
        }
Exemplo n.º 28
0
        public void Reset(Player player)
        {
            Level level = player.Level;

            lock (level.Entities)
            {
                foreach (var entity in level.Entities.ToArray())
                {
                    entity.DespawnEntity();
                }
                foreach (var entity in level.BlockEntities.ToArray())
                {
                    level.RemoveBlockEntity(entity.Coordinates);
                }
            }

            lock (level.Players)
            {
                AnvilWorldProvider worldProvider = level._worldProvider as AnvilWorldProvider;
                if (worldProvider == null)
                {
                    return;
                }

                level.BroadcastMessage(string.Format("{0} resets the world!", player.Username), type: MessageType.Raw);

                lock (worldProvider._chunkCache)
                {
                    worldProvider._chunkCache.Clear();
                    worldProvider._batchCache.Clear();
                }

                var players = level.Players;
                foreach (var p in players)
                {
                    p.Value.CleanCache();
                }
            }
        }
Exemplo n.º 29
0
        public void CompressionTests()
        {
            string basePath = @"D:\Downloads\KingsLanding1\KingsLanding1";

            int cx = (32 * 5) + 1;
            int cz = (32 * 25) + 1;

            ChunkCoordinates coordinates = new ChunkCoordinates(cx, cz);
            ChunkColumn      chunk       = new AnvilWorldProvider().GetChunk(coordinates, basePath, null, 0);
            var bytes = chunk.GetBytes();

            Stopwatch sw = new Stopwatch();

            sw.Start();
            var noChunksCompressed = 10000;

            for (int i = 0; i < noChunksCompressed; i++)
            {
                Compression.Compress(bytes, 0, bytes.Length, true);
            }
            Console.WriteLine("Compressed {2} bytes {0} times in {1}ms", noChunksCompressed, sw.ElapsedMilliseconds, bytes.Length);
        }
Exemplo n.º 30
0
        public override Level GetLevel(MiNET.Player player, string levelId)
        {
            OpenLevel level;

            if (_levels.TryGetValue(levelId, out level))
            {
                return(level);
            }

            string newLevelid;

            if (levelId.Equals(_defaultLevel, StringComparison.InvariantCultureIgnoreCase))
            {
                newLevelid = levelId;
            }
            else
            {
                newLevelid = GetLevelId(levelId);
            }

            /*var worldProvider = new WrappedAnvilWorldProvider(Api)
             * {
             *      MissingChunkProvider = new FlatlandWorldProvider(),
             *      ReadSkyLight = _readSkyLight,
             *      ReadBlockLight = _readBlockLight
             * };*/var worldProvider = new AnvilWorldProvider();

            var openLevel = new OpenLevel(Api /*, Api.EventDispatcher*/, this, newLevelid, worldProvider, EntityManager, _gameMode, _difficulty, _viewDistance)
            {
                EnableBlockTicking = _enableBlockTicking,
                EnableChunkTicking = _enableChunkTicking,

                //	IsWorldTimeStarted = _isWorldTimeStarted
            };

            LoadLevel(openLevel);

            return(openLevel);
        }