Skip to content

Commit

Permalink
feat: add basic shapeless recipe info
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Jul 2, 2024
1 parent d49df1b commit 6063407
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 15 deletions.
27 changes: 14 additions & 13 deletions include/bedrock/world/item/crafting/recipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "recipe_unlocking_requirement.h"

struct RecipeNetIdTag {};
using RecipeNetId = TypedServerNetId<RecipeNetIdTag, unsigned int>;

class Recipe {
public:
Expand Down Expand Up @@ -64,7 +65,7 @@ class Recipe {
return priority_;
}

[[nodiscard]] const TypedServerNetId<RecipeNetIdTag, unsigned int> &getNetId() const
[[nodiscard]] const RecipeNetId &getNetId() const
{
return recipe_net_id_;
}
Expand All @@ -90,16 +91,16 @@ class Recipe {
}

private:
std::string recipe_id_; // +8
mce::UUID id_; // +40 (+32)
int width_; // +56 (+48)
int height_; // +60 (+52)
int priority_; // +64 (+56)
TypedServerNetId<RecipeNetIdTag, unsigned int> recipe_net_id_; // +68 (+60)
std::vector<RecipeIngredient> ingredients_; // +72 (+64)
Result result_; // +96 (+88)
char pad_[24]; // +104 (+96)
RecipeUnlockingRequirement unlocking_requirement_; // +152 (+144)
SemVersion version_; // +184 (+176)
HashedString tag_; // +296 (+264)
std::string recipe_id_; // +8
mce::UUID id_; // +40 (+32)
int width_; // +56 (+48)
int height_; // +60 (+52)
int priority_; // +64 (+56)
RecipeNetId recipe_net_id_; // +68 (+60)
std::vector<RecipeIngredient> ingredients_; // +72 (+64)
Result result_; // +96 (+88)
char pad_[24]; // +104 (+96)
RecipeUnlockingRequirement unlocking_requirement_; // +152 (+144)
SemVersion version_; // +184 (+176)
HashedString tag_; // +296 (+264)
};
4 changes: 3 additions & 1 deletion include/bedrock/world/item/crafting/recipe_ingredient.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@

#pragma once

class RecipeIngredient {};
#include "bedrock/world/item/item_descriptor_count.h"

class RecipeIngredient : public ItemDescriptorCount {};
10 changes: 10 additions & 0 deletions include/bedrock/world/item/item_descriptor_count.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@

class ItemDescriptorCount : public ItemDescriptor {
public:
[[nodiscard]] std::int16_t getStackSize() const
{
return stack_size_;
}

void setStackSize(std::int16_t stack_size)
{
stack_size_ = stack_size;
}

private:
std::int16_t stack_size_;
};
28 changes: 27 additions & 1 deletion src/endstone_devtools/vanilla_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,36 @@ void dumpRecipes(VanillaData &data, ::Level &level)
return level.getItemRegistry().weak_registry.lock()->getItem(id)->getFullItemName();
};

// NOTE: check CraftingDataEntry::write
for (const auto &entry : packet->crafting_entries) {
switch (entry.entry_type) {
case ShapelessRecipe: {
data.recipes.shapeless.push_back({});
nlohmann::json input;
for (const auto &ingredient : entry.recipe->getIngredients()) {
input.push_back({
// {"id"},
// {"count"},
// {"type"},
// {"auxValue"},
}); // TODO: ...
}

nlohmann::json output;
for (const auto &result_item : entry.recipe->getResultItems()) {
output.push_back({
{"id", result_item.getItem()->getFullItemName()},
// {"count", }, // TODO: ...
});
}

data.recipes.shapeless.push_back({
{"id", entry.recipe->getRecipeId()},
{"input", input},
{"output", output},
{"uuid", entry.recipe->getId().toEndstone().str()},
{"tag", entry.recipe->getTag().getString()},
{"priority", entry.recipe->getPriority()},
});
break;
}
case ShapedRecipe: {
Expand Down

0 comments on commit 6063407

Please sign in to comment.