Example #1
0
 public Chunk(int chunkX, int chunkZ, Map world)
 {
     ChunkX = chunkX;
     ChunkZ = chunkZ;
     Entities = new List<Entity>();
     _World = world;
     Load();
 }
Example #2
0
        public Server()
        {
            Port = Configuration.GetInt("port", 25565);
            Running = false;
            WorldName = Configuration.Get("world", "world");
            Name = Configuration.Get("server-name", "Minecraft Server");
            Motd = Configuration.Get("motd", "Powered by " + Color.Green + "Spacecraft");
            ServerHash = "-";

            World = null;
            PlayerList = new List<Player>();
            _Listener = new TcpListener(new IPEndPoint(IPAddress.Any, Port));
        }
Example #3
0
        public void Run()
        {
            World = new Map(WorldName);
            World.Time = 0;
            if (!File.Exists(WorldName + "/level.dat")) {
                Spacecraft.Log("Generating world " + WorldName);
                World.Generate();
                World.ForceSave();
            }

            _Listener.Start();
            Spacecraft.Log("Listening on port " + Port);
            Running = true;

            InventoryItem i = new InventoryItem(3);
            PickupEntity e = new PickupEntity(World.SpawnX, World.SpawnY, World.SpawnZ, i);

            Stopwatch clock = new Stopwatch();
            clock.Start();
            double lastUpdate = 0;
            double lastGc = 0;

            while (Running) {
                // Check for new connections
                while (_Listener.Pending()) {
                    AcceptConnection(_Listener.AcceptTcpClient());
                    //Running = false;
                }

                if (lastUpdate + 0.2 < clock.Elapsed.TotalSeconds) {
                    World.Update();
                    lastUpdate = clock.Elapsed.TotalSeconds;
                }

                if (lastGc + 30 < clock.Elapsed.TotalSeconds) {
                    GC.Collect();
                }

                // Rest
                Thread.Sleep(30);
            }

            World.ForceSave();
        }