mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
start on containersetcontent
This commit is contained in:
parent
48a9221300
commit
f34eb166ee
3 changed files with 64 additions and 20 deletions
|
@ -2,6 +2,7 @@ pub use crate::chat::ChatPacket;
|
|||
use crate::{movement::WalkDirection, plugins::PluginStates, Account, PlayerInfo};
|
||||
use azalea_auth::{game_profile::GameProfile, sessionserver::SessionServerError};
|
||||
use azalea_core::{ChunkPos, ResourceLocation, Vec3};
|
||||
use azalea_inventory::Menu;
|
||||
use azalea_protocol::{
|
||||
connect::{Connection, ConnectionError, ReadConnection, WriteConnection},
|
||||
packets::{
|
||||
|
@ -825,6 +826,18 @@ impl Client {
|
|||
}
|
||||
ClientboundGamePacket::ContainerSetContent(p) => {
|
||||
debug!("Got container set content packet {:?}", p);
|
||||
// container id 0 is always the player's inventory
|
||||
if p.container_id == 0 {
|
||||
let inventory = client.inventory_menu.lock();
|
||||
for (i, slot) in p
|
||||
.items
|
||||
.iter()
|
||||
.enumerate()
|
||||
.take(Menu::Player(inventory.clone()).len())
|
||||
{
|
||||
// inventory.
|
||||
}
|
||||
}
|
||||
}
|
||||
ClientboundGamePacket::SetHealth(p) => {
|
||||
debug!("Got set health packet {:?}", p);
|
||||
|
|
|
@ -3,9 +3,11 @@ use proc_macro2::TokenStream;
|
|||
use quote::quote;
|
||||
|
||||
pub fn generate(input: &DeclareMenus) -> TokenStream {
|
||||
let mut match_variants = quote! {};
|
||||
let mut slot_mut_match_variants = quote! {};
|
||||
let mut len_match_variants = quote! {};
|
||||
for menu in &input.menus {
|
||||
match_variants.extend(generate_match_variant_for_menu(menu));
|
||||
slot_mut_match_variants.extend(generate_match_variant_for_slot_mut(menu));
|
||||
len_match_variants.extend(generate_match_variant_for_len(menu));
|
||||
}
|
||||
|
||||
quote! {
|
||||
|
@ -13,11 +15,17 @@ pub fn generate(input: &DeclareMenus) -> TokenStream {
|
|||
/// Get a mutable reference to the [`Slot`] at the given protocol index. If
|
||||
/// you're trying to get an item in a menu normally, you should just
|
||||
/// `match` it and index the `[Slot]` you get
|
||||
pub fn slot_mut(&self, i: usize) -> Option<&Slot> {
|
||||
pub fn slot_mut(&mut self, i: usize) -> Option<&Slot> {
|
||||
Some(match self {
|
||||
#match_variants
|
||||
#slot_mut_match_variants
|
||||
})
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
match self {
|
||||
#len_match_variants
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,14 +45,7 @@ pub fn generate(input: &DeclareMenus) -> TokenStream {
|
|||
/// _ => return None,
|
||||
/// }
|
||||
/// } // ...
|
||||
pub fn generate_match_variant_for_menu(menu: &Menu) -> TokenStream {
|
||||
let menu_name = &menu.name;
|
||||
let mut menu_field_names = quote! {};
|
||||
for field in &menu.fields {
|
||||
let field_name = &field.name;
|
||||
menu_field_names.extend(quote! { #field_name, })
|
||||
}
|
||||
|
||||
pub fn generate_match_variant_for_slot_mut(menu: &Menu) -> TokenStream {
|
||||
let mut match_arms = quote! {};
|
||||
let mut i = 0;
|
||||
for field in &menu.fields {
|
||||
|
@ -55,12 +56,41 @@ pub fn generate_match_variant_for_menu(menu: &Menu) -> TokenStream {
|
|||
match_arms.extend(if start == end {
|
||||
quote! { #start => #field_name, }
|
||||
} else if start == 0 {
|
||||
quote! { #start..=#end => &#field_name[i], }
|
||||
quote! { #start..=#end => &mut #field_name[i], }
|
||||
} else {
|
||||
quote! { #start..=#end => &#field_name[i - #start], }
|
||||
quote! { #start..=#end => &mut #field_name[i - #start], }
|
||||
});
|
||||
}
|
||||
|
||||
generate_matcher(
|
||||
menu,
|
||||
"e! {
|
||||
match i {
|
||||
#match_arms
|
||||
_ => return None
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn generate_match_variant_for_len(menu: &Menu) -> TokenStream {
|
||||
let length = menu.fields.iter().map(|f| f.length).sum::<usize>();
|
||||
generate_matcher(
|
||||
menu,
|
||||
"e! {
|
||||
#length
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn generate_matcher(menu: &Menu, match_arms: &TokenStream) -> TokenStream {
|
||||
let menu_name = &menu.name;
|
||||
let mut menu_field_names = quote! {};
|
||||
for field in &menu.fields {
|
||||
let field_name = &field.name;
|
||||
menu_field_names.extend(quote! { #field_name, })
|
||||
}
|
||||
|
||||
let matcher = if menu.name.to_string() == "Player" {
|
||||
quote! { (Player { #menu_field_names }) }
|
||||
} else {
|
||||
|
@ -68,10 +98,7 @@ pub fn generate_match_variant_for_menu(menu: &Menu) -> TokenStream {
|
|||
};
|
||||
quote! {
|
||||
Menu::#menu_name #matcher => {
|
||||
match i {
|
||||
#match_arms
|
||||
_ => return None,
|
||||
}
|
||||
#match_arms
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::ops::Deref;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use azalea_core::Slot;
|
||||
use azalea_inventory_macros::declare_menus;
|
||||
|
@ -10,11 +10,15 @@ use azalea_inventory_macros::declare_menus;
|
|||
pub struct SlotList<const N: usize>([Slot; N]);
|
||||
impl<const N: usize> Deref for SlotList<N> {
|
||||
type Target = [Slot; N];
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
impl<const N: usize> DerefMut for SlotList<N> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
impl<const N: usize> Default for SlotList<N> {
|
||||
fn default() -> Self {
|
||||
SlotList([(); N].map(|_| Slot::Empty))
|
||||
|
|
Loading…
Add table
Reference in a new issue