internal ReadOnlyWorld() { World = new World(null); Level = new Level(World); World.EnableBlockUpdates = false; UnloadChunks = true; }
/// <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); }
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(); }
/// <summary> /// Adds a world to this server's list of worlds. /// </summary> public void AddLevel(Level level) { level.World.OnBlockChanged += HandleOnBlockChanged; Levels.Add(level); }
/// <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); }
/// <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); }
/// <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; }