Skip to content

Commit

Permalink
1.16.1 protocol support (736) (iceiix#345)
Browse files Browse the repository at this point in the history
* Update shifted packet ids

* Add new smithing recipe type

* Also support 1.16 (735), same packets as 1.16.1 (736)

New packets:

* GenerateStructure

New packet variants:

* UseEntity_Sneakflag, split from UseEntity_Hand

* ClientAbilities_u8, split from ClientAbilities_f32

* UpdateJigsawBlock_Joint, split from UpdateJigsawBlock_Type

* ServerMessage_Sender, split from ServerMessage_Position

* ChunkData_Biomes3D_bool, split from ChunkData_Biomes3D

* JoinGame_WorldNames, split from JoinGame_HashedSeed_Respawn

* Respawn_WorldName, split from Respawn_Gamemode

* EntityEquipment_VarInt renamed

* UpdateLight_WithTrust, split from UpdateLight_NoTrust

* LoginSuccess_UUID, split from LoginSuccess_String
  • Loading branch information
iceiix committed Jun 28, 2020
1 parent 0670e76 commit 0626888
Show file tree
Hide file tree
Showing 23 changed files with 475 additions and 129 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Join with your favorite IRC client or [Matrix](https://matrix.to/#/#_espernet_#s

| Game version | Protocol version | Supported? |
| ------ | --- | --- |
| 1.16.1 | 736 ||
| 1.16 | 735 ||
| 1.15.2 | 578 ||
| 1.15.1 | 575 ||
| 1.14.4 | 498 ||
Expand Down
5 changes: 3 additions & 2 deletions protocol/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ use std::net::TcpStream;
use std::sync::atomic::{AtomicBool, AtomicI32, Ordering};
use std::time::{Duration, Instant};

pub const SUPPORTED_PROTOCOLS: [i32; 19] = [
578, 575, 498, 490, 485, 480, 477, 452, 451, 404, 340, 316, 315, 210, 109, 107, 74, 47, 5,
pub const SUPPORTED_PROTOCOLS: [i32; 21] = [
736, 735, 578, 575, 498, 490, 485, 480, 477, 452, 451, 404, 340, 316, 315, 210, 109, 107, 74,
47, 5,
];

static CURRENT_PROTOCOL_VERSION: AtomicI32 = AtomicI32::new(SUPPORTED_PROTOCOLS[0]);
Expand Down
132 changes: 120 additions & 12 deletions protocol/src/protocol/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,22 @@ state_packets!(
}
/// UseEntity is sent when the user interacts (right clicks) or attacks
/// (left clicks) an entity.
packet UseEntity {
packet UseEntity_Sneakflag {
field target_id: VarInt =,
field ty: VarInt =,
field target_x: f32 = when(|p: &UseEntity| p.ty.0 == 2),
field target_y: f32 = when(|p: &UseEntity| p.ty.0 == 2),
field target_z: f32 = when(|p: &UseEntity| p.ty.0 == 2),
field hand: VarInt = when(|p: &UseEntity| p.ty.0 == 0 || p.ty.0 == 2),
field target_x: f32 = when(|p: &UseEntity_Sneakflag| p.ty.0 == 2),
field target_y: f32 = when(|p: &UseEntity_Sneakflag| p.ty.0 == 2),
field target_z: f32 = when(|p: &UseEntity_Sneakflag| p.ty.0 == 2),
field hand: VarInt = when(|p: &UseEntity_Sneakflag| p.ty.0 == 0 || p.ty.0 == 2),
field sneaking: bool =,
}
packet UseEntity_Hand {
field target_id: VarInt =,
field ty: VarInt =,
field target_x: f32 = when(|p: &UseEntity_Hand| p.ty.0 == 2),
field target_y: f32 = when(|p: &UseEntity_Hand| p.ty.0 == 2),
field target_z: f32 = when(|p: &UseEntity_Hand| p.ty.0 == 2),
field hand: VarInt = when(|p: &UseEntity_Hand| p.ty.0 == 0 || p.ty.0 == 2),
}
packet UseEntity_Handsfree {
field target_id: VarInt =,
Expand All @@ -198,6 +207,12 @@ state_packets!(
field target_id: i32 =,
field ty: u8 =,
}
/// Sent when Generate is pressed on the Jigsaw Block interface.
packet GenerateStructure {
field location: Position =,
field levels: VarInt =,
field keep_jigsaws: bool =,
}
/// KeepAliveServerbound is sent by a client as a response to a
/// KeepAliveClientbound. If the client doesn't reply the server
/// may disconnect the client.
Expand Down Expand Up @@ -280,11 +295,14 @@ state_packets!(
}
/// ClientAbilities is used to modify the players current abilities.
/// Currently flying is the only one
packet ClientAbilities {
packet ClientAbilities_f32 {
field flags: u8 =,
field flying_speed: f32 =,
field walking_speed: f32 =,
}
packet ClientAbilities_u8 {
field flags: u8 =,
}
/// PlayerDigging is sent when the client starts/stops digging a block.
/// It also can be sent for droppping items and eating/shooting.
packet PlayerDigging {
Expand Down Expand Up @@ -381,7 +399,15 @@ state_packets!(
field slot: i16 =,
field clicked_item: Option<item::Stack> =,
}
packet UpdateJigsawBlock {
packet UpdateJigsawBlock_Joint {
field location: Position =,
field name: String =,
field target: String =,
field pool: String =,
field final_state: String =,
field joint_type: String =,
}
packet UpdateJigsawBlock_Type {
field location: Position =,
field attachment_type: String =,
field target_pool: String =,
Expand Down Expand Up @@ -840,7 +866,13 @@ state_packets!(
/// ServerMessage is a message sent by the server. It could be from a player
/// or just a system message. The Type field controls the location the
/// message is displayed at and when the message is displayed.
packet ServerMessage {
packet ServerMessage_Sender {
field message: format::Component =,
/// 0 - Chat message, 1 - System message, 2 - Action bar message
field position: u8 =,
field sender: UUID =,
}
packet ServerMessage_Position {
field message: format::Component =,
/// 0 - Chat message, 1 - System message, 2 - Action bar message
field position: u8 =,
Expand Down Expand Up @@ -1015,6 +1047,17 @@ state_packets!(
}
/// ChunkData sends or updates a single chunk on the client. If New is set
/// then biome data should be sent too.
packet ChunkData_Biomes3D_bool {
field chunk_x: i32 =,
field chunk_z: i32 =,
field new: bool =,
field ignore_old_data: bool =,
field bitmask: VarInt =,
field heightmaps: Option<nbt::NamedTag> =,
field biomes: Biomes3D = when(|p: &ChunkData_Biomes3D_bool| p.new),
field data: LenPrefixedBytes<VarInt> =,
field block_entities: LenPrefixed<VarInt, Option<nbt::NamedTag>> =,
}
packet ChunkData_Biomes3D {
field chunk_x: i32 =,
field chunk_z: i32 =,
Expand Down Expand Up @@ -1157,6 +1200,38 @@ state_packets!(
}
/// JoinGame is sent after completing the login process. This
/// sets the initial state for the client.
packet JoinGame_WorldNames {
/// The entity id the client will be referenced by
field entity_id: i32 =,
/// The starting gamemode of the client
field gamemode: u8 =,
/// The previous gamemode of the client
field previous_gamemode: u8 =,
/// Identifiers for all worlds on the server
field world_names: LenPrefixed<VarInt, String> =,
/// Represents a dimension registry
field dimension_codec: Option<nbt::NamedTag> =,
/// The dimension the client is starting in
field dimension: String =,
/// The world being spawned into
field world_name: String =,
/// Truncated SHA-256 hash of world's seed
field hashed_seed: i64 =,
/// The max number of players on the server
field max_players: u8 =,
/// The render distance (2-32)
field view_distance: VarInt =,
/// Whether the client should reduce the amount of debug
/// information it displays in F3 mode
field reduced_debug_info: bool =,
/// Whether to prompt or immediately respawn
field enable_respawn_screen: bool =,
/// Whether the world is in debug mode
field is_debug: bool =,
/// Whether the world is a superflat world
field is_flat: bool =,
}

packet JoinGame_HashedSeed_Respawn {
/// The entity id the client will be referenced by
field entity_id: i32 =,
Expand Down Expand Up @@ -1476,7 +1551,7 @@ state_packets!(
field hash: String =,
}
/// Respawn is sent to respawn the player after death or when they move worlds.
packet Respawn {
packet Respawn_Gamemode {
field dimension: i32 =,
field difficulty: u8 =,
field gamemode: u8 =,
Expand All @@ -1489,6 +1564,16 @@ state_packets!(
field gamemode: u8 =,
field level_type: String =,
}
packet Respawn_WorldName {
field dimension: String =,
field world_name: String =,
field hashed_seed: i64 =,
field gamemode: u8 =,
field previous_gamemode: u8 =,
field is_debug: bool =,
field is_flat: bool =,
field copy_metadata: bool =,
}
/// EntityHeadLook rotates an entity's head to the new angle.
packet EntityHeadLook {
field entity_id: VarInt =,
Expand Down Expand Up @@ -1583,7 +1668,7 @@ state_packets!(
/// EntityEquipment is sent to display an item on an entity, like a sword
/// or armor. Slot 0 is the held item and slots 1 to 4 are boots, leggings
/// chestplate and helmet respectively.
packet EntityEquipment {
packet EntityEquipment_VarInt {
field entity_id: VarInt =,
field slot: VarInt =,
field item: Option<item::Stack> =,
Expand Down Expand Up @@ -1880,7 +1965,16 @@ state_packets!(
field status: VarInt =,
field successful: bool =,
}
packet UpdateLight {
packet UpdateLight_WithTrust {
field chunk_x: VarInt =,
field chunk_z: VarInt =,
field trust_edges: bool =,
field sky_light_mask: VarInt =,
field block_light_mask: VarInt =,
field empty_sky_light_mask: VarInt =,
field light_arrays: Vec<u8> =,
}
packet UpdateLight_NoTrust {
field chunk_x: VarInt =,
field chunk_z: VarInt =,
field sky_light_mask: VarInt =,
Expand Down Expand Up @@ -1965,11 +2059,15 @@ state_packets!(
/// LoginSuccess is sent by the server if the player successfully
/// authenicates with the session servers (online mode) or straight
/// after LoginStart (offline mode).
packet LoginSuccess {
packet LoginSuccess_String {
/// String encoding of a uuid (with hyphens)
field uuid: String =,
field username: String =,
}
packet LoginSuccess_UUID {
field uuid: UUID =,
field username: String =,
}
/// SetInitialCompression sets the compression threshold during the
/// login state.
packet SetInitialCompression {
Expand Down Expand Up @@ -2590,6 +2688,11 @@ pub enum RecipeData {
ingredient: RecipeIngredient,
result: Option<item::Stack>,
},
Smithing {
base: RecipeIngredient,
addition: RecipeIngredient,
result: Option<item::Stack>,
},
}

impl Default for RecipeData {
Expand Down Expand Up @@ -2704,6 +2807,11 @@ impl Serializable for Recipe {
ingredient: Serializable::read_from(buf)?,
result: Serializable::read_from(buf)?,
},
"minecraft:smithing" => RecipeData::Smithing {
base: Serializable::read_from(buf)?,
addition: Serializable::read_from(buf)?,
result: Serializable::read_from(buf)?,
},
_ => panic!("unrecognized recipe type: {}", ty),
};

Expand Down
5 changes: 5 additions & 0 deletions protocol/src/protocol/versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod v1_14_2;
mod v1_14_3;
mod v1_14_4;
mod v1_15;
mod v1_16_1;
mod v1_7_10;
mod v1_8_9;
mod v1_9;
Expand All @@ -24,6 +25,8 @@ mod v1_9_2;
pub fn protocol_name_to_protocol_version(s: String) -> i32 {
match s.as_ref() {
"" => SUPPORTED_PROTOCOLS[0],
"1.16.1" => 736,
"1.16" => 735,
"1.15.2" => 578,
"1.15.1" => 575,
"1.14.4" => 498,
Expand Down Expand Up @@ -61,6 +64,8 @@ pub fn translate_internal_packet_id_for_version(
to_internal: bool,
) -> i32 {
match version {
736 => v1_16_1::translate_internal_packet_id(state, dir, id, to_internal),
735 => v1_16_1::translate_internal_packet_id(state, dir, id, to_internal),
578 => v1_15::translate_internal_packet_id(state, dir, id, to_internal),
575 => v1_15::translate_internal_packet_id(state, dir, id, to_internal),
498 => v1_14_4::translate_internal_packet_id(state, dir, id, to_internal),
Expand Down
12 changes: 6 additions & 6 deletions protocol/src/protocol/versions/v15w39c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ protocol_packet_ids!(
0x06 => ClickWindow_u8
0x07 => CloseWindow
0x08 => PluginMessageServerbound
0x09 => UseEntity
0x09 => UseEntity_Hand
0x0a => KeepAliveServerbound_VarInt
0x0b => PlayerPosition
0x0c => PlayerPositionLook
0x0d => PlayerLook
0x0e => Player
0x0f => ClientAbilities
0x0f => ClientAbilities_f32
0x10 => PlayerDigging_u8
0x11 => PlayerAction
0x12 => SteerVehicle
Expand Down Expand Up @@ -52,7 +52,7 @@ protocol_packet_ids!(
0x0c => BossBar
0x0d => ServerDifficulty
0x0e => TabCompleteReply
0x0f => ServerMessage
0x0f => ServerMessage_Position
0x10 => MultiBlockChange_VarInt
0x11 => ConfirmTransaction
0x12 => WindowClose
Expand Down Expand Up @@ -88,7 +88,7 @@ protocol_packet_ids!(
0x30 => EntityDestroy
0x31 => EntityRemoveEffect
0x32 => ResourcePackSend
0x33 => Respawn
0x33 => Respawn_Gamemode
0x34 => EntityHeadLook
0x35 => WorldBorder
0x36 => Camera
Expand All @@ -97,7 +97,7 @@ protocol_packet_ids!(
0x39 => EntityMetadata
0x3a => EntityAttach_leashed
0x3b => EntityVelocity
0x3c => EntityEquipment
0x3c => EntityEquipment_VarInt
0x3d => SetExperience
0x3e => UpdateHealth
0x3f => ScoreboardObjective
Expand All @@ -122,7 +122,7 @@ protocol_packet_ids!(
clientbound Clientbound {
0x00 => LoginDisconnect
0x01 => EncryptionRequest
0x02 => LoginSuccess
0x02 => LoginSuccess_String
0x03 => SetInitialCompression
}
}
Expand Down
Loading

0 comments on commit 0626888

Please sign in to comment.