mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
read_into -> read_from
yeah
This commit is contained in:
parent
c9faf25fab
commit
cd9a05e5a6
33 changed files with 180 additions and 180 deletions
|
@ -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<Self, String> {
|
||||
fn read_from(buf: &mut impl std::io::Read) -> Result<Self, String> {
|
||||
#(#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<Self, String>
|
||||
fn read_from(buf: &mut impl std::io::Read) -> Result<Self, String>
|
||||
{
|
||||
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)),
|
||||
|
|
|
@ -42,9 +42,9 @@ impl BitSet {
|
|||
}
|
||||
|
||||
impl McBufReadable for BitSet {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
Ok(Self {
|
||||
data: Vec::<u64>::read_into(buf)?,
|
||||
data: Vec::<u64>::read_from(buf)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -201,31 +201,31 @@ pub trait McBufReadable
|
|||
where
|
||||
Self: Sized,
|
||||
{
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String>;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String>;
|
||||
}
|
||||
|
||||
pub trait McBufVarReadable
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
fn var_read_into(buf: &mut impl Read) -> Result<Self, String>;
|
||||
fn var_read_from(buf: &mut impl Read) -> Result<Self, String>;
|
||||
}
|
||||
|
||||
impl McBufReadable for i32 {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
Readable::read_int(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufVarReadable for i32 {
|
||||
fn var_read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn var_read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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<Self, String> {
|
||||
fn var_read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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<Self, String> {
|
||||
i64::var_read_into(buf).map(|i| i as u64)
|
||||
fn var_read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
i64::var_read_from(buf).map(|i| i as u64)
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufReadable for UnsizedByteArray {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
Ok(buf.read_bytes()?.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: McBufReadable + Send> McBufReadable for Vec<T> {
|
||||
default fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
default fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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<K: McBufReadable + Send + Eq + Hash, V: McBufReadable + Send> McBufReadable for HashMap<K, V> {
|
||||
default fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
default fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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<u8> {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
buf.read_byte_array()
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufReadable for String {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
buf.read_utf()
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufReadable for u32 {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
Readable::read_int(buf).map(|i| i as u32)
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufVarReadable for u32 {
|
||||
fn var_read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn var_read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
buf.read_varint().map(|i| i as u32)
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufReadable for u16 {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
buf.read_short().map(|i| i as u16)
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufReadable for i16 {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
buf.read_short()
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufVarReadable for u16 {
|
||||
fn var_read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn var_read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
buf.read_varint().map(|i| i as u16)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: McBufVarReadable> McBufVarReadable for Vec<T> {
|
||||
fn var_read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn var_read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
buf.read_long()
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufReadable for u64 {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
i64::read_into(buf).map(|i| i as u64)
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
i64::read_from(buf).map(|i| i as u64)
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufReadable for bool {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
buf.read_boolean()
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufReadable for u8 {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
buf.read_byte()
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufReadable for i8 {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
buf.read_byte().map(|i| i as i8)
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufReadable for f32 {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
buf.read_float()
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufReadable for f64 {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
buf.read_double()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: McBufReadable> McBufReadable for Option<T> {
|
||||
default fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
default fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let present = buf.read_boolean()?;
|
||||
Ok(if present {
|
||||
Some(T::read_into(buf)?)
|
||||
Some(T::read_from(buf)?)
|
||||
} else {
|
||||
None
|
||||
})
|
||||
|
|
|
@ -33,7 +33,7 @@ impl SerializableUuid for Uuid {
|
|||
}
|
||||
|
||||
impl McBufReadable for Uuid {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
Ok(Uuid::from_int_array([
|
||||
Readable::read_int(buf)? as u32,
|
||||
Readable::read_int(buf)? as u32,
|
||||
|
|
|
@ -269,8 +269,8 @@ impl<'de> Deserialize<'de> for Component {
|
|||
}
|
||||
|
||||
impl McBufReadable for Component {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let string = String::read_into(buf)?;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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<Self, String>
|
||||
// async fn read_from(buf: &mut impl Read) -> Result<Self, String>
|
||||
// where
|
||||
// R: AsyncRead + std::marker::Unpin + std::marker::Send,
|
||||
// {
|
||||
|
|
|
@ -67,8 +67,8 @@ impl Difficulty {
|
|||
}
|
||||
|
||||
impl McBufReadable for Difficulty {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
Ok(Difficulty::by_id(u8::read_into(buf)?))
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
Ok(Difficulty::by_id(u8::read_from(buf)?))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -77,8 +77,8 @@ impl GameType {
|
|||
}
|
||||
|
||||
impl McBufReadable for GameType {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
GameType::from_id(u8::read_into(buf)?)
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
GameType::from_id(u8::read_from(buf)?)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,8 +105,8 @@ impl From<OptionalGameType> for Option<GameType> {
|
|||
}
|
||||
|
||||
impl McBufReadable for OptionalGameType {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
GameType::from_optional_id(i8::read_into(buf)?)
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
GameType::from_optional_id(i8::read_from(buf)?)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Self, String> {
|
||||
let id = u32::var_read_into(buf)?;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let id = u32::var_read_from(buf)?;
|
||||
ParticleData::read_from_particle_id(buf, id)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -225,8 +225,8 @@ impl From<&EntityPos> for ChunkPos {
|
|||
}
|
||||
|
||||
impl McBufReadable for BlockPos {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let val = u64::read_into(buf)?;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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<Self, String> {
|
||||
let long = i64::read_into(buf)?;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let long = i64::read_from(buf)?;
|
||||
Ok(ChunkSectionPos {
|
||||
x: (long >> 42) as i32,
|
||||
y: (long << 44 >> 44) as i32,
|
||||
|
|
|
@ -46,8 +46,8 @@ impl std::fmt::Debug for ResourceLocation {
|
|||
}
|
||||
|
||||
impl McBufReadable for ResourceLocation {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let location_string = String::read_into(buf)?;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -18,12 +18,12 @@ pub struct SlotData {
|
|||
}
|
||||
|
||||
impl McBufReadable for Slot {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let present = bool::read_into(buf)?;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ pub struct SaltSignaturePair {
|
|||
}
|
||||
|
||||
impl McBufReadable for SaltSignaturePair {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let salt = u64::read_into(buf)?;
|
||||
let signature = Vec::<u8>::read_into(buf)?;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let salt = u64::read_from(buf)?;
|
||||
let signature = Vec::<u8>::read_from(buf)?;
|
||||
Ok(SaltSignaturePair { salt, signature })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,14 +17,14 @@ pub struct EntityDataItem {
|
|||
}
|
||||
|
||||
impl McBufReadable for EntityMetadata {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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<Self, String> {
|
||||
let data_type = i32::var_read_into(buf)?;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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::<Component>::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::<Component>::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::<BlockPos>::read_into(buf)?),
|
||||
11 => EntityDataValue::Direction(Direction::read_into(buf)?),
|
||||
12 => EntityDataValue::OptionalUuid(Option::<Uuid>::read_into(buf)?),
|
||||
9 => EntityDataValue::BlockPos(BlockPos::read_from(buf)?),
|
||||
10 => EntityDataValue::OptionalBlockPos(Option::<BlockPos>::read_from(buf)?),
|
||||
11 => EntityDataValue::Direction(Direction::read_from(buf)?),
|
||||
12 => EntityDataValue::OptionalUuid(Option::<Uuid>::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)),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ impl Tag {
|
|||
}
|
||||
|
||||
impl McBufReadable for Tag {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
match Tag::read(buf) {
|
||||
Ok(r) => Ok(r),
|
||||
// Err(e) => Err(e.to_string()),
|
||||
|
|
|
@ -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![(
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -25,15 +25,15 @@ pub struct BrigadierNumber<T> {
|
|||
max: Option<T>,
|
||||
}
|
||||
impl<T: McBufReadable> McBufReadable for BrigadierNumber<T> {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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<Self, String> {
|
||||
let parser_type = u32::var_read_into(buf)?;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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<Self, String> {
|
||||
let flags = u8::read_into(buf)?;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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
|
||||
};
|
||||
|
|
|
@ -20,17 +20,17 @@ pub struct ClientboundLevelParticlesPacket {
|
|||
}
|
||||
|
||||
impl McBufReadable for ClientboundLevelParticlesPacket {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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<Self, String> {
|
||||
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)?;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ pub struct PlayerAbilitiesFlags {
|
|||
}
|
||||
|
||||
impl McBufReadable for PlayerAbilitiesFlags {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let byte = buf.read_byte()?;
|
||||
Ok(PlayerAbilitiesFlags {
|
||||
invulnerable: byte & 1 != 0,
|
||||
|
|
|
@ -63,14 +63,14 @@ pub struct RemovePlayer {
|
|||
}
|
||||
|
||||
impl McBufReadable for Action {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let id = buf.read_byte()?;
|
||||
Ok(match id {
|
||||
0 => Action::AddPlayer(Vec::<AddPlayer>::read_into(buf)?),
|
||||
1 => Action::UpdateGameMode(Vec::<UpdateGameMode>::read_into(buf)?),
|
||||
2 => Action::UpdateLatency(Vec::<UpdateLatency>::read_into(buf)?),
|
||||
3 => Action::UpdateDisplayName(Vec::<UpdateDisplayName>::read_into(buf)?),
|
||||
4 => Action::RemovePlayer(Vec::<RemovePlayer>::read_into(buf)?),
|
||||
0 => Action::AddPlayer(Vec::<AddPlayer>::read_from(buf)?),
|
||||
1 => Action::UpdateGameMode(Vec::<UpdateGameMode>::read_from(buf)?),
|
||||
2 => Action::UpdateLatency(Vec::<UpdateLatency>::read_from(buf)?),
|
||||
3 => Action::UpdateDisplayName(Vec::<UpdateDisplayName>::read_from(buf)?),
|
||||
4 => Action::RemovePlayer(Vec::<RemovePlayer>::read_from(buf)?),
|
||||
_ => panic!("Unknown player info action id: {}", id),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ pub struct RelativeArguments {
|
|||
}
|
||||
|
||||
impl McBufReadable for RelativeArguments {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let byte = buf.read_byte()?;
|
||||
Ok(RelativeArguments {
|
||||
x: byte & 0b1 != 0,
|
||||
|
|
|
@ -41,7 +41,7 @@ impl McBufWritable for State {
|
|||
}
|
||||
}
|
||||
impl McBufReadable for State {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let state = buf.read_varint()?;
|
||||
Ok(match state {
|
||||
0 => State::Init,
|
||||
|
|
|
@ -18,8 +18,8 @@ pub struct BlockStateWithPosition {
|
|||
}
|
||||
|
||||
impl McBufReadable for BlockStateWithPosition {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let data = u64::var_read_into(buf)?;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let data = u64::var_read_from(buf)?;
|
||||
let position_part = data & 4095;
|
||||
let state = (data >> 12) as u32;
|
||||
let position = ChunkSectionBlockPos {
|
||||
|
|
|
@ -17,14 +17,14 @@ pub struct EquipmentSlots {
|
|||
}
|
||||
|
||||
impl McBufReadable for EquipmentSlots {
|
||||
fn read_into(buf: &mut impl std::io::Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl std::io::Read) -> Result<Self, String> {
|
||||
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;
|
||||
|
|
|
@ -45,8 +45,8 @@ pub struct DisplayFlags {
|
|||
}
|
||||
|
||||
impl McBufReadable for DisplayFlags {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let data = u32::read_into(buf)?;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let data = u32::read_from(buf)?;
|
||||
Ok(DisplayFlags {
|
||||
background: (data & 0b1) != 0,
|
||||
show_toast: (data & 0b10) != 0,
|
||||
|
|
|
@ -34,7 +34,7 @@ enum Operation {
|
|||
}
|
||||
|
||||
impl McBufReadable for Operation {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
match buf.read_byte()? {
|
||||
0 => Ok(Operation::Addition),
|
||||
1 => Ok(Operation::MultiplyBase),
|
||||
|
|
|
@ -49,15 +49,15 @@ impl McBufWritable for ShapedRecipe {
|
|||
}
|
||||
}
|
||||
impl McBufReadable for ShapedRecipe {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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<Self, String> {
|
||||
let recipe_type = ResourceLocation::read_into(buf)?;
|
||||
let identifier = ResourceLocation::read_into(buf)?;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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);
|
||||
};
|
||||
|
|
|
@ -23,15 +23,15 @@ pub struct Tags {
|
|||
pub struct TagMap(HashMap<ResourceLocation, Vec<Tags>>);
|
||||
|
||||
impl McBufReadable for TagMap {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
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<Self, String> {
|
||||
let name = ResourceLocation::read_into(buf)?;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let name = ResourceLocation::read_from(buf)?;
|
||||
let elements = buf.read_int_id_list()?;
|
||||
Ok(Tags { name, elements })
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ impl ClientboundGameProfilePacket {
|
|||
}
|
||||
|
||||
pub fn read(buf: &mut impl Read) -> Result<LoginPacket, String> {
|
||||
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),
|
||||
|
|
|
@ -18,13 +18,13 @@ pub enum NonceOrSaltSignature {
|
|||
}
|
||||
|
||||
impl McBufReadable for NonceOrSaltSignature {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let is_nonce = bool::read_into(buf)?;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let is_nonce = bool::read_from(buf)?;
|
||||
if is_nonce {
|
||||
Ok(NonceOrSaltSignature::Nonce(Vec::<u8>::read_into(buf)?))
|
||||
Ok(NonceOrSaltSignature::Nonce(Vec::<u8>::read_from(buf)?))
|
||||
} else {
|
||||
Ok(NonceOrSaltSignature::SaltSignature(
|
||||
SaltSignaturePair::read_into(buf)?,
|
||||
SaltSignaturePair::read_from(buf)?,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ where
|
|||
}
|
||||
|
||||
impl azalea_buf::McBufReadable for ConnectionProtocol {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
ConnectionProtocol::from_i32(buf.read_varint()?)
|
||||
.ok_or_else(|| "Invalid intention".to_string())
|
||||
}
|
||||
|
|
|
@ -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<Self, String> {
|
||||
let block_count = u16::read_into(buf)?;
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let block_count = u16::read_from(buf)?;
|
||||
|
||||
// this is commented out because the vanilla server is wrong
|
||||
// assert!(
|
||||
|
|
|
@ -37,7 +37,7 @@ impl PalettedContainer {
|
|||
PalettedContainerType::Biomes => 64,
|
||||
};
|
||||
|
||||
let data = Vec::<u64>::read_into(buf)?;
|
||||
let data = Vec::<u64>::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<Palette, String> {
|
||||
Ok(match bits_per_entry {
|
||||
0 => Palette::SingleValue(u32::var_read_into(buf)?),
|
||||
1..=4 => Palette::Linear(Vec::<u32>::var_read_into(buf)?),
|
||||
5..=8 => Palette::Hashmap(Vec::<u32>::var_read_into(buf)?),
|
||||
0 => Palette::SingleValue(u32::var_read_from(buf)?),
|
||||
1..=4 => Palette::Linear(Vec::<u32>::var_read_from(buf)?),
|
||||
5..=8 => Palette::Hashmap(Vec::<u32>::var_read_from(buf)?),
|
||||
_ => Palette::Global,
|
||||
})
|
||||
}
|
||||
|
@ -104,8 +104,8 @@ impl Palette {
|
|||
bits_per_entry: u8,
|
||||
) -> Result<Palette, String> {
|
||||
Ok(match bits_per_entry {
|
||||
0 => Palette::SingleValue(u32::var_read_into(buf)?),
|
||||
1..=3 => Palette::Linear(Vec::<u32>::var_read_into(buf)?),
|
||||
0 => Palette::SingleValue(u32::var_read_from(buf)?),
|
||||
1..=3 => Palette::Linear(Vec::<u32>::var_read_from(buf)?),
|
||||
_ => Palette::Global,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue