Skip to content

Commit

Permalink
1.18.1 protocol (757) (iceiix#640)
Browse files Browse the repository at this point in the history
https://wiki.vg/index.php?title=Protocol&oldid=17203 1.18.1
https://wiki.vg/index.php?title=Protocol&type=revision&diff=17203&oldid=16918 1.18.1 vs 1.17.1

* protocol: add UpdateSimulationDistance packet and update IDs
* protocol: add JoinGame_WorldNames_IsHard_SimDist packet variant
* protocol: add UpdateBlockEntity_VarInt packet variant
* protocol: start adding ChunkData_AndLight, combining ChunkData + UpdateLight
* protocol: ChunkData_AndLight: add struct BlockEntityAtPackedLocation

* server: handle JoinGame_WorldNames_IsHard_SimDist packet variant
* server: handle combined chunk data and light packet
* server: on_chunk_data_and_light: set all bits in now-removed bitmask

* bit map: add derived std::fmt::Debug implementation
* bit map: allow creating, but not accessing, zero-length bit maps

* world: sanity check chunk bit_size, failing earlier
* world: read biome data bits after palette
* world: support single-valued palettes
* world: handle single-valued biomes
* world: add checks for direct palettes; update comments
* world: parse dimension tags
* world: load dimension type tags: min_y
* world: skip chunk sections underneath y<0
* world: force filling sky on 1.18+ for now, workaround until mask/fill_sky can be calculated correctly wrt min_y

* readme: add 1.18.1 (757)
  • Loading branch information
iceiix authored Aug 6, 2022
1 parent 2e224a7 commit 1f183ed
Show file tree
Hide file tree
Showing 27 changed files with 471 additions and 44 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Discussion forum: [https://github.com/iceiix/stevenarella/discussions](https://g

| Game version | Protocol version | Supported? |
| ------ | --- | --- |
| 1.18.1 | 757 ||
| 1.17.1 | 756 ||
| 1.16.5 | 754 ||
| 1.16.4 | 754 ||
Expand Down
6 changes: 3 additions & 3 deletions protocol/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ use std::io::{Read, Write};
use std::net::TcpStream;
use std::sync::atomic::{AtomicBool, AtomicI32, Ordering};

pub const SUPPORTED_PROTOCOLS: [i32; 25] = [
756, 754, 753, 751, 736, 735, 578, 575, 498, 490, 485, 480, 477, 452, 451, 404, 340, 316, 315,
210, 109, 107, 74, 47, 5,
pub const SUPPORTED_PROTOCOLS: [i32; 26] = [
757, 756, 754, 753, 751, 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
89 changes: 88 additions & 1 deletion protocol/src/protocol/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,12 @@ state_packets!(
}
/// UpdateBlockEntity updates the nbt tag of a block entity in the
/// world.
packet UpdateBlockEntity {
packet UpdateBlockEntity_VarInt {
field location: Position =,
field action: VarInt =,
field nbt: Option<nbt::NamedTag> =,
}
packet UpdateBlockEntity_u8 {
field location: Position =,
field action: u8 =,
field nbt: Option<nbt::NamedTag> =,
Expand Down Expand Up @@ -1132,6 +1137,21 @@ 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_AndLight {
field chunk_x: i32 =,
field chunk_z: i32 =,
field heightmaps: Option<nbt::NamedTag> =,
field data: LenPrefixedBytes<VarInt> =,
field block_entities: LenPrefixed<VarInt, packet::BlockEntityAtPackedLocation> =,

field trust_edges: bool =,
field sky_light_mask: LenPrefixed<VarInt, i64> =,
field block_light_mask: LenPrefixed<VarInt, i64> =,
field empty_sky_light_mask: LenPrefixed<VarInt, i64> =,
field empty_block_light_mask: LenPrefixed<VarInt, i64> =,
field sky_light_arrays: LenPrefixed<VarInt, LenPrefixed<VarInt, u8>> =,
field block_light_arrays: LenPrefixed<VarInt, LenPrefixed<VarInt, u8>> =,
}
packet ChunkData_Biomes3D_Bitmasks {
field chunk_x: i32 =,
field chunk_z: i32 =,
Expand Down Expand Up @@ -1324,6 +1344,41 @@ state_packets!(
}
/// JoinGame is sent after completing the login process. This
/// sets the initial state for the client.
packet JoinGame_WorldNames_IsHard_SimDist {
/// The entity id the client will be referenced by
field entity_id: i32 =,
/// Whether hardcore mode is enabled
field is_hardcore: bool =,
/// 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: Option<nbt::NamedTag> =,
/// 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: VarInt =,
/// The render distance (2-32)
field view_distance: VarInt =,
/// The distance the client will process entities
field simulation_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_WorldNames_IsHard {
/// The entity id the client will be referenced by
field entity_id: i32 =,
Expand Down Expand Up @@ -2019,6 +2074,10 @@ state_packets!(
field object_name: String =,
field value: Option<i32 > = when(|p: &UpdateScore_i32| p.action != 1),
}
/// UpdateSimulationDistance is used to set how far the client will process entities.
packet UpdateSimulationDistance {
field simulation_distance: VarInt =,
}
/// SpawnPosition is sent to change the player's current spawn point. Currently
/// only used by the client for the compass.
packet SpawnPosition_Angle {
Expand Down Expand Up @@ -2714,6 +2773,34 @@ impl Serializable for CriterionProgress {
}
}

#[derive(Debug, Default, Clone, PartialEq)]
pub struct BlockEntityAtPackedLocation {
/// The packed section coordinates, calculated from ((blockX & 15) << 4) | (blockZ & 15)
pub packed_xz: u8,
/// The height relative to the world
pub y: i16,
pub ty: VarInt,
pub data: Option<nbt::NamedTag>,
}

impl Serializable for BlockEntityAtPackedLocation {
fn read_from<R: io::Read>(buf: &mut R) -> Result<Self, Error> {
Ok(BlockEntityAtPackedLocation {
packed_xz: Serializable::read_from(buf)?,
y: Serializable::read_from(buf)?,
ty: Serializable::read_from(buf)?,
data: Serializable::read_from(buf)?,
})
}

fn write_to<W: io::Write>(&self, buf: &mut W) -> Result<(), Error> {
self.packed_xz.write_to(buf)?;
self.y.write_to(buf)?;
self.ty.write_to(buf)?;
self.data.write_to(buf)
}
}

#[derive(Debug, Default, Clone, PartialEq)]
pub struct EntityEquipment {
pub slot: u8,
Expand Down
3 changes: 3 additions & 0 deletions protocol/src/protocol/versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod v1_15;
mod v1_16_1;
mod v1_16_4;
mod v1_17_1;
mod v1_18_1;
mod v1_7_10;
mod v1_8_9;
mod v1_9;
Expand All @@ -27,6 +28,7 @@ mod v1_9_2;
pub fn protocol_name_to_protocol_version(s: String) -> i32 {
match s.as_ref() {
"" => SUPPORTED_PROTOCOLS[0],
"1.18.1" => 757,
"1.17.1" => 756,
"1.16.5" => 754,
"1.16.4" => 754,
Expand Down Expand Up @@ -71,6 +73,7 @@ pub fn translate_internal_packet_id_for_version(
to_internal: bool,
) -> i32 {
match version {
757 => v1_18_1::translate_internal_packet_id(state, dir, id, to_internal),
756 => v1_17_1::translate_internal_packet_id(state, dir, id, to_internal),
754 | 753 | 751 => v1_16_4::translate_internal_packet_id(state, dir, id, to_internal),
736 => v1_16_1::translate_internal_packet_id(state, dir, id, to_internal),
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/protocol/versions/v15w39c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protocol_packet_ids!(
0x06 => Animation
0x07 => Statistics
0x08 => BlockBreakAnimation
0x09 => UpdateBlockEntity
0x09 => UpdateBlockEntity_u8
0x0a => BlockAction
0x0b => BlockChange_VarInt
0x0c => BossBar
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/protocol/versions/v18w50a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protocol_packet_ids!(
0x06 => Animation
0x07 => Statistics
0x08 => BlockBreakAnimation
0x09 => UpdateBlockEntity
0x09 => UpdateBlockEntity_u8
0x0a => BlockAction
0x0b => BlockChange_VarInt
0x0c => BossBar
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/protocol/versions/v19w02a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protocol_packet_ids!(
0x06 => Animation
0x07 => Statistics
0x08 => BlockBreakAnimation
0x09 => UpdateBlockEntity
0x09 => UpdateBlockEntity_u8
0x0a => BlockAction
0x0b => BlockChange_VarInt
0x0c => BossBar
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/protocol/versions/v1_10_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protocol_packet_ids!(
0x06 => Animation
0x07 => Statistics
0x08 => BlockBreakAnimation
0x09 => UpdateBlockEntity
0x09 => UpdateBlockEntity_u8
0x0a => BlockAction
0x0b => BlockChange_VarInt
0x0c => BossBar
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/protocol/versions/v1_11_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protocol_packet_ids!(
0x06 => Animation
0x07 => Statistics
0x08 => BlockBreakAnimation
0x09 => UpdateBlockEntity
0x09 => UpdateBlockEntity_u8
0x0a => BlockAction
0x0b => BlockChange_VarInt
0x0c => BossBar
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/protocol/versions/v1_12_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protocol_packet_ids!(
0x06 => Animation
0x07 => Statistics
0x08 => BlockBreakAnimation
0x09 => UpdateBlockEntity
0x09 => UpdateBlockEntity_u8
0x0a => BlockAction
0x0b => BlockChange_VarInt
0x0c => BossBar
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/protocol/versions/v1_13_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protocol_packet_ids!(
0x06 => Animation
0x07 => Statistics
0x08 => BlockBreakAnimation
0x09 => UpdateBlockEntity
0x09 => UpdateBlockEntity_u8
0x0a => BlockAction
0x0b => BlockChange_VarInt
0x0c => BossBar
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/protocol/versions/v1_14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protocol_packet_ids!(
0x06 => Animation
0x07 => Statistics
0x08 => BlockBreakAnimation
0x09 => UpdateBlockEntity
0x09 => UpdateBlockEntity_u8
0x0a => BlockAction
0x0b => BlockChange_VarInt
0x0c => BossBar
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/protocol/versions/v1_14_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protocol_packet_ids!(
0x06 => Animation
0x07 => Statistics
0x08 => BlockBreakAnimation
0x09 => UpdateBlockEntity
0x09 => UpdateBlockEntity_u8
0x0a => BlockAction
0x0b => BlockChange_VarInt
0x0c => BossBar
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/protocol/versions/v1_14_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protocol_packet_ids!(
0x06 => Animation
0x07 => Statistics
0x08 => BlockBreakAnimation
0x09 => UpdateBlockEntity
0x09 => UpdateBlockEntity_u8
0x0a => BlockAction
0x0b => BlockChange_VarInt
0x0c => BossBar
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/protocol/versions/v1_14_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protocol_packet_ids!(
0x06 => Animation
0x07 => Statistics
0x08 => BlockBreakAnimation
0x09 => UpdateBlockEntity
0x09 => UpdateBlockEntity_u8
0x0a => BlockAction
0x0b => BlockChange_VarInt
0x0c => BossBar
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/protocol/versions/v1_14_4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protocol_packet_ids!(
0x06 => Animation
0x07 => Statistics
0x08 => BlockBreakAnimation
0x09 => UpdateBlockEntity
0x09 => UpdateBlockEntity_u8
0x0a => BlockAction
0x0b => BlockChange_VarInt
0x0c => BossBar
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/protocol/versions/v1_15.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protocol_packet_ids!(
0x07 => Statistics
0x08 => AcknowledgePlayerDigging
0x09 => BlockBreakAnimation
0x0a => UpdateBlockEntity
0x0a => UpdateBlockEntity_u8
0x0b => BlockAction
0x0c => BlockChange_VarInt
0x0d => BossBar
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/protocol/versions/v1_16_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protocol_packet_ids!(
0x06 => Statistics
0x07 => AcknowledgePlayerDigging
0x08 => BlockBreakAnimation
0x09 => UpdateBlockEntity
0x09 => UpdateBlockEntity_u8
0x0a => BlockAction
0x0b => BlockChange_VarInt
0x0c => BossBar
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/protocol/versions/v1_16_4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protocol_packet_ids!(
0x06 => Statistics
0x07 => AcknowledgePlayerDigging
0x08 => BlockBreakAnimation
0x09 => UpdateBlockEntity
0x09 => UpdateBlockEntity_u8
0x0a => BlockAction
0x0b => BlockChange_VarInt
0x0c => BossBar
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/protocol/versions/v1_17_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protocol_packet_ids!(
0x07 => Statistics
0x08 => AcknowledgePlayerDigging
0x09 => BlockBreakAnimation
0x0a => UpdateBlockEntity
0x0a => UpdateBlockEntity_u8
0x0b => BlockAction
0x0c => BlockChange_VarInt
0x0d => BossBar
Expand Down
Loading

0 comments on commit 1f183ed

Please sign in to comment.