This commit is contained in:
GIKExe 2025-05-03 22:11:28 +03:00
parent ed8524a4d5
commit 2220a4b314

View File

@ -1,18 +1,71 @@
use std::sync::Arc; use std::{collections::HashMap, sync::Arc};
use craftflow_nbt::DynNBT;
use rust_mc_proto::{DataWriter, Packet}; use rust_mc_proto::{DataWriter, Packet};
use serde_json::json;
use crate::server::{ use crate::server::{
ServerError, player::context::ClientContext, data::ReadWriteNBT, player::context::ClientContext, ServerError
}; };
use super::id::clientbound; use super::id::{clientbound::{self, configuration::REGISTRY_DATA}, serverbound};
pub fn handle_configuration_state( pub fn handle_configuration_state(
client: Arc<ClientContext>, // Контекст клиента client: Arc<ClientContext>, // Контекст клиента
) -> Result<(), ServerError> { ) -> Result<(), ServerError> {
let mut p = Packet::empty(clientbound::configuration::KNOWN_PACKS);
p.write_varint(1)?;
p.write_string("minecraft")?;
p.write_string("core")?;
p.write_string("1.21.5")?;
client.write_packet(&p)?;
client.read_packet(serverbound::configuration::KNOWN_PACKS)?;
let mut data = Vec::new();
craftflow_nbt::to_writer(&mut data, &json!(
{
"ambient_light": 0.0,
"bed_works": 1,
"coordinate_scale": 1.0,
"effects": "minecraft:overworld",
"has_ceiling": 0,
"has_raids": 1,
"has_skylight": 1,
"height": 384,
"infiniburn": "#minecraft:infiniburn_overworld",
"logical_height": 384,
"min_y": -64,
"monster_spawn_block_light_limit": 0,
"monster_spawn_light_level": {
"max_inclusive": 7,
"min_inclusive": 0,
"type": "minecraft:uniform"
},
"natural": 1,
"piglin_safe": 0,
"respawn_anchor_works": 0,
"ultrawarm": 0
}
)).unwrap();
let mut p = Packet::empty(clientbound::configuration::REGISTRY_DATA);
p.write_string("minecraft:dimension_type")?;
p.write_varint(1)?;
p.write_string("minecraft:overworld")?;
p.write_boolean(true)?;
// p.write_nbt(&DynNBT::Compound(HashMap::from_iter([
// ("bed_works".to_string(), DynNBT::Byte(1)),
// ("has_skylight".to_string(), DynNBT::Byte(1)),
// ("natural".to_string(), DynNBT::Byte(1)),
// ("coordinate_scale".to_string(), DynNBT::Double(1.0)),
// ("effects".to_string(), DynNBT::String("minecraft:overworld".to_string())),
// ])))?;
p.write_bytes(&data)?;
client.write_packet(&p)?;
Ok(()) Ok(())
} }
// Отдельная функция для работы с самой игрой // Отдельная функция для работы с самой игрой
pub fn handle_play_state( pub fn handle_play_state(