Exemple #1
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);
        }
Exemple #2
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.Normal);
                int        viewDistance = Config.GetProperty("ViewDistance", 11);

                IWorldProvider worldProvider = null;

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

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

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

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

                level = new Level(this, name, 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),
                };
                level.Initialize();

                //if (Config.GetProperty("CalculateLights", false))
                //{
                //	{
                //		AnvilWorldProvider wp = level.WorldProvider as AnvilWorldProvider;
                //		if (wp != null)
                //		{
                //			wp.Locked = true;
                ////			wp.PruneAir();
                ////			wp.MakeAirChunksAroundWorldToCompensateForBadRendering();
                //			Stopwatch sw = new Stopwatch();

                //			var chunkCount = 0;
                //			sw.Restart();
                //			SkyLightCalculations.Calculate(level);
                //			sw.Stop();
                //			chunkCount = wp._chunkCache.Where(chunk => chunk.Value != null).ToArray().Length;
                //			Log.Debug($"Recalculated sky light for {chunkCount} chunks, {chunkCount * 16 * 16 * 256} blocks. Time {sw.ElapsedMilliseconds}ms");

                //			int count = wp.LightSources.Count;
                //			sw.Restart();
                //			RecalculateBlockLight(level, wp);

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

                //			wp.Locked = false;
                //		}
                //	}
                //}

                Levels.Add(level);

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

            return(level);
        }
Exemple #3
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.Normal);
                int        viewDistance = Config.GetProperty("ViewDistance", 11);

                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()
                    {
                        MissingChunkProvider = new FlatlandWorldProvider()
                    };
                    break;

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

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

                if (Config.GetProperty("CalculateLights", false))
                {
                    {
                        AnvilWorldProvider wp = level._worldProvider as AnvilWorldProvider;
                        if (wp != null)
                        {
                            //wp.PruneAir();
                            //wp.MakeAirChunksAroundWorldToCompensateForBadRendering();

                            SkyLightCalculations.Calculate(level);

                            Stopwatch sw = new Stopwatch();

                            int count = wp.LightSources.Count;
                            sw.Restart();
                            RecalculateLight(level, wp);

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

                    {
                        FlatlandWorldProvider wp = level._worldProvider as FlatlandWorldProvider;
                        if (wp != null)
                        {
                            SkyLightCalculations.Calculate(level);
                        }
                    }
                }
                Levels.Add(level);

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

            return(level);
        }
Exemple #4
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.Normal);
                int        viewDistance       = Config.GetProperty("ViewDistance", 11);
                bool       enableBlockTicking = Config.GetProperty("EnableBlockTicking", false);
                bool       enableChunkTicking = Config.GetProperty("EnableChunkTicking", false);
                bool       isWorldTimeStarted = Config.GetProperty("IsWorldTimeStarted", false);

                IWorldProvider worldProvider = null;

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

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

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

                level = new Level(this, name, worldProvider, EntityManager, gameMode, difficulty, viewDistance)
                {
                    EnableBlockTicking = enableBlockTicking,
                    EnableChunkTicking = enableChunkTicking,
                    IsWorldTimeStarted = isWorldTimeStarted
                };
                level.Initialize();

                if (Config.GetProperty("CalculateLights", false))
                {
                    {
                        AnvilWorldProvider wp = level.WorldProvider as AnvilWorldProvider;
                        if (wp != null)
                        {
                            wp.Locked = true;
                            Stopwatch sw = new Stopwatch();

                            var chunkCount = 0;
                            sw.Restart();
                            SkyLightCalculations.Calculate(level);
                            sw.Stop();
                            chunkCount = wp._chunkCache.Where(chunk => chunk.Value != null).ToArray().Length;
                            Log.Debug($"Recalculated sky light for {chunkCount} chunks, {chunkCount * 16 * 16 * 256} blocks. Time {sw.ElapsedMilliseconds}ms");

                            int count = wp.LightSources.Count;
                            sw.Restart();
                            RecalculateBlockLight(level, wp);

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

                            wp.Locked = false;
                        }
                    }
                }

                Levels.Add(level);

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

            return(level);
        }