Example #1
0
        public object Clone()
        {
            ConcurrentDictionary <ChunkCoordinates, ChunkColumn> chunkCache = new ConcurrentDictionary <ChunkCoordinates, ChunkColumn>();

            foreach (KeyValuePair <ChunkCoordinates, ChunkColumn> valuePair in _chunkCache)
            {
                chunkCache.TryAdd(valuePair.Key, (ChunkColumn)valuePair.Value?.Clone());
            }

            AnvilWorldProvider provider = new AnvilWorldProvider(BasePath, (LevelInfo)LevelInfo.Clone(), WaterOffsetY, chunkCache);

            return(provider);
        }
Example #2
0
        private static ChunkColumn GetChunk(Level level, BlockCoordinates blockCoordinates)
        {
            AnvilWorldProvider provider = level.WorldProvider as AnvilWorldProvider;

            if (provider != null)
            {
                ChunkColumn chunk;
                provider._chunkCache.TryGetValue((ChunkCoordinates)blockCoordinates, out chunk);

                return(chunk);
            }

            return(null);
        }
Example #3
0
        public void Close()
        {
            //_levelTicker.Change(Timeout.Infinite, Timeout.Infinite);
            //WaitHandle waitHandle = new AutoResetEvent(false);
            //_levelTicker.Dispose(waitHandle);
            //WaitHandle.WaitAll(new[] {waitHandle}, TimeSpan.FromMinutes(2));
            //_levelTicker = null;

            _tickerHighPrecisionTimer.Dispose();

            foreach (var entity in Entities.Values.ToArray())
            {
                entity.DespawnEntity();
            }

            Entities.Clear();

            foreach (Player player in Players.Values.ToArray())
            {
                player.Disconnect("Unexpected player lingering on close of level: " + player.Username);
            }

            Players.Clear();

            BlockEntities.Clear();

            BlockWithTicks.Clear();
            BlockWithTicks = null;
            BlockEntities  = null;
            Players        = null;
            Entities       = null;

            AnvilWorldProvider provider = _worldProvider as AnvilWorldProvider;

            if (provider != null)
            {
                foreach (var chunk in provider._chunkCache)
                {
                    chunk.Value?.ClearCache();
                }
            }

            _worldProvider = null;

            Log.Info("Closed level: " + LevelId);
        }
Example #4
0
        public SingleplayerServer(string world, Gamemode gamemode, Difficulty difficulty, Alex alex, IPEndPoint endPoint, PlayerProfile profile, DedicatedThreadPool threadPool, out NetworkProvider networkProvider) : base(alex, endPoint, profile, threadPool, out networkProvider)
        {
            Server = new OpenServer();
            ReflectionHelper.SetPrivatePropertyValue(
                typeof(OpenServer), Server, "Endpoint", new IPEndPoint(IPAddress.Loopback, 0));

            ConnectionEndpoint = Server.Endpoint;
            Api = ReflectionHelper.GetPrivatePropertyValue <OpenApi>(typeof(OpenServer), Server, "OpenApi");

            MiNET.Worlds.AnvilWorldProvider provider = new MiNET.Worlds.AnvilWorldProvider(world);

            MiNETLevel = new OpenLevel(
                Api, Api.LevelManager, "default", provider, Api.LevelManager.EntityManager, (GameMode)gamemode,
                difficulty);

            Api.LevelManager.SetDefaultLevel(MiNETLevel);
        }
Example #5
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);
					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);
				}
			}
		}
Example #6
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", 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();
                        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;
        }
Example #7
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);
		}