From cd9a05e5a62190b3d4a2a733bf637d6324aec5fd Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 25 Jun 2022 02:33:28 -0500 Subject: [PATCH] read_into -> read_from yeah --- azalea-buf/buf-macros/src/lib.rs | 10 +-- azalea-buf/src/definitions.rs | 4 +- azalea-buf/src/read.rs | 62 +++++++++---------- azalea-buf/src/serializable_uuid.rs | 2 +- azalea-chat/src/component.rs | 6 +- azalea-core/src/difficulty.rs | 4 +- azalea-core/src/game_type.rs | 8 +-- azalea-core/src/particle/mod.rs | 18 +++--- azalea-core/src/position.rs | 14 ++--- azalea-core/src/resource_location.rs | 6 +- azalea-core/src/slot.rs | 6 +- azalea-crypto/src/signing.rs | 6 +- azalea-entity/src/data.rs | 52 ++++++++-------- azalea-nbt/src/decode.rs | 2 +- azalea-nbt/src/lib.rs | 2 +- azalea-protocol/packet-macros/src/lib.rs | 2 +- .../clientbound_declare_commands_packet.rs | 32 +++++----- .../clientbound_level_particles_packet.rs | 22 +++---- .../clientbound_player_abilities_packet.rs | 2 +- .../game/clientbound_player_info_packet.rs | 12 ++-- .../clientbound_player_position_packet.rs | 2 +- .../packets/game/clientbound_recipe_packet.rs | 2 +- ...lientbound_section_blocks_update_packet.rs | 4 +- .../game/clientbound_set_equipment_packet.rs | 6 +- .../clientbound_update_advancements_packet.rs | 4 +- .../clientbound_update_attributes_packet.rs | 2 +- .../game/clientbound_update_recipes_packet.rs | 28 ++++----- .../game/clientbound_update_tags_packet.rs | 10 +-- .../login/clientbound_game_profile_packet.rs | 2 +- .../packets/login/serverbound_key_packet.rs | 8 +-- azalea-protocol/src/packets/mod.rs | 2 +- azalea-world/src/chunk.rs | 6 +- azalea-world/src/palette.rs | 12 ++-- 33 files changed, 180 insertions(+), 180 deletions(-) diff --git a/azalea-buf/buf-macros/src/lib.rs b/azalea-buf/buf-macros/src/lib.rs index 4cc397a2..a735a920 100644 --- a/azalea-buf/buf-macros/src/lib.rs +++ b/azalea-buf/buf-macros/src/lib.rs @@ -21,11 +21,11 @@ fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::TokenSt syn::Type::Path(_) => { if f.attrs.iter().any(|a| a.path.is_ident("var")) { quote! { - let #field_name = azalea_buf::McBufVarReadable::var_read_into(buf)?; + let #field_name = azalea_buf::McBufVarReadable::var_read_from(buf)?; } } else { quote! { - let #field_name = azalea_buf::McBufReadable::read_into(buf)?; + let #field_name = azalea_buf::McBufReadable::read_from(buf)?; } } } @@ -41,7 +41,7 @@ fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::TokenSt quote! { impl azalea_buf::McBufReadable for #ident { - fn read_into(buf: &mut impl std::io::Read) -> Result { + fn read_from(buf: &mut impl std::io::Read) -> Result { #(#read_fields)* Ok(#ident { #(#read_field_names: #read_field_names),* @@ -76,9 +76,9 @@ fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::TokenSt quote! { impl azalea_buf::McBufReadable for #ident { - fn read_into(buf: &mut impl std::io::Read) -> Result + fn read_from(buf: &mut impl std::io::Read) -> Result { - let id = azalea_buf::McBufVarReadable::var_read_into(buf)?; + let id = azalea_buf::McBufVarReadable::var_read_from(buf)?; match id { #match_contents _ => Err(format!("Unknown enum variant {}", id)), diff --git a/azalea-buf/src/definitions.rs b/azalea-buf/src/definitions.rs index 921fb63d..f3452bea 100644 --- a/azalea-buf/src/definitions.rs +++ b/azalea-buf/src/definitions.rs @@ -42,9 +42,9 @@ impl BitSet { } impl McBufReadable for BitSet { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { Ok(Self { - data: Vec::::read_into(buf)?, + data: Vec::::read_from(buf)?, }) } } diff --git a/azalea-buf/src/read.rs b/azalea-buf/src/read.rs index 569a5b1d..92c4d79b 100644 --- a/azalea-buf/src/read.rs +++ b/azalea-buf/src/read.rs @@ -201,31 +201,31 @@ pub trait McBufReadable where Self: Sized, { - fn read_into(buf: &mut impl Read) -> Result; + fn read_from(buf: &mut impl Read) -> Result; } pub trait McBufVarReadable where Self: Sized, { - fn var_read_into(buf: &mut impl Read) -> Result; + fn var_read_from(buf: &mut impl Read) -> Result; } impl McBufReadable for i32 { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { Readable::read_int(buf) } } impl McBufVarReadable for i32 { - fn var_read_into(buf: &mut impl Read) -> Result { + fn var_read_from(buf: &mut impl Read) -> Result { buf.read_varint() } } impl McBufVarReadable for i64 { // fast varints modified from https://github.com/luojia65/mc-varint/blob/master/src/lib.rs#L54 - fn var_read_into(buf: &mut impl Read) -> Result { + fn var_read_from(buf: &mut impl Read) -> Result { let mut buffer = [0]; let mut ans = 0; for i in 0..8 { @@ -240,139 +240,139 @@ impl McBufVarReadable for i64 { } } impl McBufVarReadable for u64 { - fn var_read_into(buf: &mut impl Read) -> Result { - i64::var_read_into(buf).map(|i| i as u64) + fn var_read_from(buf: &mut impl Read) -> Result { + i64::var_read_from(buf).map(|i| i as u64) } } impl McBufReadable for UnsizedByteArray { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { Ok(buf.read_bytes()?.into()) } } impl McBufReadable for Vec { - default fn read_into(buf: &mut impl Read) -> Result { + default fn read_from(buf: &mut impl Read) -> Result { let length = buf.read_varint()? as usize; let mut contents = Vec::with_capacity(length); for _ in 0..length { - contents.push(T::read_into(buf)?); + contents.push(T::read_from(buf)?); } Ok(contents) } } impl McBufReadable for HashMap { - default fn read_into(buf: &mut impl Read) -> Result { + default fn read_from(buf: &mut impl Read) -> Result { let length = buf.read_varint()? as usize; let mut contents = HashMap::with_capacity(length); for _ in 0..length { - contents.insert(K::read_into(buf)?, V::read_into(buf)?); + contents.insert(K::read_from(buf)?, V::read_from(buf)?); } Ok(contents) } } impl McBufReadable for Vec { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { buf.read_byte_array() } } impl McBufReadable for String { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { buf.read_utf() } } impl McBufReadable for u32 { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { Readable::read_int(buf).map(|i| i as u32) } } impl McBufVarReadable for u32 { - fn var_read_into(buf: &mut impl Read) -> Result { + fn var_read_from(buf: &mut impl Read) -> Result { buf.read_varint().map(|i| i as u32) } } impl McBufReadable for u16 { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { buf.read_short().map(|i| i as u16) } } impl McBufReadable for i16 { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { buf.read_short() } } impl McBufVarReadable for u16 { - fn var_read_into(buf: &mut impl Read) -> Result { + fn var_read_from(buf: &mut impl Read) -> Result { buf.read_varint().map(|i| i as u16) } } impl McBufVarReadable for Vec { - fn var_read_into(buf: &mut impl Read) -> Result { + fn var_read_from(buf: &mut impl Read) -> Result { let length = buf.read_varint()? as usize; let mut contents = Vec::with_capacity(length); for _ in 0..length { - contents.push(T::var_read_into(buf)?); + contents.push(T::var_read_from(buf)?); } Ok(contents) } } impl McBufReadable for i64 { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { buf.read_long() } } impl McBufReadable for u64 { - fn read_into(buf: &mut impl Read) -> Result { - i64::read_into(buf).map(|i| i as u64) + fn read_from(buf: &mut impl Read) -> Result { + i64::read_from(buf).map(|i| i as u64) } } impl McBufReadable for bool { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { buf.read_boolean() } } impl McBufReadable for u8 { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { buf.read_byte() } } impl McBufReadable for i8 { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { buf.read_byte().map(|i| i as i8) } } impl McBufReadable for f32 { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { buf.read_float() } } impl McBufReadable for f64 { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { buf.read_double() } } impl McBufReadable for Option { - default fn read_into(buf: &mut impl Read) -> Result { + default fn read_from(buf: &mut impl Read) -> Result { let present = buf.read_boolean()?; Ok(if present { - Some(T::read_into(buf)?) + Some(T::read_from(buf)?) } else { None }) diff --git a/azalea-buf/src/serializable_uuid.rs b/azalea-buf/src/serializable_uuid.rs index 10921aa6..eb256d90 100644 --- a/azalea-buf/src/serializable_uuid.rs +++ b/azalea-buf/src/serializable_uuid.rs @@ -33,7 +33,7 @@ impl SerializableUuid for Uuid { } impl McBufReadable for Uuid { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { Ok(Uuid::from_int_array([ Readable::read_int(buf)? as u32, Readable::read_int(buf)? as u32, diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs index d307bcbc..d2f687d4 100755 --- a/azalea-chat/src/component.rs +++ b/azalea-chat/src/component.rs @@ -269,8 +269,8 @@ impl<'de> Deserialize<'de> for Component { } impl McBufReadable for Component { - fn read_into(buf: &mut impl Read) -> Result { - let string = String::read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let string = String::read_from(buf)?; let json: serde_json::Value = serde_json::from_str(string.as_str()) .map_err(|_| "Component isn't valid JSON".to_string())?; let component = Component::deserialize(json).map_err(|e| e.to_string())?; @@ -279,7 +279,7 @@ impl McBufReadable for Component { } impl McBufWritable for Component { - // async fn read_into(buf: &mut impl Read) -> Result + // async fn read_from(buf: &mut impl Read) -> Result // where // R: AsyncRead + std::marker::Unpin + std::marker::Send, // { diff --git a/azalea-core/src/difficulty.rs b/azalea-core/src/difficulty.rs index ebbb7708..718359f3 100755 --- a/azalea-core/src/difficulty.rs +++ b/azalea-core/src/difficulty.rs @@ -67,8 +67,8 @@ impl Difficulty { } impl McBufReadable for Difficulty { - fn read_into(buf: &mut impl Read) -> Result { - Ok(Difficulty::by_id(u8::read_into(buf)?)) + fn read_from(buf: &mut impl Read) -> Result { + Ok(Difficulty::by_id(u8::read_from(buf)?)) } } diff --git a/azalea-core/src/game_type.rs b/azalea-core/src/game_type.rs index 67c392b2..d41e5b84 100755 --- a/azalea-core/src/game_type.rs +++ b/azalea-core/src/game_type.rs @@ -77,8 +77,8 @@ impl GameType { } impl McBufReadable for GameType { - fn read_into(buf: &mut impl Read) -> Result { - GameType::from_id(u8::read_into(buf)?) + fn read_from(buf: &mut impl Read) -> Result { + GameType::from_id(u8::read_from(buf)?) } } @@ -105,8 +105,8 @@ impl From for Option { } impl McBufReadable for OptionalGameType { - fn read_into(buf: &mut impl Read) -> Result { - GameType::from_optional_id(i8::read_into(buf)?) + fn read_from(buf: &mut impl Read) -> Result { + GameType::from_optional_id(i8::read_from(buf)?) } } diff --git a/azalea-core/src/particle/mod.rs b/azalea-core/src/particle/mod.rs index 6eb53955..3b2e9807 100644 --- a/azalea-core/src/particle/mod.rs +++ b/azalea-core/src/particle/mod.rs @@ -157,8 +157,8 @@ impl ParticleData { Ok(match id { 0 => ParticleData::AmbientEntityEffect, 1 => ParticleData::AngryVillager, - 2 => ParticleData::Block(BlockParticle::read_into(buf)?), - 3 => ParticleData::BlockMarker(BlockParticle::read_into(buf)?), + 2 => ParticleData::Block(BlockParticle::read_from(buf)?), + 3 => ParticleData::BlockMarker(BlockParticle::read_from(buf)?), 4 => ParticleData::Bubble, 5 => ParticleData::Cloud, 6 => ParticleData::Crit, @@ -169,8 +169,8 @@ impl ParticleData { 11 => ParticleData::LandingLava, 12 => ParticleData::DrippingWater, 13 => ParticleData::FallingWater, - 14 => ParticleData::Dust(DustParticle::read_into(buf)?), - 15 => ParticleData::DustColorTransition(DustColorTransitionParticle::read_into(buf)?), + 14 => ParticleData::Dust(DustParticle::read_from(buf)?), + 15 => ParticleData::DustColorTransition(DustColorTransitionParticle::read_from(buf)?), 16 => ParticleData::Effect, 17 => ParticleData::ElderGuardian, 18 => ParticleData::EnchantedHit, @@ -179,7 +179,7 @@ impl ParticleData { 21 => ParticleData::EntityEffect, 22 => ParticleData::ExplosionEmitter, 23 => ParticleData::Explosion, - 24 => ParticleData::FallingDust(BlockParticle::read_into(buf)?), + 24 => ParticleData::FallingDust(BlockParticle::read_from(buf)?), 25 => ParticleData::Firework, 26 => ParticleData::Fishing, 27 => ParticleData::Flame, @@ -190,8 +190,8 @@ impl ParticleData { 32 => ParticleData::Composter, 33 => ParticleData::Heart, 34 => ParticleData::InstantEffect, - 35 => ParticleData::Item(ItemParticle::read_into(buf)?), - 36 => ParticleData::Vibration(VibrationParticle::read_into(buf)?), + 35 => ParticleData::Item(ItemParticle::read_from(buf)?), + 36 => ParticleData::Vibration(VibrationParticle::read_from(buf)?), 37 => ParticleData::ItemSlime, 38 => ParticleData::ItemSnowball, 39 => ParticleData::LargeSmoke, @@ -249,8 +249,8 @@ impl ParticleData { } impl McBufReadable for ParticleData { - fn read_into(buf: &mut impl Read) -> Result { - let id = u32::var_read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let id = u32::var_read_from(buf)?; ParticleData::read_from_particle_id(buf, id) } } diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs index de8e2516..195558e8 100644 --- a/azalea-core/src/position.rs +++ b/azalea-core/src/position.rs @@ -225,8 +225,8 @@ impl From<&EntityPos> for ChunkPos { } impl McBufReadable for BlockPos { - fn read_into(buf: &mut impl Read) -> Result { - let val = u64::read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let val = u64::read_from(buf)?; let x = (val >> 38) as i32; let y = (val & 0xFFF) as i32; let z = ((val >> 12) & 0x3FFFFFF) as i32; @@ -235,17 +235,17 @@ impl McBufReadable for BlockPos { } impl McBufReadable for GlobalPos { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { Ok(GlobalPos { - dimension: ResourceLocation::read_into(buf)?, - pos: BlockPos::read_into(buf)?, + dimension: ResourceLocation::read_from(buf)?, + pos: BlockPos::read_from(buf)?, }) } } impl McBufReadable for ChunkSectionPos { - fn read_into(buf: &mut impl Read) -> Result { - let long = i64::read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let long = i64::read_from(buf)?; Ok(ChunkSectionPos { x: (long >> 42) as i32, y: (long << 44 >> 44) as i32, diff --git a/azalea-core/src/resource_location.rs b/azalea-core/src/resource_location.rs index acca0c58..945b6d80 100755 --- a/azalea-core/src/resource_location.rs +++ b/azalea-core/src/resource_location.rs @@ -46,8 +46,8 @@ impl std::fmt::Debug for ResourceLocation { } impl McBufReadable for ResourceLocation { - fn read_into(buf: &mut impl Read) -> Result { - let location_string = String::read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let location_string = String::read_from(buf)?; ResourceLocation::new(&location_string) } } @@ -99,7 +99,7 @@ mod tests { let mut buf = Cursor::new(buf); assert_eq!( - ResourceLocation::read_into(&mut buf).unwrap(), + ResourceLocation::read_from(&mut buf).unwrap(), ResourceLocation::new("minecraft:dirt").unwrap() ); } diff --git a/azalea-core/src/slot.rs b/azalea-core/src/slot.rs index 6e622872..8b1f784d 100644 --- a/azalea-core/src/slot.rs +++ b/azalea-core/src/slot.rs @@ -18,12 +18,12 @@ pub struct SlotData { } impl McBufReadable for Slot { - fn read_into(buf: &mut impl Read) -> Result { - let present = bool::read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let present = bool::read_from(buf)?; if !present { return Ok(Slot::Empty); } - let slot = SlotData::read_into(buf)?; + let slot = SlotData::read_from(buf)?; Ok(Slot::Present(slot)) } } diff --git a/azalea-crypto/src/signing.rs b/azalea-crypto/src/signing.rs index 4fc07d30..535f9f1d 100644 --- a/azalea-crypto/src/signing.rs +++ b/azalea-crypto/src/signing.rs @@ -8,9 +8,9 @@ pub struct SaltSignaturePair { } impl McBufReadable for SaltSignaturePair { - fn read_into(buf: &mut impl Read) -> Result { - let salt = u64::read_into(buf)?; - let signature = Vec::::read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let salt = u64::read_from(buf)?; + let signature = Vec::::read_from(buf)?; Ok(SaltSignaturePair { salt, signature }) } } diff --git a/azalea-entity/src/data.rs b/azalea-entity/src/data.rs index 5d2a66fc..f8468ecf 100644 --- a/azalea-entity/src/data.rs +++ b/azalea-entity/src/data.rs @@ -17,14 +17,14 @@ pub struct EntityDataItem { } impl McBufReadable for EntityMetadata { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { let mut metadata = Vec::new(); loop { - let index = u8::read_into(buf)?; + let index = u8::read_from(buf)?; if index == 0xff { break; } - let value = EntityDataValue::read_into(buf)?; + let value = EntityDataValue::read_from(buf)?; metadata.push(EntityDataItem { index, value }); } Ok(EntityMetadata(metadata)) @@ -70,46 +70,46 @@ pub enum EntityDataValue { } impl McBufReadable for EntityDataValue { - fn read_into(buf: &mut impl Read) -> Result { - let data_type = i32::var_read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let data_type = i32::var_read_from(buf)?; Ok(match data_type { - 0 => EntityDataValue::Byte(u8::read_into(buf)?), - 1 => EntityDataValue::Int(i32::var_read_into(buf)?), - 2 => EntityDataValue::Float(f32::read_into(buf)?), - 3 => EntityDataValue::String(String::read_into(buf)?), - 4 => EntityDataValue::Component(Component::read_into(buf)?), - 5 => EntityDataValue::OptionalComponent(Option::::read_into(buf)?), - 6 => EntityDataValue::ItemStack(Slot::read_into(buf)?), - 7 => EntityDataValue::Boolean(bool::read_into(buf)?), + 0 => EntityDataValue::Byte(u8::read_from(buf)?), + 1 => EntityDataValue::Int(i32::var_read_from(buf)?), + 2 => EntityDataValue::Float(f32::read_from(buf)?), + 3 => EntityDataValue::String(String::read_from(buf)?), + 4 => EntityDataValue::Component(Component::read_from(buf)?), + 5 => EntityDataValue::OptionalComponent(Option::::read_from(buf)?), + 6 => EntityDataValue::ItemStack(Slot::read_from(buf)?), + 7 => EntityDataValue::Boolean(bool::read_from(buf)?), 8 => EntityDataValue::Rotations { - x: f32::read_into(buf)?, - y: f32::read_into(buf)?, - z: f32::read_into(buf)?, + x: f32::read_from(buf)?, + y: f32::read_from(buf)?, + z: f32::read_from(buf)?, }, - 9 => EntityDataValue::BlockPos(BlockPos::read_into(buf)?), - 10 => EntityDataValue::OptionalBlockPos(Option::::read_into(buf)?), - 11 => EntityDataValue::Direction(Direction::read_into(buf)?), - 12 => EntityDataValue::OptionalUuid(Option::::read_into(buf)?), + 9 => EntityDataValue::BlockPos(BlockPos::read_from(buf)?), + 10 => EntityDataValue::OptionalBlockPos(Option::::read_from(buf)?), + 11 => EntityDataValue::Direction(Direction::read_from(buf)?), + 12 => EntityDataValue::OptionalUuid(Option::::read_from(buf)?), 13 => EntityDataValue::OptionalBlockState({ - let val = i32::read_into(buf)?; + let val = i32::read_from(buf)?; if val == 0 { None } else { Some(val) } }), - 14 => EntityDataValue::CompoundTag(azalea_nbt::Tag::read_into(buf)?), - 15 => EntityDataValue::Particle(Particle::read_into(buf)?), - 16 => EntityDataValue::VillagerData(VillagerData::read_into(buf)?), + 14 => EntityDataValue::CompoundTag(azalea_nbt::Tag::read_from(buf)?), + 15 => EntityDataValue::Particle(Particle::read_from(buf)?), + 16 => EntityDataValue::VillagerData(VillagerData::read_from(buf)?), 17 => EntityDataValue::OptionalUnsignedInt({ - let val = u32::var_read_into(buf)?; + let val = u32::var_read_from(buf)?; if val == 0 { None } else { Some((val - 1) as u32) } }), - 18 => EntityDataValue::Pose(Pose::read_into(buf)?), + 18 => EntityDataValue::Pose(Pose::read_from(buf)?), _ => return Err(format!("Unknown entity data type: {}", data_type)), }) } diff --git a/azalea-nbt/src/decode.rs b/azalea-nbt/src/decode.rs index 1c011839..5f0e8fd2 100755 --- a/azalea-nbt/src/decode.rs +++ b/azalea-nbt/src/decode.rs @@ -139,7 +139,7 @@ impl Tag { } impl McBufReadable for Tag { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { match Tag::read(buf) { Ok(r) => Ok(r), // Err(e) => Err(e.to_string()), diff --git a/azalea-nbt/src/lib.rs b/azalea-nbt/src/lib.rs index cb2eb28e..75232eb0 100755 --- a/azalea-nbt/src/lib.rs +++ b/azalea-nbt/src/lib.rs @@ -26,7 +26,7 @@ mod tests { let mut buf = Cursor::new(buf); - let result = Tag::read_into(&mut buf).unwrap(); + let result = Tag::read_from(&mut buf).unwrap(); assert_eq!( result, Tag::Compound(HashMap::from_iter(vec![( diff --git a/azalea-protocol/packet-macros/src/lib.rs b/azalea-protocol/packet-macros/src/lib.rs index 58487cdd..2e40cbd1 100755 --- a/azalea-protocol/packet-macros/src/lib.rs +++ b/azalea-protocol/packet-macros/src/lib.rs @@ -32,7 +32,7 @@ fn as_packet_derive(input: TokenStream, state: proc_macro2::TokenStream) -> Toke buf: &mut impl std::io::Read, ) -> Result<#state, String> { use azalea_buf::McBufReadable; - Ok(Self::read_into(buf)?.get()) + Ok(Self::read_from(buf)?.get()) } } }; diff --git a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs index bf29a050..ee3f21a2 100755 --- a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs @@ -25,15 +25,15 @@ pub struct BrigadierNumber { max: Option, } impl McBufReadable for BrigadierNumber { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { let flags = buf.read_byte()?; let min = if flags & 0x01 != 0 { - Some(T::read_into(buf)?) + Some(T::read_from(buf)?) } else { None }; let max = if flags & 0x02 != 0 { - Some(T::read_into(buf)?) + Some(T::read_from(buf)?) } else { None }; @@ -124,16 +124,16 @@ pub enum BrigadierParser { } impl McBufReadable for BrigadierParser { - fn read_into(buf: &mut impl Read) -> Result { - let parser_type = u32::var_read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let parser_type = u32::var_read_from(buf)?; match parser_type { 0 => Ok(BrigadierParser::Bool), - 1 => Ok(BrigadierParser::Float(BrigadierNumber::read_into(buf)?)), - 2 => Ok(BrigadierParser::Double(BrigadierNumber::read_into(buf)?)), - 3 => Ok(BrigadierParser::Integer(BrigadierNumber::read_into(buf)?)), - 4 => Ok(BrigadierParser::Long(BrigadierNumber::read_into(buf)?)), - 5 => Ok(BrigadierParser::String(BrigadierString::read_into(buf)?)), + 1 => Ok(BrigadierParser::Float(BrigadierNumber::read_from(buf)?)), + 2 => Ok(BrigadierParser::Double(BrigadierNumber::read_from(buf)?)), + 3 => Ok(BrigadierParser::Integer(BrigadierNumber::read_from(buf)?)), + 4 => Ok(BrigadierParser::Long(BrigadierNumber::read_from(buf)?)), + 5 => Ok(BrigadierParser::String(BrigadierString::read_from(buf)?)), 6 => { let flags = buf.read_byte()?; Ok(BrigadierParser::Entity { @@ -183,10 +183,10 @@ impl McBufReadable for BrigadierParser { 41 => Ok(BrigadierParser::Dimension), 42 => Ok(BrigadierParser::Time), 43 => Ok(BrigadierParser::ResourceOrTag { - registry_key: ResourceLocation::read_into(buf)?, + registry_key: ResourceLocation::read_from(buf)?, }), 44 => Ok(BrigadierParser::Resource { - registry_key: ResourceLocation::read_into(buf)?, + registry_key: ResourceLocation::read_from(buf)?, }), 45 => Ok(BrigadierParser::TemplateMirror), 46 => Ok(BrigadierParser::TemplateRotation), @@ -198,8 +198,8 @@ impl McBufReadable for BrigadierParser { // TODO: BrigadierNodeStub should have more stuff impl McBufReadable for BrigadierNodeStub { - fn read_into(buf: &mut impl Read) -> Result { - let flags = u8::read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let flags = u8::read_from(buf)?; if flags > 31 { println!( "Warning: The flags from a Brigadier node are over 31 ({flags}; {flags:#b}). This is probably a bug.", @@ -217,9 +217,9 @@ impl McBufReadable for BrigadierNodeStub { // argument node if node_type == 2 { let _name = buf.read_utf()?; - let _parser = BrigadierParser::read_into(buf)?; + let _parser = BrigadierParser::read_from(buf)?; let _suggestions_type = if has_suggestions_type { - Some(ResourceLocation::read_into(buf)?) + Some(ResourceLocation::read_from(buf)?) } else { None }; diff --git a/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs b/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs index df1174b7..a9ce57ad 100644 --- a/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs @@ -20,17 +20,17 @@ pub struct ClientboundLevelParticlesPacket { } impl McBufReadable for ClientboundLevelParticlesPacket { - fn read_into(buf: &mut impl Read) -> Result { - let particle_id = u32::var_read_into(buf)?; - let override_limiter = bool::read_into(buf)?; - let x = f64::read_into(buf)?; - let y = f64::read_into(buf)?; - let z = f64::read_into(buf)?; - let x_dist = f32::read_into(buf)?; - let y_dist = f32::read_into(buf)?; - let z_dist = f32::read_into(buf)?; - let max_speed = f32::read_into(buf)?; - let count = u32::read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let particle_id = u32::var_read_from(buf)?; + let override_limiter = bool::read_from(buf)?; + let x = f64::read_from(buf)?; + let y = f64::read_from(buf)?; + let z = f64::read_from(buf)?; + let x_dist = f32::read_from(buf)?; + let y_dist = f32::read_from(buf)?; + let z_dist = f32::read_from(buf)?; + let max_speed = f32::read_from(buf)?; + let count = u32::read_from(buf)?; let data = ParticleData::read_from_particle_id(buf, particle_id)?; diff --git a/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs index d351ab04..bc3c653e 100755 --- a/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs @@ -20,7 +20,7 @@ pub struct PlayerAbilitiesFlags { } impl McBufReadable for PlayerAbilitiesFlags { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { let byte = buf.read_byte()?; Ok(PlayerAbilitiesFlags { invulnerable: byte & 1 != 0, diff --git a/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs index f216fde8..522a371a 100644 --- a/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs @@ -63,14 +63,14 @@ pub struct RemovePlayer { } impl McBufReadable for Action { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { let id = buf.read_byte()?; Ok(match id { - 0 => Action::AddPlayer(Vec::::read_into(buf)?), - 1 => Action::UpdateGameMode(Vec::::read_into(buf)?), - 2 => Action::UpdateLatency(Vec::::read_into(buf)?), - 3 => Action::UpdateDisplayName(Vec::::read_into(buf)?), - 4 => Action::RemovePlayer(Vec::::read_into(buf)?), + 0 => Action::AddPlayer(Vec::::read_from(buf)?), + 1 => Action::UpdateGameMode(Vec::::read_from(buf)?), + 2 => Action::UpdateLatency(Vec::::read_from(buf)?), + 3 => Action::UpdateDisplayName(Vec::::read_from(buf)?), + 4 => Action::RemovePlayer(Vec::::read_from(buf)?), _ => panic!("Unknown player info action id: {}", id), }) } diff --git a/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs index 29f7c1a3..d28d6620 100644 --- a/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs @@ -28,7 +28,7 @@ pub struct RelativeArguments { } impl McBufReadable for RelativeArguments { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { let byte = buf.read_byte()?; Ok(RelativeArguments { x: byte & 0b1 != 0, diff --git a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs index a79bfcf1..a00774da 100644 --- a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs @@ -41,7 +41,7 @@ impl McBufWritable for State { } } impl McBufReadable for State { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { let state = buf.read_varint()?; Ok(match state { 0 => State::Init, diff --git a/azalea-protocol/src/packets/game/clientbound_section_blocks_update_packet.rs b/azalea-protocol/src/packets/game/clientbound_section_blocks_update_packet.rs index 6ee27ed1..60ebe26c 100644 --- a/azalea-protocol/src/packets/game/clientbound_section_blocks_update_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_section_blocks_update_packet.rs @@ -18,8 +18,8 @@ pub struct BlockStateWithPosition { } impl McBufReadable for BlockStateWithPosition { - fn read_into(buf: &mut impl Read) -> Result { - let data = u64::var_read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let data = u64::var_read_from(buf)?; let position_part = data & 4095; let state = (data >> 12) as u32; let position = ChunkSectionBlockPos { diff --git a/azalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs index aa352189..769d24bb 100644 --- a/azalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs @@ -17,14 +17,14 @@ pub struct EquipmentSlots { } impl McBufReadable for EquipmentSlots { - fn read_into(buf: &mut impl std::io::Read) -> Result { + fn read_from(buf: &mut impl std::io::Read) -> Result { let mut slots = vec![]; loop { - let equipment_byte = u8::read_into(buf)?; + let equipment_byte = u8::read_from(buf)?; let equipment_slot = EquipmentSlot::from_byte(equipment_byte & 127) .ok_or_else(|| format!("Invalid equipment slot byte {}", equipment_byte))?; - let item = Slot::read_into(buf)?; + let item = Slot::read_from(buf)?; slots.push((equipment_slot, item)); if equipment_byte & 128 == 0 { break; diff --git a/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs index 43e4d69f..118dd477 100644 --- a/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs @@ -45,8 +45,8 @@ pub struct DisplayFlags { } impl McBufReadable for DisplayFlags { - fn read_into(buf: &mut impl Read) -> Result { - let data = u32::read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let data = u32::read_from(buf)?; Ok(DisplayFlags { background: (data & 0b1) != 0, show_toast: (data & 0b10) != 0, diff --git a/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs index 3eca2a84..c1f57cda 100644 --- a/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs @@ -34,7 +34,7 @@ enum Operation { } impl McBufReadable for Operation { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { match buf.read_byte()? { 0 => Ok(Operation::Addition), 1 => Ok(Operation::MultiplyBase), diff --git a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs index 05d57695..dc434eb7 100644 --- a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs @@ -49,15 +49,15 @@ impl McBufWritable for ShapedRecipe { } } impl McBufReadable for ShapedRecipe { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { let width = buf.read_varint()?.try_into().unwrap(); let height = buf.read_varint()?.try_into().unwrap(); let group = buf.read_utf()?; let mut ingredients = Vec::with_capacity(width * height); for _ in 0..width * height { - ingredients.push(Ingredient::read_into(buf)?); + ingredients.push(Ingredient::read_from(buf)?); } - let result = Slot::read_into(buf)?; + let result = Slot::read_from(buf)?; Ok(ShapedRecipe { width, @@ -129,17 +129,17 @@ impl McBufWritable for Recipe { } impl McBufReadable for Recipe { - fn read_into(buf: &mut impl Read) -> Result { - let recipe_type = ResourceLocation::read_into(buf)?; - let identifier = ResourceLocation::read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let recipe_type = ResourceLocation::read_from(buf)?; + let identifier = ResourceLocation::read_from(buf)?; // rust doesn't let us match ResourceLocation so we have to do a big // if-else chain :( let data = if recipe_type == ResourceLocation::new("minecraft:crafting_shapeless").unwrap() { - RecipeData::CraftingShapeless(ShapelessRecipe::read_into(buf)?) + RecipeData::CraftingShapeless(ShapelessRecipe::read_from(buf)?) } else if recipe_type == ResourceLocation::new("minecraft:crafting_shaped").unwrap() { - RecipeData::CraftingShaped(ShapedRecipe::read_into(buf)?) + RecipeData::CraftingShaped(ShapedRecipe::read_from(buf)?) } else if recipe_type == ResourceLocation::new("minecraft:crafting_special_armordye").unwrap() { @@ -197,17 +197,17 @@ impl McBufReadable for Recipe { { RecipeData::CraftingSpecialSuspiciousStew } else if recipe_type == ResourceLocation::new("minecraft:smelting").unwrap() { - RecipeData::Smelting(CookingRecipe::read_into(buf)?) + RecipeData::Smelting(CookingRecipe::read_from(buf)?) } else if recipe_type == ResourceLocation::new("minecraft:blasting").unwrap() { - RecipeData::Blasting(CookingRecipe::read_into(buf)?) + RecipeData::Blasting(CookingRecipe::read_from(buf)?) } else if recipe_type == ResourceLocation::new("minecraft:smoking").unwrap() { - RecipeData::Smoking(CookingRecipe::read_into(buf)?) + RecipeData::Smoking(CookingRecipe::read_from(buf)?) } else if recipe_type == ResourceLocation::new("minecraft:campfire_cooking").unwrap() { - RecipeData::CampfireCooking(CookingRecipe::read_into(buf)?) + RecipeData::CampfireCooking(CookingRecipe::read_from(buf)?) } else if recipe_type == ResourceLocation::new("minecraft:stonecutting").unwrap() { - RecipeData::Stonecutting(StoneCuttingRecipe::read_into(buf)?) + RecipeData::Stonecutting(StoneCuttingRecipe::read_from(buf)?) } else if recipe_type == ResourceLocation::new("minecraft:smithing").unwrap() { - RecipeData::Smithing(SmithingRecipe::read_into(buf)?) + RecipeData::Smithing(SmithingRecipe::read_from(buf)?) } else { panic!("Unknown recipe type sent by server: {}", recipe_type); }; diff --git a/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs index cf3bc069..caa97d7b 100755 --- a/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs @@ -23,15 +23,15 @@ pub struct Tags { pub struct TagMap(HashMap>); impl McBufReadable for TagMap { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { let length = buf.read_varint()? as usize; let mut data = HashMap::with_capacity(length); for _ in 0..length { - let tag_type = ResourceLocation::read_into(buf)?; + let tag_type = ResourceLocation::read_from(buf)?; let tags_count = buf.read_varint()? as usize; let mut tags_vec = Vec::with_capacity(tags_count); for _ in 0..tags_count { - let tags = Tags::read_into(buf)?; + let tags = Tags::read_from(buf)?; tags_vec.push(tags); } data.insert(tag_type, tags_vec); @@ -51,8 +51,8 @@ impl McBufWritable for TagMap { } } impl McBufReadable for Tags { - fn read_into(buf: &mut impl Read) -> Result { - let name = ResourceLocation::read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let name = ResourceLocation::read_from(buf)?; let elements = buf.read_int_id_list()?; Ok(Tags { name, elements }) } diff --git a/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs b/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs index bd2edf38..a06b999b 100755 --- a/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs +++ b/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs @@ -25,7 +25,7 @@ impl ClientboundGameProfilePacket { } pub fn read(buf: &mut impl Read) -> Result { - let uuid = Uuid::read_into(buf)?; + let uuid = Uuid::read_from(buf)?; let name = buf.read_utf_with_len(16)?; Ok(ClientboundGameProfilePacket { game_profile: GameProfile::new(uuid, name), diff --git a/azalea-protocol/src/packets/login/serverbound_key_packet.rs b/azalea-protocol/src/packets/login/serverbound_key_packet.rs index 12b7c4ec..7a21736b 100644 --- a/azalea-protocol/src/packets/login/serverbound_key_packet.rs +++ b/azalea-protocol/src/packets/login/serverbound_key_packet.rs @@ -18,13 +18,13 @@ pub enum NonceOrSaltSignature { } impl McBufReadable for NonceOrSaltSignature { - fn read_into(buf: &mut impl Read) -> Result { - let is_nonce = bool::read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let is_nonce = bool::read_from(buf)?; if is_nonce { - Ok(NonceOrSaltSignature::Nonce(Vec::::read_into(buf)?)) + Ok(NonceOrSaltSignature::Nonce(Vec::::read_from(buf)?)) } else { Ok(NonceOrSaltSignature::SaltSignature( - SaltSignaturePair::read_into(buf)?, + SaltSignaturePair::read_from(buf)?, )) } } diff --git a/azalea-protocol/src/packets/mod.rs b/azalea-protocol/src/packets/mod.rs index 1c2533e2..2f439cd5 100755 --- a/azalea-protocol/src/packets/mod.rs +++ b/azalea-protocol/src/packets/mod.rs @@ -51,7 +51,7 @@ where } impl azalea_buf::McBufReadable for ConnectionProtocol { - fn read_into(buf: &mut impl Read) -> Result { + fn read_from(buf: &mut impl Read) -> Result { ConnectionProtocol::from_i32(buf.read_varint()?) .ok_or_else(|| "Invalid intention".to_string()) } diff --git a/azalea-world/src/chunk.rs b/azalea-world/src/chunk.rs index 27ef1ca7..a19ece8c 100644 --- a/azalea-world/src/chunk.rs +++ b/azalea-world/src/chunk.rs @@ -117,7 +117,7 @@ impl Chunk { let section_count = world_height / SECTION_HEIGHT; let mut sections = Vec::with_capacity(section_count as usize); for _ in 0..section_count { - let section = Section::read_into(buf)?; + let section = Section::read_from(buf)?; sections.push(section); } Ok(Chunk { sections }) @@ -171,8 +171,8 @@ pub struct Section { } impl McBufReadable for Section { - fn read_into(buf: &mut impl Read) -> Result { - let block_count = u16::read_into(buf)?; + fn read_from(buf: &mut impl Read) -> Result { + let block_count = u16::read_from(buf)?; // this is commented out because the vanilla server is wrong // assert!( diff --git a/azalea-world/src/palette.rs b/azalea-world/src/palette.rs index 4779dc4b..1b40f257 100644 --- a/azalea-world/src/palette.rs +++ b/azalea-world/src/palette.rs @@ -37,7 +37,7 @@ impl PalettedContainer { PalettedContainerType::Biomes => 64, }; - let data = Vec::::read_into(buf)?; + let data = Vec::::read_from(buf)?; debug_assert!( bits_per_entry != 0 || data.is_empty(), "Bits per entry is 0 but data is not empty." @@ -92,9 +92,9 @@ impl Palette { bits_per_entry: u8, ) -> Result { Ok(match bits_per_entry { - 0 => Palette::SingleValue(u32::var_read_into(buf)?), - 1..=4 => Palette::Linear(Vec::::var_read_into(buf)?), - 5..=8 => Palette::Hashmap(Vec::::var_read_into(buf)?), + 0 => Palette::SingleValue(u32::var_read_from(buf)?), + 1..=4 => Palette::Linear(Vec::::var_read_from(buf)?), + 5..=8 => Palette::Hashmap(Vec::::var_read_from(buf)?), _ => Palette::Global, }) } @@ -104,8 +104,8 @@ impl Palette { bits_per_entry: u8, ) -> Result { Ok(match bits_per_entry { - 0 => Palette::SingleValue(u32::var_read_into(buf)?), - 1..=3 => Palette::Linear(Vec::::var_read_into(buf)?), + 0 => Palette::SingleValue(u32::var_read_from(buf)?), + 1..=3 => Palette::Linear(Vec::::var_read_from(buf)?), _ => Palette::Global, }) }