mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 23:44:38 +00:00
inventory menu should hopefully work
This commit is contained in:
parent
f34eb166ee
commit
572240efd4
2 changed files with 25 additions and 18 deletions
|
@ -110,8 +110,9 @@ pub struct Client {
|
||||||
pub players: Arc<RwLock<HashMap<Uuid, PlayerInfo>>>,
|
pub players: Arc<RwLock<HashMap<Uuid, PlayerInfo>>>,
|
||||||
tasks: Arc<Mutex<Vec<JoinHandle<()>>>>,
|
tasks: Arc<Mutex<Vec<JoinHandle<()>>>>,
|
||||||
|
|
||||||
pub inventory_menu: Arc<Mutex<azalea_inventory::Player>>,
|
// The player's inventory. This is guaranteed to be a Menu::Player.
|
||||||
pub container_menu: Arc<Mutex<Option<azalea_inventory::Menu>>>,
|
pub inventory_menu: Arc<Mutex<Menu>>,
|
||||||
|
pub container_menu: Arc<Mutex<Option<Menu>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -197,7 +198,9 @@ impl Client {
|
||||||
tasks: Arc::new(Mutex::new(Vec::new())),
|
tasks: Arc::new(Mutex::new(Vec::new())),
|
||||||
|
|
||||||
// empty by default
|
// 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
|
// we don't have any container open when we spawn
|
||||||
container_menu: Arc::new(Mutex::new(None)),
|
container_menu: Arc::new(Mutex::new(None)),
|
||||||
}
|
}
|
||||||
|
@ -828,14 +831,11 @@ impl Client {
|
||||||
debug!("Got container set content packet {:?}", p);
|
debug!("Got container set content packet {:?}", p);
|
||||||
// container id 0 is always the player's inventory
|
// container id 0 is always the player's inventory
|
||||||
if p.container_id == 0 {
|
if p.container_id == 0 {
|
||||||
let inventory = client.inventory_menu.lock();
|
let mut inventory = client.inventory_menu.lock();
|
||||||
for (i, slot) in p
|
for (i, slot) in p.items.iter().enumerate().take(inventory.len()) {
|
||||||
.items
|
if let Some(slot_ref) = inventory.slot_mut(i) {
|
||||||
.iter()
|
*slot_ref = slot.clone();
|
||||||
.enumerate()
|
}
|
||||||
.take(Menu::Player(inventory.clone()).len())
|
|
||||||
{
|
|
||||||
// inventory.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub fn generate(input: &DeclareMenus) -> TokenStream {
|
||||||
/// Get a mutable reference to the [`Slot`] at the given protocol index. If
|
/// 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
|
/// you're trying to get an item in a menu normally, you should just
|
||||||
/// `match` it and index the `[Slot]` you get
|
/// `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 {
|
Some(match self {
|
||||||
#slot_mut_match_variants
|
#slot_mut_match_variants
|
||||||
})
|
})
|
||||||
|
@ -70,6 +70,7 @@ pub fn generate_match_variant_for_slot_mut(menu: &Menu) -> TokenStream {
|
||||||
_ => return None
|
_ => return None
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,16 +81,22 @@ pub fn generate_match_variant_for_len(menu: &Menu) -> TokenStream {
|
||||||
"e! {
|
"e! {
|
||||||
#length
|
#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 menu_name = &menu.name;
|
||||||
let mut menu_field_names = quote! {};
|
let menu_field_names = if needs_fields {
|
||||||
for field in &menu.fields {
|
let mut menu_field_names = quote! {};
|
||||||
let field_name = &field.name;
|
for field in &menu.fields {
|
||||||
menu_field_names.extend(quote! { #field_name, })
|
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" {
|
let matcher = if menu.name.to_string() == "Player" {
|
||||||
quote! { (Player { #menu_field_names }) }
|
quote! { (Player { #menu_field_names }) }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue