mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
update advancements packet
This commit is contained in:
parent
0b84e1cbb8
commit
e53ef8b0dd
7 changed files with 124 additions and 5 deletions
|
@ -244,10 +244,10 @@ impl Client {
|
||||||
println!("Got add entity packet {:?}", p);
|
println!("Got add entity packet {:?}", p);
|
||||||
}
|
}
|
||||||
GamePacket::ClientboundSetEntityDataPacket(p) => {
|
GamePacket::ClientboundSetEntityDataPacket(p) => {
|
||||||
println!("Got set entity data packet {:?}", p);
|
// println!("Got set entity data packet {:?}", p);
|
||||||
}
|
}
|
||||||
GamePacket::ClientboundUpdateAttributesPacket(p) => {
|
GamePacket::ClientboundUpdateAttributesPacket(p) => {
|
||||||
println!("Got update attributes packet {:?}", p);
|
// println!("Got update attributes packet {:?}", p);
|
||||||
}
|
}
|
||||||
GamePacket::ClientboundEntityVelocityPacket(p) => {
|
GamePacket::ClientboundEntityVelocityPacket(p) => {
|
||||||
println!("Got entity velocity packet {:?}", p);
|
println!("Got entity velocity packet {:?}", p);
|
||||||
|
@ -279,6 +279,9 @@ impl Client {
|
||||||
GamePacket::ClientboundTeleportEntityPacket(p) => {
|
GamePacket::ClientboundTeleportEntityPacket(p) => {
|
||||||
println!("Got teleport entity packet {:?}", p);
|
println!("Got teleport entity packet {:?}", p);
|
||||||
}
|
}
|
||||||
|
GamePacket::ClientboundUpdateAdvancementsPacket(p) => {
|
||||||
|
println!("Got update advancements packet {:?}", p);
|
||||||
|
}
|
||||||
_ => panic!("Unexpected packet {:?}", packet),
|
_ => panic!("Unexpected packet {:?}", packet),
|
||||||
}
|
}
|
||||||
println!();
|
println!();
|
||||||
|
|
|
@ -72,7 +72,7 @@ fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::TokenSt
|
||||||
impl crate::mc_buf::McBufReadable for #ident {
|
impl crate::mc_buf::McBufReadable for #ident {
|
||||||
fn read_into(buf: &mut impl std::io::Read) -> Result<Self, String>
|
fn read_into(buf: &mut impl std::io::Read) -> Result<Self, String>
|
||||||
{
|
{
|
||||||
let id = buf.read_varint()?;
|
let id = crate::mc_buf::McBufVarReadable::var_read_into(buf)?;
|
||||||
match id {
|
match id {
|
||||||
#match_contents
|
#match_contents
|
||||||
_ => Err(format!("Unknown enum variant {}", id)),
|
_ => Err(format!("Unknown enum variant {}", id)),
|
||||||
|
|
|
@ -6,7 +6,7 @@ use azalea_core::{
|
||||||
};
|
};
|
||||||
use byteorder::{ReadBytesExt, WriteBytesExt, BE};
|
use byteorder::{ReadBytesExt, WriteBytesExt, BE};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::io::Read;
|
use std::{collections::HashMap, hash::Hash, io::Read};
|
||||||
use tokio::io::{AsyncRead, AsyncReadExt};
|
use tokio::io::{AsyncRead, AsyncReadExt};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
@ -294,6 +294,17 @@ impl<T: McBufReadable + Send> McBufReadable for Vec<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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> {
|
||||||
|
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)?);
|
||||||
|
}
|
||||||
|
Ok(contents)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl McBufReadable for Vec<u8> {
|
impl McBufReadable for Vec<u8> {
|
||||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
buf.read_byte_array()
|
buf.read_byte_array()
|
||||||
|
|
|
@ -5,7 +5,7 @@ use azalea_core::{
|
||||||
serializable_uuid::SerializableUuid, BlockPos, Direction, Slot,
|
serializable_uuid::SerializableUuid, BlockPos, Direction, Slot,
|
||||||
};
|
};
|
||||||
use byteorder::{BigEndian, WriteBytesExt};
|
use byteorder::{BigEndian, WriteBytesExt};
|
||||||
use std::io::Write;
|
use std::{collections::HashMap, io::Write};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub trait Writable: Write {
|
pub trait Writable: Write {
|
||||||
|
@ -174,6 +174,18 @@ impl<T: McBufWritable> McBufWritable for Vec<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K: McBufWritable, V: McBufWritable> McBufWritable for HashMap<K, V> {
|
||||||
|
default fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
|
u32::var_write_into(&(self.len() as u32), buf)?;
|
||||||
|
for (key, value) in self {
|
||||||
|
key.write_into(buf)?;
|
||||||
|
value.write_into(buf)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl McBufWritable for Vec<u8> {
|
impl McBufWritable for Vec<u8> {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_byte_array(self)
|
buf.write_byte_array(self)
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
use crate::packets::{McBufReadable, McBufWritable};
|
||||||
|
use azalea_chat::component::Component;
|
||||||
|
use azalea_core::{resource_location::ResourceLocation, Slot};
|
||||||
|
use packet_macros::{GamePacket, McBufReadable, McBufWritable};
|
||||||
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
io::{Read, Write},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, GamePacket)]
|
||||||
|
pub struct ClientboundUpdateAdvancementsPacket {
|
||||||
|
pub reset: bool,
|
||||||
|
pub added: HashMap<ResourceLocation, Advancement>,
|
||||||
|
pub removed: Vec<ResourceLocation>,
|
||||||
|
pub progress: HashMap<ResourceLocation, AdvancementProgress>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, McBufReadable, McBufWritable)]
|
||||||
|
pub struct Advancement {
|
||||||
|
parent_id: Option<ResourceLocation>,
|
||||||
|
display: Option<DisplayInfo>,
|
||||||
|
// rewards: AdvancementRewards.EMPTY,
|
||||||
|
criteria: HashMap<ResourceLocation, Criterion>,
|
||||||
|
requirements: Vec<Vec<String>>,
|
||||||
|
// requirements_strategy: RequirementsStrategy.AND
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, McBufReadable, McBufWritable)]
|
||||||
|
pub struct DisplayInfo {
|
||||||
|
pub title: Component,
|
||||||
|
pub description: Component,
|
||||||
|
pub icon: Slot,
|
||||||
|
pub frame: FrameType,
|
||||||
|
pub flags: DisplayFlags,
|
||||||
|
pub background: Option<ResourceLocation>,
|
||||||
|
pub x: f32,
|
||||||
|
pub y: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct DisplayFlags {
|
||||||
|
pub background: bool,
|
||||||
|
pub show_toast: bool,
|
||||||
|
pub hidden: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl McBufReadable for DisplayFlags {
|
||||||
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
|
let data = u32::read_into(buf)?;
|
||||||
|
Ok(DisplayFlags {
|
||||||
|
background: (data & 0b1) != 0,
|
||||||
|
show_toast: (data & 0b10) != 0,
|
||||||
|
hidden: (data & 0b100) != 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl McBufWritable for DisplayFlags {
|
||||||
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
|
let mut data = 0;
|
||||||
|
if self.background {
|
||||||
|
data |= 0b1;
|
||||||
|
}
|
||||||
|
if self.show_toast {
|
||||||
|
data |= 0b10;
|
||||||
|
}
|
||||||
|
if self.hidden {
|
||||||
|
data |= 0b100;
|
||||||
|
}
|
||||||
|
u32::write_into(&data, buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Copy, McBufReadable, McBufWritable)]
|
||||||
|
pub enum FrameType {
|
||||||
|
Task = 0,
|
||||||
|
Challenge = 1,
|
||||||
|
Goal = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
// nothing is written here
|
||||||
|
#[derive(Clone, Debug, McBufReadable, McBufWritable)]
|
||||||
|
pub struct Criterion {}
|
||||||
|
|
||||||
|
pub type AdvancementProgress = HashMap<ResourceLocation, CriterionProgress>;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, McBufReadable, McBufWritable)]
|
||||||
|
pub struct CriterionProgress {
|
||||||
|
date: Option<u64>,
|
||||||
|
}
|
|
@ -25,6 +25,7 @@ pub mod clientbound_set_experience_packet;
|
||||||
pub mod clientbound_set_health_packet;
|
pub mod clientbound_set_health_packet;
|
||||||
pub mod clientbound_set_time_packet;
|
pub mod clientbound_set_time_packet;
|
||||||
pub mod clientbound_teleport_entity_packet;
|
pub mod clientbound_teleport_entity_packet;
|
||||||
|
pub mod clientbound_update_advancements_packet;
|
||||||
pub mod clientbound_update_attributes_packet;
|
pub mod clientbound_update_attributes_packet;
|
||||||
pub mod clientbound_update_recipes_packet;
|
pub mod clientbound_update_recipes_packet;
|
||||||
pub mod clientbound_update_tags_packet;
|
pub mod clientbound_update_tags_packet;
|
||||||
|
@ -67,6 +68,7 @@ declare_state_packets!(
|
||||||
0x52: clientbound_set_health_packet::ClientboundSetHealthPacket,
|
0x52: clientbound_set_health_packet::ClientboundSetHealthPacket,
|
||||||
0x59: clientbound_set_time_packet::ClientboundSetTimePacket,
|
0x59: clientbound_set_time_packet::ClientboundSetTimePacket,
|
||||||
0x62: clientbound_teleport_entity_packet::ClientboundTeleportEntityPacket,
|
0x62: clientbound_teleport_entity_packet::ClientboundTeleportEntityPacket,
|
||||||
|
0x63: clientbound_update_advancements_packet::ClientboundUpdateAdvancementsPacket,
|
||||||
0x64: clientbound_update_attributes_packet::ClientboundUpdateAttributesPacket,
|
0x64: clientbound_update_attributes_packet::ClientboundUpdateAttributesPacket,
|
||||||
0x66: clientbound_update_recipes_packet::ClientboundUpdateRecipesPacket,
|
0x66: clientbound_update_recipes_packet::ClientboundUpdateRecipesPacket,
|
||||||
0x67: clientbound_update_tags_packet::ClientboundUpdateTagsPacket,
|
0x67: clientbound_update_tags_packet::ClientboundUpdateTagsPacket,
|
||||||
|
|
|
@ -98,6 +98,7 @@ def generate(burger_packets, mappings: Mappings, target_packet_id, target_packet
|
||||||
if instruction['operation'] == 'write':
|
if instruction['operation'] == 'write':
|
||||||
obfuscated_field_name = instruction['field']
|
obfuscated_field_name = instruction['field']
|
||||||
if '.' in obfuscated_field_name or ' ' in obfuscated_field_name or '(' in obfuscated_field_name:
|
if '.' in obfuscated_field_name or ' ' in obfuscated_field_name or '(' in obfuscated_field_name:
|
||||||
|
generated_packet_code.append(f'// TODO: {instruction}')
|
||||||
continue
|
continue
|
||||||
field_name = mappings.get_field(
|
field_name = mappings.get_field(
|
||||||
obfuscated_class_name, obfuscated_field_name)
|
obfuscated_class_name, obfuscated_field_name)
|
||||||
|
|
Loading…
Add table
Reference in a new issue