Skip to content

Commit

Permalink
remove some unnecessary code and improve docs for Menu
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Oct 27, 2023
1 parent 2803e9e commit 48b5d12
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
12 changes: 6 additions & 6 deletions azalea-buf/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl<T: McBufReadable + Send> McBufReadable for Vec<T> {
let length = u32::var_read_from(buf)? as usize;
// we don't set the capacity here so we can't get exploited into
// allocating a bunch
let mut contents = vec![];
let mut contents = Vec::new();
for _ in 0..length {
contents.push(T::read_from(buf)?);
}
Expand All @@ -184,7 +184,7 @@ impl<T: McBufReadable + Send> McBufReadable for Vec<T> {
}

impl<K: McBufReadable + Send + Eq + Hash, V: McBufReadable + Send> McBufReadable for HashMap<K, V> {
default fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let length = i32::var_read_from(buf)? as usize;
let mut contents = HashMap::new();
for _ in 0..length {
Expand All @@ -197,7 +197,7 @@ impl<K: McBufReadable + Send + Eq + Hash, V: McBufReadable + Send> McBufReadable
impl<K: McBufReadable + Send + Eq + Hash, V: McBufVarReadable + Send> McBufVarReadable
for HashMap<K, V>
{
default fn var_read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
fn var_read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let length = i32::var_read_from(buf)? as usize;
let mut contents = HashMap::new();
for _ in 0..length {
Expand Down Expand Up @@ -308,7 +308,7 @@ impl McBufReadable for f64 {
}

impl<T: McBufReadable> McBufReadable for Option<T> {
default fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let present = bool::read_from(buf)?;
Ok(if present {
Some(T::read_from(buf)?)
Expand All @@ -319,7 +319,7 @@ impl<T: McBufReadable> McBufReadable for Option<T> {
}

impl<T: McBufVarReadable> McBufVarReadable for Option<T> {
default fn var_read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
fn var_read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let present = bool::read_from(buf)?;
Ok(if present {
Some(T::var_read_from(buf)?)
Expand All @@ -331,7 +331,7 @@ impl<T: McBufVarReadable> McBufVarReadable for Option<T> {

// [String; 4]
impl<T: McBufReadable, const N: usize> McBufReadable for [T; N] {
default fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let mut contents = Vec::with_capacity(N);
for _ in 0..N {
contents.push(T::read_from(buf)?);
Expand Down
12 changes: 6 additions & 6 deletions azalea-buf/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<T: McBufWritable> McBufWritable for Vec<T> {
}

impl<T: McBufWritable> McBufWritable for [T] {
default fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
(self.len() as u32).var_write_into(buf)?;
for item in self {
T::write_into(item, buf)?;
Expand All @@ -74,7 +74,7 @@ impl<T: McBufWritable> McBufWritable for [T] {
}

impl<K: McBufWritable, V: McBufWritable> McBufWritable for HashMap<K, V> {
default fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
u32::var_write_into(&(self.len() as u32), buf)?;
for (key, value) in self {
key.write_into(buf)?;
Expand All @@ -86,7 +86,7 @@ impl<K: McBufWritable, V: McBufWritable> McBufWritable for HashMap<K, V> {
}

impl<K: McBufWritable, V: McBufVarWritable> McBufVarWritable for HashMap<K, V> {
default fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
u32::var_write_into(&(self.len() as u32), buf)?;
for (key, value) in self {
key.write_into(buf)?;
Expand Down Expand Up @@ -225,7 +225,7 @@ impl McBufWritable for f64 {
}

impl<T: McBufWritable> McBufWritable for Option<T> {
default fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
if let Some(s) = self {
true.write_into(buf)?;
s.write_into(buf)?;
Expand All @@ -237,7 +237,7 @@ impl<T: McBufWritable> McBufWritable for Option<T> {
}

impl<T: McBufVarWritable> McBufVarWritable for Option<T> {
default fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
if let Some(s) = self {
true.write_into(buf)?;
s.var_write_into(buf)?;
Expand All @@ -250,7 +250,7 @@ impl<T: McBufVarWritable> McBufVarWritable for Option<T> {

// [T; N]
impl<T: McBufWritable, const N: usize> McBufWritable for [T; N] {
default fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
for i in self {
i.write_into(buf)?;
}
Expand Down
1 change: 0 additions & 1 deletion azalea-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#![allow(incomplete_features)]
#![feature(trait_upcasting)]
#![feature(error_generic_member_access)]
#![feature(type_alias_impl_trait)]

mod account;
pub mod attack;
Expand Down
3 changes: 3 additions & 0 deletions azalea-inventory/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ pub enum ClickType {

impl Menu {
/// Shift-click a slot in this menu.
///
/// Keep in mind that this doesn't send any packets to the server, it just
/// mutates this specific `Menu`.
pub fn quick_move_stack(&mut self, slot_index: usize) -> ItemSlot {
let slot = self.slot(slot_index);
if slot.is_none() {
Expand Down
4 changes: 4 additions & 0 deletions azalea/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ impl ContainerHandle {

/// Returns the menu of the container. If the container is closed, this
/// will return `None`.
///
/// Note that any modifications you make to the `Menu` you're given will not
/// actually cause any packets to be sent. If you're trying to modify your
/// inventory, use [`Self::open_inventory`] instead
pub fn menu(&self) -> Option<Menu> {
let ecs = self.client.ecs.lock();
let inventory = ecs
Expand Down

0 comments on commit 48b5d12

Please sign in to comment.