aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-04-26 19:38:07 -0500
committermat <github@matdoes.dev>2022-04-26 19:38:07 -0500
commit9c69d7d5f2f704b1de37e1a102bf4390cdd879a5 (patch)
tree5bef94cbfc34fca7045f220f226c581757f3953c
parentdd24110019c0ded21e064b2273acc326173c84f5 (diff)
downloadazalea-drasl-9c69d7d5f2f704b1de37e1a102bf4390cdd879a5.tar.xz
finish update recipes packet implementation
-rwxr-xr-xazalea-auth/src/lib.rs4
-rwxr-xr-xazalea-client/src/connect.rs1
-rwxr-xr-xazalea-core/src/resource_location.rs7
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs5
-rw-r--r--azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs128
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_update_tags_packet.rs7
-rw-r--r--bot/src/main.rs2
7 files changed, 125 insertions, 29 deletions
diff --git a/azalea-auth/src/lib.rs b/azalea-auth/src/lib.rs
index afe9eb33..ba35055f 100755
--- a/azalea-auth/src/lib.rs
+++ b/azalea-auth/src/lib.rs
@@ -1,6 +1,4 @@
//! Handle Minecraft authentication.
-pub mod game_profile;
pub mod encryption;
-
-
+pub mod game_profile;
diff --git a/azalea-client/src/connect.rs b/azalea-client/src/connect.rs
index f441f2f3..b29ead3c 100755
--- a/azalea-client/src/connect.rs
+++ b/azalea-client/src/connect.rs
@@ -122,6 +122,7 @@ pub async fn join_server(address: &ServerAddress) -> Result<(), String> {
panic!("Error: {:?}", e);
}
}
+ println!();
}
Ok(())
diff --git a/azalea-core/src/resource_location.rs b/azalea-core/src/resource_location.rs
index 7e28a2a2..cdf8f381 100755
--- a/azalea-core/src/resource_location.rs
+++ b/azalea-core/src/resource_location.rs
@@ -1,6 +1,6 @@
//! A resource, like minecraft:stone
-#[derive(Hash, Clone, Debug, PartialEq, Eq)]
+#[derive(Hash, Clone, PartialEq, Eq)]
pub struct ResourceLocation {
pub namespace: String,
pub path: String,
@@ -36,6 +36,11 @@ impl std::fmt::Display for ResourceLocation {
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)]
mod tests {
diff --git a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs
index dc914f73..2df78ce9 100755
--- a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs
@@ -23,7 +23,6 @@ impl ClientboundDeclareCommandsPacket {
buf: &mut T,
) -> Result<GamePacket, String> {
let node_count = buf.read_varint().await?;
- println!("node_count: {}", node_count);
let mut nodes = Vec::with_capacity(node_count as usize);
for _ in 0..node_count {
let node = BrigadierNodeStub::read_into(buf).await?;
@@ -55,20 +54,16 @@ impl McBufReadable for BrigadierNodeStub {
let is_executable = flags & 0x04 != 0;
let has_redirect = flags & 0x08 != 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?;
- println!("children: {:?}", children);
let redirect_node = if has_redirect {
buf.read_varint().await?
} else {
0
};
- println!("redirect_node: {}", redirect_node);
if node_type == 2 {
let name = buf.read_utf().await?;
- println!("name: {}", name);
let resource_location = if has_suggestions_type {
Some(buf.read_resource_location().await?)
diff --git a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
index d9e6b262..5ae06a6f 100644
--- a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
@@ -25,14 +25,54 @@ pub struct ShapelessRecipe {
ingredients: Vec<Ingredient>,
result: Slot,
}
-#[derive(Clone, Debug, McBufReadable, McBufWritable)]
+#[derive(Clone, Debug)]
pub struct ShapedRecipe {
- width: u32,
- height: u32,
+ // TODO: make own McBufReadable and McBufWritable for this
+ width: usize,
+ height: usize,
group: String,
ingredients: Vec<Ingredient>,
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)]
pub struct CookingRecipe {
group: String,
@@ -78,6 +118,7 @@ pub enum RecipeData {
Smoking(CookingRecipe),
CampfireCooking(CookingRecipe),
Stonecutting(StoneCuttingRecipe),
+ Smithing(SmithingRecipe),
}
#[derive(Clone, Debug, McBufReadable, McBufWritable)]
@@ -90,6 +131,7 @@ impl McBufWritable for Recipe {
todo!()
}
}
+
#[async_trait]
impl McBufReadable for Recipe {
async fn read_into<R>(buf: &mut R) -> Result<Self, String>
@@ -103,15 +145,77 @@ impl McBufReadable for Recipe {
// if-else chain :(
let data = if recipe_type == ResourceLocation::new("minecraft:crafting_shapeless").unwrap()
{
- let group = buf.read_utf().await?;
- let ingredients = Vec::<Ingredient>::read_into(buf).await?;
- let result = Slot::read_into(buf).await?;
-
- RecipeData::CraftingShapeless(ShapelessRecipe {
- group,
- ingredients,
- result,
- })
+ RecipeData::CraftingShapeless(ShapelessRecipe::read_into(buf).await?)
+ } else if recipe_type == ResourceLocation::new("minecraft:crafting_shaped").unwrap() {
+ RecipeData::CraftingShaped(ShapedRecipe::read_into(buf).await?)
+ } else if recipe_type
+ == ResourceLocation::new("minecraft:crafting_special_armordye").unwrap()
+ {
+ RecipeData::CraftingSpecialArmorDye
+ } 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 {
panic!("Unknown recipe type sent by server: {}", recipe_type);
};
diff --git a/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs
index 66eee4b6..b6046948 100755
--- a/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs
@@ -24,20 +24,16 @@ impl McBufReadable for HashMap<ResourceLocation, Vec<Tags>> {
where
R: AsyncRead + std::marker::Unpin + std::marker::Send,
{
- println!("reading tags!");
let length = buf.read_varint().await? as usize;
- println!("length: {}", length);
let mut data = HashMap::with_capacity(length);
for _ in 0..length {
let tag_type = buf.read_resource_location().await?;
- println!("read tag type {}", tag_type);
let tags_count = buf.read_varint().await? as usize;
let mut tags_vec = Vec::with_capacity(tags_count);
for _ in 0..tags_count {
let tags = Tags::read_into(buf).await?;
tags_vec.push(tags);
}
- println!("tags: {} {:?}", tag_type, tags_vec);
data.insert(tag_type, tags_vec);
}
Ok(data)
@@ -60,11 +56,8 @@ impl McBufReadable for Tags {
where
R: AsyncRead + std::marker::Unpin + std::marker::Send,
{
- println!("reading tags.");
let name = buf.read_resource_location().await?;
- println!("tags name: {}", name);
let elements = buf.read_int_id_list().await?;
- println!("elements: {:?}", elements);
Ok(Tags { name, elements })
}
}
diff --git a/bot/src/main.rs b/bot/src/main.rs
index 71e325c6..b13a608b 100644
--- a/bot/src/main.rs
+++ b/bot/src/main.rs
@@ -3,7 +3,7 @@ async fn main() {
println!("Hello, world!");
// 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())
// .await
// .unwrap();