private void ProcessBlockUpdates() { if (!BlockUpdatesEnabled) { return; } var adjacent = new[] { Coordinates3D.Up, Coordinates3D.Down, Coordinates3D.Left, Coordinates3D.Right, Coordinates3D.Forwards, Coordinates3D.Backwards }; while (PendingBlockUpdates.Count != 0) { var update = PendingBlockUpdates.Dequeue(); var source = update.World.GetBlockData(update.Coordinates); foreach (var offset in adjacent) { var descriptor = update.World.GetBlockData(update.Coordinates + offset); var provider = BlockRepository.GetBlockProvider(descriptor.ID); if (provider != null) { provider.BlockUpdate(descriptor, source, this, update.World); } } } }
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) { lighter.EnqueueOperation(new BoundingBox(e.Position, e.Position + Vector3.One), true); lighter.EnqueueOperation(new BoundingBox(e.Position, e.Position + Vector3.One), false); } } } }
public void ScheduleBlockUpdate(DateTime time, Vector3 position) { if (time > DateTime.Now) { lock (PendingBlockUpdatesLock) PendingBlockUpdates.Add(new TimedBlockUpdate(time, position)); } // TODO: Schedule updates upon loading chunks }
public void DoScheduledUpdates() { var time = DateTime.Now; lock (PendingBlockUpdatesLock) { for (int i = 0; i < PendingBlockUpdates.Count; i++) { if (PendingBlockUpdates[i].Time <= time) { var block = GetBlock(PendingBlockUpdates[i].Position); block.OnScheduledUpdate(this, PendingBlockUpdates[i].Position); PendingBlockUpdates.RemoveAt(i--); } } } }
void HandleBlockChanged(object sender, BlockChangeEventArgs e) { 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(); }
public bool UpdatePending(Vector3 position) { lock (PendingBlockUpdatesLock) return(PendingBlockUpdates.Any(update => update.Position == position)); }