Skip to content

Commit

Permalink
Update to Minecraft 1.20.1 (#358)
Browse files Browse the repository at this point in the history
## Description

Updates valence to Minecraft 1.20.1, which is protocol compatible with
1.20.

closes #357

---------

Co-authored-by: Ryan Johnson <[email protected]>
Co-authored-by: AviiNL <[email protected]>
  • Loading branch information
3 people authored Jun 13, 2023
1 parent c4741b6 commit 09fbd9b
Show file tree
Hide file tree
Showing 38 changed files with 50,065 additions and 43,604 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exclude = ["rust-mc-bot", "tools/stresser", "tools/packet_inspector"]
resolver = "2"

[workspace.package]
version = "0.2.0-dev+mc.1.19.4"
version = "0.2.0-dev+mc.1.20.1"
edition = "2021"
repository = "https://github.com/valence-rs/valence"
documentation = "https://docs.rs/valence/"
Expand Down
1 change: 0 additions & 1 deletion crates/valence/benches/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub fn packet(c: &mut Criterion) {
}),
blocks_and_biomes: BLOCKS_AND_BIOMES.as_slice(),
block_entities: Cow::Borrowed(&[]),
trust_edges: false,
sky_light_mask: Cow::Borrowed(&[]),
block_light_mask: Cow::Borrowed(&[]),
empty_sky_light_mask: Cow::Borrowed(&[]),
Expand Down
2 changes: 1 addition & 1 deletion crates/valence/examples/death.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn squat_and_die(mut clients: Query<&mut Client>, mut events: EventReader<Sneaki
for event in events.iter() {
if event.state == SneakState::Start {
if let Ok(mut client) = clients.get_mut(event.client) {
client.kill(None, "Squatted too hard.");
client.kill("Squatted too hard.");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/valence_advancement/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl<'w, 's> UpdateAdvancementCachedBytesQuery<'w, 's> {
display_data: None,
criteria: vec![],
requirements: vec![],
sends_telemetry_data: false,
};

if let Some(a_parent) = a_parent {
Expand Down
1 change: 1 addition & 0 deletions crates/valence_advancement/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct Advancement<'a, I> {
pub display_data: Option<AdvancementDisplay<'a, I>>,
pub criteria: Vec<(Ident<Cow<'a, str>>, ())>,
pub requirements: Vec<AdvancementRequirements<'a>>,
pub sends_telemetry_data: bool,
}

#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
Expand Down
5 changes: 3 additions & 2 deletions crates/valence_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,9 @@ impl Client {

/// Kills the client and shows `message` on the death screen. If an entity
/// killed the player, you should supply it as `killer`.
pub fn kill(&mut self, killer: Option<EntityId>, message: impl Into<Text>) {
pub fn kill(&mut self, message: impl Into<Text>) {
self.write_packet(&DeathMessageS2c {
player_id: VarInt(0),
entity_id: killer.map(|id| id.get()).unwrap_or(-1),
message: message.into().into(),
});
}
Expand Down Expand Up @@ -725,6 +724,7 @@ fn initial_join(
is_debug: q.is_debug.0,
is_flat: q.is_flat.0,
last_death_location,
portal_cooldown: VarInt(0), // TODO.
});

q.client.enc.append_bytes(tags.sync_tags_packet());
Expand Down Expand Up @@ -785,6 +785,7 @@ fn respawn(
is_flat: is_flat.0,
copy_metadata: true,
last_death_location,
portal_cooldown: VarInt(0), // TODO
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/valence_client/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ pub enum UpdatePlayerAbilitiesC2s {
#[packet(id = packet_id::UPDATE_SIGN_C2S)]
pub struct UpdateSignC2s<'a> {
pub position: BlockPos,
pub is_front_text: bool,
pub lines: [&'a str; 4],
}

Expand Down Expand Up @@ -249,8 +250,6 @@ pub mod structure_block {
#[packet(id = packet_id::DEATH_MESSAGE_S2C)]
pub struct DeathMessageS2c<'a> {
pub player_id: VarInt,
/// Killer's entity ID, -1 if no killer
pub entity_id: i32,
pub message: Cow<'a, Text>,
}

Expand Down Expand Up @@ -286,7 +285,6 @@ pub struct EnterCombatS2c;
#[packet(id = packet_id::END_COMBAT_S2C)]
pub struct EndCombatS2c {
pub duration: VarInt,
pub entity_id: i32,
}

#[derive(Copy, Clone, Debug, Encode, Decode, Packet)]
Expand Down Expand Up @@ -324,6 +322,7 @@ pub struct GameJoinS2c<'a> {
pub is_debug: bool,
pub is_flat: bool,
pub last_death_location: Option<GlobalPos<'a>>,
pub portal_cooldown: VarInt,
}

#[derive(Copy, Clone, Debug, Encode, Decode, Packet)]
Expand Down Expand Up @@ -388,6 +387,7 @@ pub struct PlayerRespawnS2c<'a> {
pub is_flat: bool,
pub copy_metadata: bool,
pub last_death_location: Option<GlobalPos<'a>>,
pub portal_cooldown: VarInt,
}

#[derive(Copy, Clone, Debug, Encode, Decode, Packet)]
Expand Down
4 changes: 2 additions & 2 deletions crates/valence_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ pub mod __private {
extern crate self as valence_core;

/// The Minecraft protocol version this library currently targets.
pub const PROTOCOL_VERSION: i32 = 762;
pub const PROTOCOL_VERSION: i32 = 763;

/// The stringified name of the Minecraft version this library currently
/// targets.
pub const MINECRAFT_VERSION: &str = "1.19.4";
pub const MINECRAFT_VERSION: &str = "1.20.1";

/// Minecraft's standard ticks per second (TPS).
pub const DEFAULT_TPS: NonZeroU32 = match NonZeroU32::new(20) {
Expand Down
2 changes: 1 addition & 1 deletion crates/valence_entity/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl Value {
quote!(None)
}
Value::ItemStack(stack) => {
assert_eq!(stack, "1 air");
assert_eq!(stack, "0 air");
quote!(valence_core::item::ItemStack::default())
}
Value::Boolean(b) => quote!(#b),
Expand Down
2 changes: 0 additions & 2 deletions crates/valence_instance/src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ impl Chunk<true> {

writer.write_packet(&ChunkDeltaUpdateS2c {
chunk_section_position,
invert_trust_edges: false,
blocks: Cow::Borrowed(&sect.section_updates),
});
}
Expand Down Expand Up @@ -457,7 +456,6 @@ impl Chunk<true> {
heightmaps: Cow::Owned(heightmaps),
blocks_and_biomes: scratch,
block_entities: Cow::Borrowed(&block_entities),
trust_edges: true,
sky_light_mask: Cow::Borrowed(&info.filler_sky_light_mask),
block_light_mask: Cow::Borrowed(&[]),
empty_sky_light_mask: Cow::Borrowed(&[]),
Expand Down
3 changes: 0 additions & 3 deletions crates/valence_instance/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ pub struct ChunkDataS2c<'a> {
pub heightmaps: Cow<'a, Compound>,
pub blocks_and_biomes: &'a [u8],
pub block_entities: Cow<'a, [ChunkDataBlockEntity<'a>]>,
pub trust_edges: bool,
pub sky_light_mask: Cow<'a, [u64]>,
pub block_light_mask: Cow<'a, [u64]>,
pub empty_sky_light_mask: Cow<'a, [u64]>,
Expand All @@ -116,7 +115,6 @@ pub struct ChunkDataBlockEntity<'a> {
#[packet(id = packet_id::CHUNK_DELTA_UPDATE_S2C)]
pub struct ChunkDeltaUpdateS2c<'a> {
pub chunk_section_position: i64,
pub invert_trust_edges: bool,
pub blocks: Cow<'a, [VarLong]>,
}

Expand Down Expand Up @@ -144,7 +142,6 @@ pub struct ChunkRenderDistanceCenterS2c {
pub struct LightUpdateS2c {
pub chunk_x: VarInt,
pub chunk_z: VarInt,
pub trust_edges: bool,
pub sky_light_mask: Vec<u64>,
pub block_light_mask: Vec<u64>,
pub empty_sky_light_mask: Vec<u64>,
Expand Down
38 changes: 33 additions & 5 deletions crates/valence_inventory/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,19 @@ pub mod synchronize_recipes {
ingredient: Ingredient,
result: Option<ItemStack>,
},
Smithing {
SmithingTransform {
recipe_id: Ident<Cow<'a, str>>,
template: Ingredient,
base: Ingredient,
addition: Ingredient,
result: Option<ItemStack>,
},
SmithingTrim {
recipe_id: Ident<Cow<'a, str>>,
template: Ingredient,
base: Ingredient,
addition: Ingredient,
},
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
Expand Down Expand Up @@ -600,17 +607,31 @@ pub mod synchronize_recipes {
ingredient.encode(&mut w)?;
result.encode(w)
}
Recipe::Smithing {
Recipe::SmithingTransform {
recipe_id,
template,
base,
addition,
result,
} => {
"smithing".encode(&mut w)?;
"smithing_transform".encode(&mut w)?;
recipe_id.encode(&mut w)?;
template.encode(&mut w)?;
base.encode(&mut w)?;
addition.encode(&mut w)?;
result.encode(w)
result.encode(&mut w)
}
Recipe::SmithingTrim {
recipe_id,
template,
base,
addition,
} => {
"smithing_trim".encode(&mut w)?;
recipe_id.encode(&mut w)?;
template.encode(&mut w)?;
base.encode(&mut w)?;
addition.encode(&mut w)
}
}
}
Expand Down Expand Up @@ -690,12 +711,19 @@ pub mod synchronize_recipes {
ingredient: Decode::decode(r)?,
result: Decode::decode(r)?,
},
"minecraft:smithing" => Self::Smithing {
"minecraft:smithing_transform" => Self::SmithingTransform {
recipe_id: Decode::decode(r)?,
template: Decode::decode(r)?,
base: Decode::decode(r)?,
addition: Decode::decode(r)?,
result: Decode::decode(r)?,
},
"minecraft:smithing_trim" => Self::SmithingTrim {
recipe_id: Decode::decode(r)?,
template: Decode::decode(r)?,
base: Decode::decode(r)?,
addition: Decode::decode(r)?,
},
other => Self::CraftingSpecial {
kind: match other {
"minecraft:crafting_special_armordye" => SpecialCraftingKind::ArmorDye,
Expand Down
2 changes: 1 addition & 1 deletion crates/valence_registry/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl RegistryCodec {

impl Default for RegistryCodec {
fn default() -> Self {
let codec = include_bytes!("../../../extracted/registry_codec_1.19.4.dat");
let codec = include_bytes!("../../../extracted/registry_codec_1.20.dat");
let compound = Compound::from_binary(&mut codec.as_slice())
.expect("failed to decode vanilla registry codec")
.0;
Expand Down
Loading

0 comments on commit 09fbd9b

Please sign in to comment.