1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

inventory menu should hopefully work

This commit is contained in:
Ubuntu 2022-12-09 19:02:59 +00:00
parent f34eb166ee
commit 572240efd4
2 changed files with 25 additions and 18 deletions

View file

@ -110,8 +110,9 @@ pub struct Client {
pub players: Arc<RwLock<HashMap<Uuid, PlayerInfo>>>,
tasks: Arc<Mutex<Vec<JoinHandle<()>>>>,
pub inventory_menu: Arc<Mutex<azalea_inventory::Player>>,
pub container_menu: Arc<Mutex<Option<azalea_inventory::Menu>>>,
// The player's inventory. This is guaranteed to be a Menu::Player.
pub inventory_menu: Arc<Mutex<Menu>>,
pub container_menu: Arc<Mutex<Option<Menu>>>,
}
#[derive(Default)]
@ -197,7 +198,9 @@ impl Client {
tasks: Arc::new(Mutex::new(Vec::new())),
// empty by default
inventory_menu: Arc::new(Mutex::new(azalea_inventory::Player::default())),
inventory_menu: Arc::new(Mutex::new(
Menu::Player(azalea_inventory::Player::default()),
)),
// we don't have any container open when we spawn
container_menu: Arc::new(Mutex::new(None)),
}
@ -828,14 +831,11 @@ impl Client {
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.
let mut inventory = client.inventory_menu.lock();
for (i, slot) in p.items.iter().enumerate().take(inventory.len()) {
if let Some(slot_ref) = inventory.slot_mut(i) {
*slot_ref = slot.clone();
}
}
}
}

View file

@ -15,7 +15,7 @@ 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(&mut self, i: usize) -> Option<&Slot> {
pub fn slot_mut(&mut self, i: usize) -> Option<&mut Slot> {
Some(match self {
#slot_mut_match_variants
})
@ -70,6 +70,7 @@ pub fn generate_match_variant_for_slot_mut(menu: &Menu) -> TokenStream {
_ => return None
}
},
true,
)
}
@ -80,16 +81,22 @@ pub fn generate_match_variant_for_len(menu: &Menu) -> TokenStream {
&quote! {
#length
},
false,
)
}
fn generate_matcher(menu: &Menu, match_arms: &TokenStream) -> TokenStream {
fn generate_matcher(menu: &Menu, match_arms: &TokenStream, needs_fields: bool) -> 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 menu_field_names = if needs_fields {
let mut menu_field_names = quote! {};
for field in &menu.fields {
let field_name = &field.name;
menu_field_names.extend(quote! { #field_name, })
}
menu_field_names
} else {
quote! { .. }
};
let matcher = if menu.name.to_string() == "Player" {
quote! { (Player { #menu_field_names }) }