Beispiel #1
0
 void HandleBlockChanged(object sender, BlockChangeEventArgs e)
 {
     // TODO: Propegate lighting changes to client (not possible with beta 1.7.3 protocol)
     if (e.NewBlock.ID != e.OldBlock.ID || e.NewBlock.Metadata != e.OldBlock.Metadata)
     {
         for (int i = 0, ClientsCount = Clients.Count; i < ClientsCount; i++)
         {
             var client = (RemoteClient)Clients[i];
             // TODO: Confirm that the client knows of this block
             if (client.LoggedIn && client.World == sender)
             {
                 client.QueuePacket(new BlockChangePacket(e.Position.X, (sbyte)e.Position.Y, e.Position.Z,
                                                          (sbyte)e.NewBlock.ID, (sbyte)e.NewBlock.Metadata));
             }
         }
         PendingBlockUpdates.Enqueue(new BlockUpdate {
             Coordinates = e.Position, World = sender as IWorld
         });
         ProcessBlockUpdates();
         if (Program.ServerConfiguration.EnableLighting)
         {
             var lighter = WorldLighters.SingleOrDefault(l => l.World == sender);
             if (lighter != null)
             {
                 var posA = e.Position;
                 posA.Y = 0;
                 var posB = e.Position;
                 posB.Y = World.Height;
                 posB.X++; posB.Z++;
                 lighter.EnqueueOperation(new BoundingBox(posA, posB), true);
                 lighter.EnqueueOperation(new BoundingBox(posA, posB), false);
             }
         }
     }
 }
 void HandleChunkLoaded(object sender, ChunkLoadedEventArgs e)
 {
     ChunksToSchedule.Add(new Tuple <IWorld, IChunk>(sender as IWorld, e.Chunk));
     if (Program.ServerConfiguration.EnableLighting)
     {
         var lighter = WorldLighters.SingleOrDefault(l => l.World == sender);
         lighter.InitialLighting(e.Chunk, false);
     }
 }
Beispiel #3
0
        public void AddWorld(IWorld world)
        {
            Worlds.Add(world);
            world.BlockRepository = BlockRepository;
            world.ChunkGenerated += HandleChunkGenerated;
            world.ChunkLoaded    += HandleChunkLoaded;
            world.BlockChanged   += HandleBlockChanged;
            var manager = new EntityManager(this, world);

            EntityManagers.Add(manager);
            var lighter = new WorldLighting(world, BlockRepository);

            WorldLighters.Add(lighter);
            foreach (var chunk in world)
            {
                HandleChunkLoaded(world, new ChunkLoadedEventArgs(chunk));
            }
        }