-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
68 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "ferrumc-entity-utils" | ||
version = "0.1.0" | ||
edition = "2024" | ||
|
||
[dependencies] | ||
ferrumc-net = { workspace = true } | ||
ferrumc-net-codec = { workspace = true } | ||
ferrumc-ecs = { workspace = true } | ||
ferrumc-text = { workspace = true } | ||
async-trait = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod send_message; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use async_trait::async_trait; | ||
use ferrumc_ecs::Universe; | ||
use ferrumc_net::{connection::StreamWriter, packets::outgoing::system_message::SystemMessagePacket, NetResult}; | ||
use ferrumc_net_codec::encode::NetEncodeOpts; | ||
use ferrumc_text::TextComponent; | ||
|
||
#[async_trait] | ||
pub trait SendMessageExt { | ||
async fn send_message(&self, message: TextComponent, universe: &Universe) -> NetResult<()>; | ||
async fn send_actionbar(&self, message: TextComponent, universe: &Universe) -> NetResult<()>; | ||
} | ||
|
||
#[async_trait] | ||
impl SendMessageExt for usize { | ||
async fn send_message(&self, message: TextComponent, universe: &Universe) -> NetResult<()> { | ||
let mut writer = universe.get_mut::<StreamWriter>(*self)?; | ||
writer.send_packet( | ||
&SystemMessagePacket::new(message, false), | ||
&NetEncodeOpts::WithLength | ||
).await | ||
} | ||
|
||
async fn send_actionbar(&self, message: TextComponent, universe: &Universe) -> NetResult<()> { | ||
let mut writer = universe.get_mut::<StreamWriter>(*self)?; | ||
writer.send_packet( | ||
&SystemMessagePacket::new(message, true), | ||
&NetEncodeOpts::WithLength | ||
).await | ||
} | ||
} |