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

remove some unnecessary code and improve docs for Menu

This commit is contained in:
mat 2023-10-26 23:13:26 -05:00
parent 2803e9ef0d
commit 48b5d12171
5 changed files with 19 additions and 13 deletions

View file

@ -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)?);
}
@ -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 {
@ -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 {
@ -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)?)
@ -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)?)
@ -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)?);

View file

@ -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)?;
@ -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)?;
@ -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)?;
@ -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)?;
@ -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)?;
@ -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)?;
}

View file

@ -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;

View file

@ -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() {

View file

@ -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