ferrumc-rs / ferrumc

A reimplementation of the minecraft server in rust.
MIT License
1.04k stars 31 forks source link

Added broadcasting packets with options. And GlobalState Extension trait to easily `state.broadcast(&packet, opts).await;` #110

Closed Sweattypalms closed 3 weeks ago

Sweattypalms commented 3 weeks ago

Better broadcasting. You can simply do state.broadcast(&packet, options); and it broadcasts to either: All entities, or specifically the entities mentioned with the BroadcastOptions::default().only(entities);. Can also have both Sync and Async callbacks using

BroadcastOptions::default().with_async_callback(|entity, state| async move {
// do whatever
});

Or for Sync callbaks

BroadcastOptions::default().with_sync_callback(move |entity, state| {
// do whatever
});