Misc protocol fixes: position (fixes #301), 1.14+ block place, spawn object (#343)

* some protocol fixes

* remove newline
This commit is contained in:
Kezi 2020-06-27 23:08:33 +02:00 committed by GitHub
parent 3f35673c77
commit dde28b48b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 40 additions and 16 deletions

View File

@ -940,14 +940,15 @@ impl Serializable for Position {
let pos = buf.read_u64::<BigEndian>()?;
Ok(Position::new(
((pos as i64) >> 38) as i32,
(((pos as i64) >> 26) & 0xFFF) as i32,
((pos as i64) << 38 >> 38) as i32,
(((pos as i64)) & 0xFFF) as i32,
((pos as i64) << 26 >> 38) as i32
))
}
fn write_to<W: io::Write>(&self, buf: &mut W) -> Result<(), Error> {
let pos = (((self.x as u64) & 0x3FFFFFF) << 38)
| (((self.y as u64) & 0xFFF) << 26)
| ((self.z as u64) & 0x3FFFFFF);
| ((self.y as u64) & 0xFFF)
| (((self.z as u64) & 0x3FFFFFF) << 12);
buf.write_u64::<BigEndian>(pos)?;
Result::Ok(())
}

View File

@ -473,6 +473,15 @@ state_packets!(
field cursor_y: u8 =,
field cursor_z: u8 =,
}
packet PlayerBlockPlacement_insideblock {
field hand: VarInt =,
field location: Position =,
field face: VarInt =,
field cursor_x: f32 =,
field cursor_y: f32 =,
field cursor_z: f32 =,
field inside_block: bool =, //1.14 added insideblock
}
/// UseItem is sent when the client tries to use an item.
packet UseItem {
@ -523,6 +532,20 @@ state_packets!(
field velocity_y: i16 = when(|p: &SpawnObject_i32_NoUUID| p.data != 0),
field velocity_z: i16 = when(|p: &SpawnObject_i32_NoUUID| p.data != 0),
}
packet SpawnObject_VarInt {
field entity_id: VarInt =,
field uuid: UUID =,
field ty: VarInt =, //1.14 changed u8 to VarInt
field x: f64 =,
field y: f64 =,
field z: f64 =,
field pitch: i8 =,
field yaw: i8 =,
field data: i32 =,
field velocity_x: i16 =,
field velocity_y: i16 =,
field velocity_z: i16 =,
}
/// SpawnExperienceOrb spawns a single experience orb into the world when
/// it is in range of the client. The count controls the amount of experience
/// gained when collected.

View File

@ -52,11 +52,11 @@ protocol_packet_ids!(
0x29 => SetSign
0x2a => ArmSwing
0x2b => SpectateTeleport
0x2c => PlayerBlockPlacement_f32
0x2c => PlayerBlockPlacement_insideblock
0x2d => UseItem
}
clientbound Clientbound {
0x00 => SpawnObject
0x00 => SpawnObject_VarInt
0x01 => SpawnExperienceOrb
0x02 => SpawnGlobalEntity
0x03 => SpawnMob_WithMeta

View File

@ -52,11 +52,11 @@ protocol_packet_ids!(
0x29 => SetSign
0x2a => ArmSwing
0x2b => SpectateTeleport
0x2c => PlayerBlockPlacement_f32
0x2c => PlayerBlockPlacement_insideblock
0x2d => UseItem
}
clientbound Clientbound {
0x00 => SpawnObject
0x00 => SpawnObject_VarInt
0x01 => SpawnExperienceOrb
0x02 => SpawnGlobalEntity
0x03 => SpawnMob_WithMeta

View File

@ -52,11 +52,11 @@ protocol_packet_ids!(
0x29 => SetSign
0x2a => ArmSwing
0x2b => SpectateTeleport
0x2c => PlayerBlockPlacement_f32
0x2c => PlayerBlockPlacement_insideblock
0x2d => UseItem
}
clientbound Clientbound {
0x00 => SpawnObject
0x00 => SpawnObject_VarInt
0x01 => SpawnExperienceOrb
0x02 => SpawnGlobalEntity
0x03 => SpawnMob_WithMeta

View File

@ -52,11 +52,11 @@ protocol_packet_ids!(
0x29 => SetSign
0x2a => ArmSwing
0x2b => SpectateTeleport
0x2c => PlayerBlockPlacement_f32
0x2c => PlayerBlockPlacement_insideblock
0x2d => UseItem
}
clientbound Clientbound {
0x00 => SpawnObject
0x00 => SpawnObject_VarInt
0x01 => SpawnExperienceOrb
0x02 => SpawnGlobalEntity
0x03 => SpawnMob_WithMeta

View File

@ -52,11 +52,11 @@ protocol_packet_ids!(
0x29 => SetSign
0x2a => ArmSwing
0x2b => SpectateTeleport
0x2c => PlayerBlockPlacement_f32
0x2c => PlayerBlockPlacement_insideblock
0x2d => UseItem
}
clientbound Clientbound {
0x00 => SpawnObject
0x00 => SpawnObject_VarInt
0x01 => SpawnExperienceOrb
0x02 => SpawnGlobalEntity
0x03 => SpawnMob_WithMeta

View File

@ -52,11 +52,11 @@ protocol_packet_ids!(
0x29 => SetSign
0x2a => ArmSwing
0x2b => SpectateTeleport
0x2c => PlayerBlockPlacement_f32
0x2c => PlayerBlockPlacement_insideblock
0x2d => UseItem
}
clientbound Clientbound {
0x00 => SpawnObject
0x00 => SpawnObject_VarInt
0x01 => SpawnExperienceOrb
0x02 => SpawnGlobalEntity
0x03 => SpawnMob_NoMeta