mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
add recipe packet
This commit is contained in:
parent
f859dbbba0
commit
4f9f2468f0
3 changed files with 64 additions and 0 deletions
|
@ -120,6 +120,9 @@ pub async fn join_server(address: &ServerAddress) -> Result<(), String> {
|
|||
GamePacket::ClientboundEntityEventPacket(p) => {
|
||||
println!("Got entity event packet {:?}", p);
|
||||
}
|
||||
GamePacket::ClientboundRecipePacket(p) => {
|
||||
println!("Got recipe packet {:?}", p);
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
panic!("Error: {:?}", e);
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
use async_trait::async_trait;
|
||||
use azalea_chat::component::Component;
|
||||
use azalea_core::{resource_location::ResourceLocation, Slot};
|
||||
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
|
||||
use tokio::io::AsyncRead;
|
||||
|
||||
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
|
||||
|
||||
#[derive(Clone, Debug, GamePacket)]
|
||||
pub struct ClientboundRecipePacket {
|
||||
pub action: State,
|
||||
pub settings: RecipeBookSettings,
|
||||
pub recipes: Vec<ResourceLocation>,
|
||||
pub to_highlight: Vec<ResourceLocation>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, McBufReadable, McBufWritable)]
|
||||
pub struct RecipeBookSettings {
|
||||
pub gui_open: bool,
|
||||
pub filtering_craftable: bool,
|
||||
|
||||
pub furnace_gui_open: bool,
|
||||
pub furnace_filtering_craftable: bool,
|
||||
|
||||
pub blast_furnace_gui_open: bool,
|
||||
pub blast_furnace_filtering_craftable: bool,
|
||||
|
||||
pub smoker_gui_open: bool,
|
||||
pub smoker_filtering_craftable: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Copy)]
|
||||
pub enum State {
|
||||
Init = 0,
|
||||
Add = 1,
|
||||
Remove = 2,
|
||||
}
|
||||
|
||||
impl McBufWritable for State {
|
||||
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
||||
buf.write_varint(*self as i32)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
#[async_trait]
|
||||
impl McBufReadable for State {
|
||||
async fn read_into<R>(buf: &mut R) -> Result<Self, String>
|
||||
where
|
||||
R: AsyncRead + std::marker::Unpin + std::marker::Send,
|
||||
{
|
||||
let state = buf.read_varint().await?.try_into().unwrap();
|
||||
Ok(match state {
|
||||
0 => State::Init,
|
||||
1 => State::Add,
|
||||
2 => State::Remove,
|
||||
_ => panic!("Invalid state: {}", state),
|
||||
})
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ pub mod clientbound_disconnect_packet;
|
|||
pub mod clientbound_entity_event_packet;
|
||||
pub mod clientbound_login_packet;
|
||||
pub mod clientbound_player_abilities_packet;
|
||||
pub mod clientbound_recipe_packet;
|
||||
pub mod clientbound_set_carried_item_packet;
|
||||
pub mod clientbound_update_recipes_packet;
|
||||
pub mod clientbound_update_tags_packet;
|
||||
|
@ -23,6 +24,7 @@ declare_state_packets!(
|
|||
0x18: clientbound_custom_payload_packet::ClientboundCustomPayloadPacket,
|
||||
0x26: clientbound_login_packet::ClientboundLoginPacket,
|
||||
0x32: clientbound_player_abilities_packet::ClientboundPlayerAbilitiesPacket,
|
||||
0x39: clientbound_recipe_packet::ClientboundRecipePacket,
|
||||
0x48: clientbound_set_carried_item_packet::ClientboundSetCarriedItemPacket,
|
||||
0x4a: clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket,
|
||||
0x66: clientbound_update_recipes_packet::ClientboundUpdateRecipesPacket,
|
||||
|
|
Loading…
Add table
Reference in a new issue