mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
finish update recipes packet implementation
This commit is contained in:
parent
dd24110019
commit
9c69d7d5f2
7 changed files with 125 additions and 29 deletions
|
@ -1,6 +1,4 @@
|
||||||
//! Handle Minecraft authentication.
|
//! Handle Minecraft authentication.
|
||||||
|
|
||||||
pub mod game_profile;
|
|
||||||
pub mod encryption;
|
pub mod encryption;
|
||||||
|
pub mod game_profile;
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,7 @@ pub async fn join_server(address: &ServerAddress) -> Result<(), String> {
|
||||||
panic!("Error: {:?}", e);
|
panic!("Error: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
println!();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! A resource, like minecraft:stone
|
//! A resource, like minecraft:stone
|
||||||
|
|
||||||
#[derive(Hash, Clone, Debug, PartialEq, Eq)]
|
#[derive(Hash, Clone, PartialEq, Eq)]
|
||||||
pub struct ResourceLocation {
|
pub struct ResourceLocation {
|
||||||
pub namespace: String,
|
pub namespace: String,
|
||||||
pub path: String,
|
pub path: String,
|
||||||
|
@ -36,6 +36,11 @@ impl std::fmt::Display for ResourceLocation {
|
||||||
write!(f, "{}:{}", self.namespace, self.path)
|
write!(f, "{}:{}", self.namespace, self.path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl std::fmt::Debug for ResourceLocation {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{}:{}", self.namespace, self.path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
|
@ -23,7 +23,6 @@ impl ClientboundDeclareCommandsPacket {
|
||||||
buf: &mut T,
|
buf: &mut T,
|
||||||
) -> Result<GamePacket, String> {
|
) -> Result<GamePacket, String> {
|
||||||
let node_count = buf.read_varint().await?;
|
let node_count = buf.read_varint().await?;
|
||||||
println!("node_count: {}", node_count);
|
|
||||||
let mut nodes = Vec::with_capacity(node_count as usize);
|
let mut nodes = Vec::with_capacity(node_count as usize);
|
||||||
for _ in 0..node_count {
|
for _ in 0..node_count {
|
||||||
let node = BrigadierNodeStub::read_into(buf).await?;
|
let node = BrigadierNodeStub::read_into(buf).await?;
|
||||||
|
@ -55,20 +54,16 @@ impl McBufReadable for BrigadierNodeStub {
|
||||||
let is_executable = flags & 0x04 != 0;
|
let is_executable = flags & 0x04 != 0;
|
||||||
let has_redirect = flags & 0x08 != 0;
|
let has_redirect = flags & 0x08 != 0;
|
||||||
let has_suggestions_type = flags & 0x10 != 0;
|
let has_suggestions_type = flags & 0x10 != 0;
|
||||||
println!("flags: {}, node_type: {}, is_executable: {}, has_redirect: {}, has_suggestions_type: {}", flags, node_type, is_executable, has_redirect, has_suggestions_type);
|
|
||||||
|
|
||||||
let children = buf.read_int_id_list().await?;
|
let children = buf.read_int_id_list().await?;
|
||||||
println!("children: {:?}", children);
|
|
||||||
let redirect_node = if has_redirect {
|
let redirect_node = if has_redirect {
|
||||||
buf.read_varint().await?
|
buf.read_varint().await?
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
println!("redirect_node: {}", redirect_node);
|
|
||||||
|
|
||||||
if node_type == 2 {
|
if node_type == 2 {
|
||||||
let name = buf.read_utf().await?;
|
let name = buf.read_utf().await?;
|
||||||
println!("name: {}", name);
|
|
||||||
|
|
||||||
let resource_location = if has_suggestions_type {
|
let resource_location = if has_suggestions_type {
|
||||||
Some(buf.read_resource_location().await?)
|
Some(buf.read_resource_location().await?)
|
||||||
|
|
|
@ -25,14 +25,54 @@ pub struct ShapelessRecipe {
|
||||||
ingredients: Vec<Ingredient>,
|
ingredients: Vec<Ingredient>,
|
||||||
result: Slot,
|
result: Slot,
|
||||||
}
|
}
|
||||||
#[derive(Clone, Debug, McBufReadable, McBufWritable)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ShapedRecipe {
|
pub struct ShapedRecipe {
|
||||||
width: u32,
|
// TODO: make own McBufReadable and McBufWritable for this
|
||||||
height: u32,
|
width: usize,
|
||||||
|
height: usize,
|
||||||
group: String,
|
group: String,
|
||||||
ingredients: Vec<Ingredient>,
|
ingredients: Vec<Ingredient>,
|
||||||
result: Slot,
|
result: Slot,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl McBufWritable for ShapedRecipe {
|
||||||
|
fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
||||||
|
buf.write_varint(self.width.try_into().unwrap())?;
|
||||||
|
buf.write_varint(self.height.try_into().unwrap())?;
|
||||||
|
buf.write_utf(&self.group)?;
|
||||||
|
for ingredient in &self.ingredients {
|
||||||
|
ingredient.write_into(buf)?;
|
||||||
|
}
|
||||||
|
self.result.write_into(buf)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[async_trait]
|
||||||
|
impl McBufReadable for ShapedRecipe {
|
||||||
|
async fn read_into<R>(buf: &mut R) -> Result<Self, String>
|
||||||
|
where
|
||||||
|
R: AsyncRead + std::marker::Unpin + std::marker::Send,
|
||||||
|
{
|
||||||
|
let width = buf.read_varint().await?.try_into().unwrap();
|
||||||
|
let height = buf.read_varint().await?.try_into().unwrap();
|
||||||
|
let group = buf.read_utf().await?;
|
||||||
|
let mut ingredients = Vec::with_capacity(width * height);
|
||||||
|
for _ in 0..width * height {
|
||||||
|
ingredients.push(Ingredient::read_into(buf).await?);
|
||||||
|
}
|
||||||
|
let result = Slot::read_into(buf).await?;
|
||||||
|
|
||||||
|
Ok(ShapedRecipe {
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
group,
|
||||||
|
ingredients,
|
||||||
|
result,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBufReadable, McBufWritable)]
|
#[derive(Clone, Debug, McBufReadable, McBufWritable)]
|
||||||
pub struct CookingRecipe {
|
pub struct CookingRecipe {
|
||||||
group: String,
|
group: String,
|
||||||
|
@ -78,6 +118,7 @@ pub enum RecipeData {
|
||||||
Smoking(CookingRecipe),
|
Smoking(CookingRecipe),
|
||||||
CampfireCooking(CookingRecipe),
|
CampfireCooking(CookingRecipe),
|
||||||
Stonecutting(StoneCuttingRecipe),
|
Stonecutting(StoneCuttingRecipe),
|
||||||
|
Smithing(SmithingRecipe),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, McBufReadable, McBufWritable)]
|
#[derive(Clone, Debug, McBufReadable, McBufWritable)]
|
||||||
|
@ -90,6 +131,7 @@ impl McBufWritable for Recipe {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl McBufReadable for Recipe {
|
impl McBufReadable for Recipe {
|
||||||
async fn read_into<R>(buf: &mut R) -> Result<Self, String>
|
async fn read_into<R>(buf: &mut R) -> Result<Self, String>
|
||||||
|
@ -103,15 +145,77 @@ impl McBufReadable for Recipe {
|
||||||
// if-else chain :(
|
// if-else chain :(
|
||||||
let data = if recipe_type == ResourceLocation::new("minecraft:crafting_shapeless").unwrap()
|
let data = if recipe_type == ResourceLocation::new("minecraft:crafting_shapeless").unwrap()
|
||||||
{
|
{
|
||||||
let group = buf.read_utf().await?;
|
RecipeData::CraftingShapeless(ShapelessRecipe::read_into(buf).await?)
|
||||||
let ingredients = Vec::<Ingredient>::read_into(buf).await?;
|
} else if recipe_type == ResourceLocation::new("minecraft:crafting_shaped").unwrap() {
|
||||||
let result = Slot::read_into(buf).await?;
|
RecipeData::CraftingShaped(ShapedRecipe::read_into(buf).await?)
|
||||||
|
} else if recipe_type
|
||||||
RecipeData::CraftingShapeless(ShapelessRecipe {
|
== ResourceLocation::new("minecraft:crafting_special_armordye").unwrap()
|
||||||
group,
|
{
|
||||||
ingredients,
|
RecipeData::CraftingSpecialArmorDye
|
||||||
result,
|
} else if recipe_type
|
||||||
})
|
== ResourceLocation::new("minecraft:crafting_special_bookcloning").unwrap()
|
||||||
|
{
|
||||||
|
RecipeData::CraftingSpecialBookCloning
|
||||||
|
} else if recipe_type
|
||||||
|
== ResourceLocation::new("minecraft:crafting_special_mapcloning").unwrap()
|
||||||
|
{
|
||||||
|
RecipeData::CraftingSpecialMapCloning
|
||||||
|
} else if recipe_type
|
||||||
|
== ResourceLocation::new("minecraft:crafting_special_mapextending").unwrap()
|
||||||
|
{
|
||||||
|
RecipeData::CraftingSpecialMapExtending
|
||||||
|
} else if recipe_type
|
||||||
|
== ResourceLocation::new("minecraft:crafting_special_firework_rocket").unwrap()
|
||||||
|
{
|
||||||
|
RecipeData::CraftingSpecialFireworkRocket
|
||||||
|
} else if recipe_type
|
||||||
|
== ResourceLocation::new("minecraft:crafting_special_firework_star").unwrap()
|
||||||
|
{
|
||||||
|
RecipeData::CraftingSpecialFireworkStar
|
||||||
|
} else if recipe_type
|
||||||
|
== ResourceLocation::new("minecraft:crafting_special_firework_star_fade").unwrap()
|
||||||
|
{
|
||||||
|
RecipeData::CraftingSpecialFireworkStarFade
|
||||||
|
} else if recipe_type
|
||||||
|
== ResourceLocation::new("minecraft:crafting_special_repairitem").unwrap()
|
||||||
|
{
|
||||||
|
RecipeData::CraftingSpecialRepairItem
|
||||||
|
} else if recipe_type
|
||||||
|
== ResourceLocation::new("minecraft:crafting_special_tippedarrow").unwrap()
|
||||||
|
{
|
||||||
|
RecipeData::CraftingSpecialTippedArrow
|
||||||
|
} else if recipe_type
|
||||||
|
== ResourceLocation::new("minecraft:crafting_special_bannerduplicate").unwrap()
|
||||||
|
{
|
||||||
|
RecipeData::CraftingSpecialBannerDuplicate
|
||||||
|
} else if recipe_type
|
||||||
|
== ResourceLocation::new("minecraft:crafting_special_banneraddpattern").unwrap()
|
||||||
|
{
|
||||||
|
RecipeData::CraftingSpecialBannerAddPattern
|
||||||
|
} else if recipe_type
|
||||||
|
== ResourceLocation::new("minecraft:crafting_special_shielddecoration").unwrap()
|
||||||
|
{
|
||||||
|
RecipeData::CraftingSpecialShieldDecoration
|
||||||
|
} else if recipe_type
|
||||||
|
== ResourceLocation::new("minecraft:crafting_special_shulkerboxcoloring").unwrap()
|
||||||
|
{
|
||||||
|
RecipeData::CraftingSpecialShulkerBoxColoring
|
||||||
|
} else if recipe_type
|
||||||
|
== ResourceLocation::new("minecraft:crafting_special_suspiciousstew").unwrap()
|
||||||
|
{
|
||||||
|
RecipeData::CraftingSpecialSuspiciousStew
|
||||||
|
} else if recipe_type == ResourceLocation::new("minecraft:smelting").unwrap() {
|
||||||
|
RecipeData::Smelting(CookingRecipe::read_into(buf).await?)
|
||||||
|
} else if recipe_type == ResourceLocation::new("minecraft:blasting").unwrap() {
|
||||||
|
RecipeData::Blasting(CookingRecipe::read_into(buf).await?)
|
||||||
|
} else if recipe_type == ResourceLocation::new("minecraft:smoking").unwrap() {
|
||||||
|
RecipeData::Smoking(CookingRecipe::read_into(buf).await?)
|
||||||
|
} else if recipe_type == ResourceLocation::new("minecraft:campfire_cooking").unwrap() {
|
||||||
|
RecipeData::CampfireCooking(CookingRecipe::read_into(buf).await?)
|
||||||
|
} else if recipe_type == ResourceLocation::new("minecraft:stonecutting").unwrap() {
|
||||||
|
RecipeData::Stonecutting(StoneCuttingRecipe::read_into(buf).await?)
|
||||||
|
} else if recipe_type == ResourceLocation::new("minecraft:smithing").unwrap() {
|
||||||
|
RecipeData::Smithing(SmithingRecipe::read_into(buf).await?)
|
||||||
} else {
|
} else {
|
||||||
panic!("Unknown recipe type sent by server: {}", recipe_type);
|
panic!("Unknown recipe type sent by server: {}", recipe_type);
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,20 +24,16 @@ impl McBufReadable for HashMap<ResourceLocation, Vec<Tags>> {
|
||||||
where
|
where
|
||||||
R: AsyncRead + std::marker::Unpin + std::marker::Send,
|
R: AsyncRead + std::marker::Unpin + std::marker::Send,
|
||||||
{
|
{
|
||||||
println!("reading tags!");
|
|
||||||
let length = buf.read_varint().await? as usize;
|
let length = buf.read_varint().await? as usize;
|
||||||
println!("length: {}", length);
|
|
||||||
let mut data = HashMap::with_capacity(length);
|
let mut data = HashMap::with_capacity(length);
|
||||||
for _ in 0..length {
|
for _ in 0..length {
|
||||||
let tag_type = buf.read_resource_location().await?;
|
let tag_type = buf.read_resource_location().await?;
|
||||||
println!("read tag type {}", tag_type);
|
|
||||||
let tags_count = buf.read_varint().await? as usize;
|
let tags_count = buf.read_varint().await? as usize;
|
||||||
let mut tags_vec = Vec::with_capacity(tags_count);
|
let mut tags_vec = Vec::with_capacity(tags_count);
|
||||||
for _ in 0..tags_count {
|
for _ in 0..tags_count {
|
||||||
let tags = Tags::read_into(buf).await?;
|
let tags = Tags::read_into(buf).await?;
|
||||||
tags_vec.push(tags);
|
tags_vec.push(tags);
|
||||||
}
|
}
|
||||||
println!("tags: {} {:?}", tag_type, tags_vec);
|
|
||||||
data.insert(tag_type, tags_vec);
|
data.insert(tag_type, tags_vec);
|
||||||
}
|
}
|
||||||
Ok(data)
|
Ok(data)
|
||||||
|
@ -60,11 +56,8 @@ impl McBufReadable for Tags {
|
||||||
where
|
where
|
||||||
R: AsyncRead + std::marker::Unpin + std::marker::Send,
|
R: AsyncRead + std::marker::Unpin + std::marker::Send,
|
||||||
{
|
{
|
||||||
println!("reading tags.");
|
|
||||||
let name = buf.read_resource_location().await?;
|
let name = buf.read_resource_location().await?;
|
||||||
println!("tags name: {}", name);
|
|
||||||
let elements = buf.read_int_id_list().await?;
|
let elements = buf.read_int_id_list().await?;
|
||||||
println!("elements: {:?}", elements);
|
|
||||||
Ok(Tags { name, elements })
|
Ok(Tags { name, elements })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ async fn main() {
|
||||||
println!("Hello, world!");
|
println!("Hello, world!");
|
||||||
|
|
||||||
// let address = "95.111.249.143:10000";
|
// let address = "95.111.249.143:10000";
|
||||||
let address = "localhost:52400";
|
let address = "localhost:57308";
|
||||||
// let response = azalea_client::ping::ping_server(&address.try_into().unwrap())
|
// let response = azalea_client::ping::ping_server(&address.try_into().unwrap())
|
||||||
// .await
|
// .await
|
||||||
// .unwrap();
|
// .unwrap();
|
||||||
|
|
Loading…
Add table
Reference in a new issue