1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

fixes for 1.21.4

This commit is contained in:
mat 2024-11-27 06:07:30 +00:00
parent d0472484fd
commit ab12de69f9
13 changed files with 2435 additions and 2380 deletions

View file

@ -20,6 +20,7 @@ use azalea_protocol::{
common::client_information::ClientInformation,
connect::{Connection, ConnectionError, Proxy},
packets::{
self,
config::{ClientboundConfigPacket, ServerboundConfigPacket},
game::ServerboundGamePacket,
handshake::{
@ -463,6 +464,13 @@ impl Client {
}
ClientboundLoginPacket::CookieRequest(p) => {
debug!("Got cookie request {:?}", p);
conn.write(packets::login::ServerboundCookieResponse {
key: p.key,
// cookies aren't implemented
payload: None,
})
.await?;
}
}
};

View file

@ -5,7 +5,8 @@ use azalea_protocol::packets::config::s_finish_configuration::ServerboundFinishC
use azalea_protocol::packets::config::s_keep_alive::ServerboundKeepAlive;
use azalea_protocol::packets::config::s_select_known_packs::ServerboundSelectKnownPacks;
use azalea_protocol::packets::config::{
self, ClientboundConfigPacket, ServerboundConfigPacket, ServerboundResourcePack,
self, ClientboundConfigPacket, ServerboundConfigPacket, ServerboundCookieResponse,
ServerboundResourcePack,
};
use azalea_protocol::packets::{ConnectionProtocol, Packet};
use azalea_protocol::read::deserialize_packet;
@ -36,8 +37,8 @@ pub fn send_packet_events(
// since otherwise it'd cause issues with events in process_packet_events
// running twice
packet_events.clear();
for (player_entity, raw_connection) in &query {
let packets_lock = raw_connection.incoming_packet_queue();
for (player_entity, raw_conn) in &query {
let packets_lock = raw_conn.incoming_packet_queue();
let mut packets = packets_lock.lock();
if !packets.is_empty() {
for raw_packet in packets.iter() {
@ -106,14 +107,14 @@ pub fn process_packet_events(ecs: &mut World) {
let mut system_state: SystemState<Query<&mut RawConnection>> =
SystemState::new(ecs);
let mut query = system_state.get_mut(ecs);
let mut raw_connection = query.get_mut(player_entity).unwrap();
let mut raw_conn = query.get_mut(player_entity).unwrap();
raw_connection
raw_conn
.write_packet(ServerboundFinishConfiguration {})
.expect(
"we should be in the right state and encoding this packet shouldn't fail",
);
raw_connection.set_state(ConnectionProtocol::Game);
raw_conn.set_state(ConnectionProtocol::Game);
// these components are added now that we're going to be in the Game state
ecs.entity_mut(player_entity)
@ -145,13 +146,13 @@ pub fn process_packet_events(ecs: &mut World) {
EventWriter<KeepAliveEvent>,
)> = SystemState::new(ecs);
let (query, mut keepalive_events) = system_state.get_mut(ecs);
let raw_connection = query.get(player_entity).unwrap();
let raw_conn = query.get(player_entity).unwrap();
keepalive_events.send(KeepAliveEvent {
entity: player_entity,
id: p.id,
});
raw_connection
raw_conn
.write_packet(ServerboundKeepAlive { id: p.id })
.unwrap();
}
@ -160,9 +161,9 @@ pub fn process_packet_events(ecs: &mut World) {
let mut system_state: SystemState<Query<&RawConnection>> = SystemState::new(ecs);
let mut query = system_state.get_mut(ecs);
let raw_connection = query.get_mut(player_entity).unwrap();
let raw_conn = query.get_mut(player_entity).unwrap();
raw_connection
raw_conn
.write_packet(config::s_pong::ServerboundPong { id: p.id })
.unwrap();
}
@ -171,10 +172,10 @@ pub fn process_packet_events(ecs: &mut World) {
let mut system_state: SystemState<Query<&RawConnection>> = SystemState::new(ecs);
let mut query = system_state.get_mut(ecs);
let raw_connection = query.get_mut(player_entity).unwrap();
let raw_conn = query.get_mut(player_entity).unwrap();
// always accept resource pack
raw_connection
raw_conn
.write_packet(ServerboundResourcePack {
id: p.id,
action: config::s_resource_pack::Action::Accepted,
@ -192,6 +193,18 @@ pub fn process_packet_events(ecs: &mut World) {
}
ClientboundConfigPacket::CookieRequest(p) => {
debug!("Got cookie request packet {p:?}");
let mut system_state: SystemState<Query<&RawConnection>> = SystemState::new(ecs);
let mut query = system_state.get_mut(ecs);
let raw_conn = query.get_mut(player_entity).unwrap();
raw_conn
.write_packet(ServerboundCookieResponse {
key: p.key,
// cookies aren't implemented
payload: None,
})
.unwrap();
}
ClientboundConfigPacket::ResetChat(p) => {
debug!("Got reset chat packet {p:?}");
@ -207,10 +220,10 @@ pub fn process_packet_events(ecs: &mut World) {
let mut system_state: SystemState<Query<&RawConnection>> = SystemState::new(ecs);
let mut query = system_state.get_mut(ecs);
let raw_connection = query.get_mut(player_entity).unwrap();
let raw_conn = query.get_mut(player_entity).unwrap();
// resource pack management isn't implemented
raw_connection
raw_conn
.write_packet(ServerboundSelectKnownPacks {
known_packs: vec![],
})
@ -241,9 +254,9 @@ pub fn handle_send_packet_event(
mut query: Query<&mut RawConnection>,
) {
for event in send_packet_events.read() {
if let Ok(raw_connection) = query.get_mut(event.sent_by) {
if let Ok(raw_conn) = query.get_mut(event.sent_by) {
// debug!("Sending packet: {:?}", event.packet);
if let Err(e) = raw_connection.write_packet(event.packet.clone()) {
if let Err(e) = raw_conn.write_packet(event.packet.clone()) {
error!("Failed to send packet: {e}");
}
}

File diff suppressed because it is too large Load diff

View file

@ -5,32 +5,32 @@ use azalea_protocol_macros::declare_state_packets;
declare_state_packets!(ConfigPacket,
Clientbound => [
keep_alive,
registry_data,
reset_chat,
resource_pack_pop,
resource_pack_push,
select_known_packs,
server_links,
cookie_request,
custom_payload,
disconnect,
finish_configuration,
keep_alive,
ping,
cookie_request,
reset_chat,
registry_data,
resource_pack_pop,
resource_pack_push,
store_cookie,
transfer,
update_enabled_features,
update_tags,
transfer,
store_cookie,
custom_payload,
select_known_packs,
custom_report_details,
server_links,
],
Serverbound => [
keep_alive,
resource_pack,
select_known_packs,
finish_configuration,
client_information,
cookie_response,
pong,
custom_payload,
finish_configuration,
keep_alive,
pong,
resource_pack,
select_known_packs,
]
);

View file

@ -5,21 +5,74 @@ use azalea_protocol_macros::declare_state_packets;
declare_state_packets!(GamePacket,
Clientbound => [
damage_event,
game_event,
map_item_data,
tab_list,
tag_query,
take_item_entity,
bundle_delimiter,
add_entity,
add_experience_orb,
animate,
award_stats,
block_changed_ack,
block_destruction,
block_entity_data,
block_event,
block_update,
boss_event,
change_difficulty,
chunk_batch_finished,
chunk_batch_start,
chunks_biomes,
clear_titles,
command_suggestions,
commands,
container_close,
container_set_content,
container_set_data,
container_set_slot,
cookie_request,
cooldown,
custom_chat_completions,
custom_payload,
damage_event,
debug_sample,
delete_chat,
disconnect,
disguised_chat,
entity_event,
entity_position_sync,
explode,
forget_level_chunk,
game_event,
horse_screen_open,
hurt_animation,
initialize_border,
keep_alive,
level_chunk_with_light,
level_event,
level_particles,
light_update,
login,
map_item_data,
merchant_offers,
move_entity_pos,
move_entity_pos_rot,
move_minecart_along_track,
move_entity_rot,
move_vehicle,
open_book,
open_screen,
open_sign_editor,
ping,
pong_response,
place_ghost_recipe,
player_abilities,
player_chat,
player_combat_end,
player_combat_enter,
player_combat_kill,
player_info_remove,
player_info_update,
player_look_at,
player_position,
player_rotation,
recipe_book_add,
recipe_book_remove,
recipe_book_settings,
@ -29,10 +82,10 @@ declare_state_packets!(GamePacket,
resource_pack_pop,
resource_pack_push,
respawn,
rotate_head,
section_blocks_update,
select_advancements_tab,
server_data,
server_links,
set_action_bar_text,
set_border_center,
set_border_lerp_size,
@ -62,87 +115,73 @@ declare_state_packets!(GamePacket,
set_time,
set_title_text,
set_titles_animation,
sound_entity,
sound,
start_configuration,
stop_sound,
store_cookie,
system_chat,
tab_list,
tag_query,
take_item_entity,
teleport_entity,
change_difficulty,
chunk_batch_finished,
chunk_batch_start,
chunks_biomes,
disconnect,
disguised_chat,
light_update,
ping,
ticking_state,
ticking_step,
block_changed_ack,
block_destruction,
block_entity_data,
block_event,
block_update,
clear_titles,
place_ghost_recipe,
player_abilities,
player_chat,
player_combat_end,
player_combat_enter,
player_combat_kill,
player_info_remove,
player_info_update,
player_look_at,
player_position,
player_rotation,
animate,
entity_event,
entity_position_sync,
initialize_border,
boss_event,
command_suggestions,
commands,
container_close,
container_set_content,
container_set_data,
container_set_slot,
cookie_request,
cooldown,
forget_level_chunk,
horse_screen_open,
login,
move_entity_pos,
move_entity_pos_rot,
move_entity_rot,
move_minecart_along_track,
move_vehicle,
pong_response,
rotate_head,
sound,
sound_entity,
open_book,
open_screen,
open_sign_editor,
transfer,
update_advancements,
update_attributes,
update_mob_effect,
update_recipes,
update_tags,
projectile_power,
transfer,
start_configuration,
stop_sound,
store_cookie,
bundle_delimiter,
custom_chat_completions,
custom_payload,
custom_report_details,
hurt_animation,
award_stats,
explode,
system_chat,
server_links,
],
Serverbound => [
paddle_boat,
accept_teleportation,
edit_book,
block_entity_tag_query,
bundle_item_selected,
change_difficulty,
chat_ack,
chat_command,
chat_command_signed,
chat,
chat_session_update,
chunk_batch_received,
client_command,
client_tick_end,
client_information,
command_suggestion,
configuration_acknowledged,
container_button_click,
container_click,
container_close,
container_slot_state_changed,
cookie_response,
custom_payload,
debug_sample_subscription,
edit_book,
entity_tag_query,
interact,
jigsaw_generate,
keep_alive,
lock_difficulty,
move_player_pos,
move_player_pos_rot,
move_player_rot,
move_player_status_only,
move_vehicle,
paddle_boat,
pick_item_from_block,
pick_item_from_entity,
ping_request,
place_recipe,
player_abilities,
player_action,
player_command,
player_input,
player_loaded,
pong,
recipe_book_change_settings,
recipe_book_seen_recipe,
rename_item,
@ -156,49 +195,10 @@ declare_state_packets!(GamePacket,
set_creative_mode_slot,
set_jigsaw_block,
set_structure_block,
teleport_to_entity,
change_difficulty,
chat,
chat_ack,
chat_command,
chat_command_signed,
chat_session_update,
chunk_batch_received,
jigsaw_generate,
pick_item_from_block,
pick_item_from_entity,
ping_request,
sign_update,
block_entity_tag_query,
client_command,
client_information,
client_tick_end,
place_recipe,
player_abilities,
player_action,
player_command,
player_input,
player_loaded,
entity_tag_query,
interact,
command_suggestion,
configuration_acknowledged,
container_button_click,
container_click,
container_close,
container_slot_state_changed,
cookie_response,
lock_difficulty,
move_player_pos,
move_player_pos_rot,
move_player_rot,
move_player_status_only,
move_vehicle,
pong,
use_item,
use_item_on,
bundle_item_selected,
custom_payload,
swing,
teleport_to_entity,
use_item_on,
use_item,
]
);

View file

@ -1,8 +1,8 @@
use azalea_buf::AzBuf;
use azalea_chat::FormattedText;
use azalea_core::resource_location::ResourceLocation;
use azalea_protocol_macros::ClientboundLoginPacket;
#[derive(Clone, Debug, AzBuf, ClientboundLoginPacket)]
pub struct ClientboundCookieRequest {
pub key: FormattedText,
pub key: ResourceLocation,
}

View file

@ -3,8 +3,7 @@ use azalea_protocol_macros::ClientboundLoginPacket;
#[derive(Clone, Debug, AzBuf, ClientboundLoginPacket)]
pub struct ClientboundHello {
// TODO: make this len thing work
// #[len(20)]
#[limit(20)]
pub server_id: String,
pub public_key: Vec<u8>,
pub challenge: Vec<u8>,

View file

@ -5,18 +5,18 @@ use azalea_protocol_macros::declare_state_packets;
declare_state_packets!(LoginPacket,
Clientbound => [
hello,
cookie_request,
login_compression,
login_disconnect,
hello,
login_finished,
login_compression,
custom_query,
cookie_request,
],
Serverbound => [
hello,
key,
cookie_response,
login_acknowledged,
custom_query_answer,
login_acknowledged,
cookie_response,
]
);

View file

@ -5,11 +5,11 @@ use azalea_protocol_macros::declare_state_packets;
declare_state_packets!(StatusPacket,
Clientbound => [
pong_response,
status_response,
pong_response,
],
Serverbound => [
ping_request,
status_request,
ping_request,
]
);

View file

@ -27,7 +27,7 @@ def generate():
block_states_report, pixlyzer_block_datas, ordered_blocks, mappings)
lib.code.shapes.generate_block_shapes(
pixlyzer_block_datas, shape_datas['shapes'], shape_datas['aabbs'], block_states_report, mappings)
pixlyzer_block_datas, shape_datas['shapes'], shape_datas['aabbs'], block_states_report)
lib.code.utils.fmt()

View file

@ -81,7 +81,7 @@ def packet_direction_report_to_packet_names(report):
packet_id = packet['protocol_id']
name_to_id[resource_location.split(':')[-1]] = packet_id
names_sorted = [name for name in sorted(name_to_id.keys(), key=lambda item: item[1])]
names_sorted = [name for name in sorted(name_to_id, key=lambda x: name_to_id[x])]
return names_sorted
def get_packets(direction: str, state: str):

View file

@ -5,11 +5,11 @@ COLLISION_BLOCKS_RS_DIR = get_dir_location(
'../azalea-physics/src/collision/blocks.rs')
def generate_block_shapes(blocks_pixlyzer: dict, shapes: dict, aabbs: dict, block_states_report, mappings: Mappings):
def generate_block_shapes(blocks_pixlyzer: dict, shapes: dict, aabbs: dict, block_states_report):
blocks, shapes = simplify_shapes(blocks_pixlyzer, shapes, aabbs)
code = generate_block_shapes_code(
blocks, shapes, block_states_report, mappings)
blocks, shapes, block_states_report)
with open(COLLISION_BLOCKS_RS_DIR, 'w') as f:
f.write(code)
@ -63,7 +63,7 @@ def simplify_shapes(blocks: dict, shapes: dict, aabbs: dict):
return new_blocks, new_shapes
def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report, mappings: Mappings):
def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report):
# look at __cache__/generator-mod-*/blockCollisionShapes.json for format of blocks and shapes
generated_shape_code = ''
@ -75,7 +75,9 @@ def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report,
empty_shapes = []
full_shapes = []
block_state_ids_to_shape_ids = []
# the index into this list is the block state id
shapes_map = []
for block_id, shape_ids in blocks.items():
if isinstance(shape_ids, int):
shape_ids = [shape_ids]
@ -89,17 +91,19 @@ def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report,
elif shape_id == 1 :
full_shapes.append(block_state_id)
block_state_ids_to_shape_ids.append((block_state_id, shape_id))
while len(shapes_map) <= block_state_id:
# default to shape 1 for missing shapes (full block)
shapes_map.append(1)
shapes_map[block_state_id] = shape_id
generated_map_code = f'static SHAPES_MAP: [&Lazy<VoxelShape>; {len(block_state_ids_to_shape_ids)}] = ['
block_state_ids_to_shape_ids = sorted(block_state_ids_to_shape_ids, key=lambda x: x[0])
generated_map_code = f'static SHAPES_MAP: [&Lazy<VoxelShape>; {len(shapes_map)}] = ['
empty_shape_match_code = convert_ints_to_rust_ranges(empty_shapes)
block_shape_match_code = convert_ints_to_rust_ranges(full_shapes)
for block_state_id, shape_id in block_state_ids_to_shape_ids:
for block_state_id, shape_id in enumerate(shapes_map):
generated_map_code += f'&SHAPE{shape_id},\n'
generated_map_code += '];'
@ -109,7 +113,7 @@ def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report,
return f'''
//! Autogenerated block collisions for every block
// This file is generated from codegen/lib/code/block_shapes.py. If you want to
// This file is generated from codegen/lib/code/shapes.py. If you want to
// modify it, change that file.
#![allow(clippy::explicit_auto_deref)]

View file

@ -31,84 +31,13 @@ new_version_id = sys.argv[1]
new_mappings = lib.download.get_mappings_for_version(new_version_id)
new_burger_data = lib.extract.get_burger_data_for_version(new_version_id)
old_packet_list = lib.extract.get_packet_list(old_version_id)
new_packet_list = lib.extract.get_packet_list(new_version_id)
# old_packets: dict[PacketIdentifier, str] = {}
# old_packets_data: dict[PacketIdentifier, dict] = {}
# new_packets: dict[PacketIdentifier, str] = {}
# new_packets_data: dict[PacketIdentifier, dict] = {}
# for packet in old_packet_list:
# assert packet['class'].endswith('.class')
# packet_name = old_mappings.get_class(packet['class'][:-6])
# packet_ident = PacketIdentifier(
# packet['id'], packet['direction'].lower(), fix_state(packet['state']))
# old_packets[packet_ident] = packet_name
# old_packets_data[packet_ident] = packet
# for packet in new_packet_list:
# assert packet['class'].endswith('.class')
# packet_name = new_mappings.get_class(packet['class'][:-6])
# packet_ident = PacketIdentifier(
# packet['id'], packet['direction'].lower(), fix_state(packet['state']))
# new_packets[packet_ident] = packet_name
# new_packets_data[packet_ident] = packet
# # find removed packets
# removed_packets: list[PacketIdentifier] = []
# for packet, packet_name in old_packets.items():
# if packet_name not in new_packets.values():
# removed_packets.append(packet)
# print('Removed packet:', packet, packet_name)
# for (direction, state), packets in group_packets(removed_packets).items():
# lib.code.packet.remove_packet_ids(packets, direction, state)
print()
# # find packets that changed ids
# changed_packets: dict[PacketIdentifier, int] = {}
# for old_packet, old_packet_name in old_packets.items():
# for new_packet, new_packet_name in new_packets.items():
# if old_packet_name == new_packet_name and old_packet.direction == new_packet.direction and old_packet.state == new_packet.state and old_packet.packet_id != new_packet.packet_id:
# changed_packets[old_packet] = new_packet.packet_id
# print('Changed packet id:', old_packet, '->',
# new_packet, f'({new_packet_name})')
# break
# for (direction, state), packets in group_packets(list(changed_packets.keys())).items():
# id_map: dict[int, int] = {}
# for old_packet_id in packets:
# new_packet_id = changed_packets[PacketIdentifier(
# old_packet_id, direction, state)]
# id_map[old_packet_id] = new_packet_id
# lib.code.packet.change_packet_ids(id_map, direction, state)
# print()
# # find added/changed packets
# added_or_changed_packets: list[PacketIdentifier] = []
# for new_packet, packet_name in new_packets.items():
# old_packet = None
# for old_packet_tmp, old_packet_name in old_packets.items():
# if old_packet_name == packet_name:
# old_packet = old_packet_tmp
# break
# if packet_name not in old_packets.values():
# added_or_changed_packets.append(new_packet)
# print('Added packet:', new_packet, packet_name)
# elif old_packet and not lib.code.packet.are_packet_instructions_identical(new_packets_data[new_packet].get('instructions'), old_packets_data[old_packet].get('instructions')):
# added_or_changed_packets.append(new_packet)
# print('Changed packet:', new_packet, packet_name)
# for packet in added_or_changed_packets:
# lib.code.packet.generate_packet(
# new_burger_data[0]['packets']['packet'], new_mappings, packet.packet_id, packet.direction, packet.state)
new_packets_report = lib.extract.get_packets_report(new_version_id)
lib.code.packet.set_packets(new_packets_report)
lib.code.version.set_protocol_version(
new_burger_data[0]['version']['protocol'])
# print('Updated protocol!')
print('Updated protocol!')
# old_ordered_blocks = lib.extract.get_ordered_blocks_burger(old_version_id)