示例#1
0
 internal ReadOnlyWorld()
 {
     World = new World(null);
     Level = new Level(World);
     World.EnableBlockUpdates = false;
     UnloadChunks = true;
 }
示例#2
0
 /// <summary>
 /// Creates a new world for client-side use.
 /// </summary>
 public World(Level level)
 {
     Level = level;
     Name = "world";
     Entities = new List<Entity>();
     Regions = new Dictionary<Vector3, Region>();
     EnableBlockUpdates = true;
     EntityUpdateTimer = new Timer(DoEntityUpdates, null, Level.TickLength, Level.TickLength);
 }
示例#3
0
        public Server()
        {
            Config = new ServerConfig();
            JsonSerializerSettings settings = new JsonSerializerSettings();
            settings.MissingMemberHandling = MissingMemberHandling.Error;
            //Parse the config file. If the config isn't valid, throw an error.
            if (File.Exists("config.json"))
                try { Config = JsonConvert.DeserializeObject<ServerConfig>(File.ReadAllText("config.json"), settings); }
                catch (JsonException e) { Logger.Log("Config file is invalid!", LogType.Error); }
            else
                File.WriteAllText("config.json", JsonConvert.SerializeObject(Config, Formatting.Indented));

            //Parse the IP from the config file.
            if (!string.IsNullOrWhiteSpace(Config.IP))
            {
                if (!IPAddress.TryParse(Config.IP, out ServerIP))
                    ServerIP = IPAddress.Any;
            }
            else
                ServerIP = IPAddress.Any;
            ServerPort = Config.Port;
            MCServer = new MinecraftServer(new IPEndPoint(ServerIP, ServerPort));
            LogProvider.RegisterProvider(new MCServerLogger());

            //Choose the world generator based on the config file.
            if (string.IsNullOrWhiteSpace(Config.World))
                Config.World = "world";
            switch (Config.WorldType)
            {
                case LevelGenerator.Debug:
                    Generator = new DebugGenerator();
                    break;
                case LevelGenerator.Flatland:
                    Generator = new FlatlandGenerator();
                    break;
                default:
                    //No default generator yet!
                    Generator = new DebugGenerator();
                    break;
            }
            Level l = new Level(Generator, Config.World);
            l.GameMode = GameMode.Survival;
            if (Config.Gamemode == Gamemode.Creative) l.GameMode = GameMode.Creative;
            MCServer.AddLevel(l);

            MCServer.Settings.MotD = Config.MOTD;
            MCServer.Settings.MaxPlayers = Config.MaxPlayers;
            MCServer.Settings.OnlineMode = Config.Online;
            MCServer.Settings.Difficulty = Config.Difficulty;

            MCServer.PlayerLoggedIn += new EventHandler<Craft.Net.Server.Events.PlayerLogInEventArgs>(PlayerLoggedIn);
            MCServer.Start();
        }
示例#4
0
 /// <summary>
 /// Adds a world to this server's list of worlds.
 /// </summary>
 public void AddLevel(Level level)
 {
     level.World.OnBlockChanged += HandleOnBlockChanged;
     Levels.Add(level);
 }
示例#5
0
 /// <summary>
 /// Adds a worldBlockChangedr's list of worlds.
 /// </summary>
 public void AddLevel(Level level)
 {
     level.World.BlockChanged += HandleOnBlockChanged;
     level.World.SpawnEntity += (sender, args) => 
         EntityManager.SpawnEntity(sender as World, args.Entity);
     level.World.DestroyEntity += (sender, args) =>
         EntityManager.DespawnEntity(sender as World, args.Entity);
     Levels.Add(level);
 }
示例#6
0
 /// <summary>
 /// Creates a new world for server-side use with the specified world generator
 /// and the specified working directory.
 /// </summary>
 public World(Level level, IWorldGenerator worldGenerator, string directory) : this(level, worldGenerator)
 {
     Directory = directory;
     if (!System.IO.Directory.Exists(directory))
         System.IO.Directory.CreateDirectory(directory);
 }
示例#7
0
 /// <summary>
 /// Creates a new world for server-side use with the specified world generator.
 /// </summary>
 public World(Level level, IWorldGenerator worldGenerator) : this(level)
 {
     WorldGenerator = worldGenerator;
 }