Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dump item components & creative group #137

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/bedrock/world/item/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,14 @@ float Item::getFurnaceBurnIntervalMultipler() const
{
return furnace_burn_interval_modifier_;
}

ItemVersion Item::getItemVersion() const
{
return item_parse_version_;
}

const std::string &Item::getCreativeGroup() const
{
return creative_group_;
}

2 changes: 2 additions & 0 deletions src/bedrock/world/item/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ class Item {
Item &setMinRequiredBaseGameVersion(const BaseGameVersion &base_game_version);
ItemDescriptor buildDescriptor(std::int16_t, const CompoundTag *) const;
[[nodiscard]] float getFurnaceBurnIntervalMultipler() const;
[[nodiscard]] ItemVersion getItemVersion() const;
[[nodiscard]] const std::string &getCreativeGroup() const;

protected:
ItemVersion item_parse_version_;
Expand Down
19 changes: 19 additions & 0 deletions src/endstone/core/devtools/devtools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ struct adl_serializer<ListTag> {
adl_serializer<Tag>::to_json(j, tag);
}
};

template <>
struct adl_serializer<CompoundTag> {
static void to_json(json &j, const CompoundTag &tag) // NOLINT(*-identifier-naming)
{
adl_serializer<Tag>::to_json(j, tag);
}
};
NLOHMANN_JSON_NAMESPACE_END

namespace endstone::devtools {
Expand Down Expand Up @@ -319,6 +327,11 @@ void render()
std::get<CompoundTag>(file_to_save).put("items", data->creative_items.copy());
openFileBrowser("Save Creative Items", "creative_items.nbt");
}
if (ImGui::MenuItem("Item Components")) {
file_to_save = CompoundTag();
std::get<CompoundTag>(file_to_save).deepCopy(data->item_components);
openFileBrowser("Save Item Components", "item_components.nbt");
}
ImGui::EndMenu();
}
ImGui::EndMenu();
Expand Down Expand Up @@ -501,6 +514,10 @@ void showItemWindow(bool *open)
if (ImGui::CollapsingHeader(fmt::format("{} Item Tags", data->item_tags.size()).c_str())) {
ImGui::Json(data->item_tags);
}

if (ImGui::CollapsingHeader(fmt::format("{} Item Components", data->item_components.size()).c_str())) {
ImGui::Json(data->item_components);
}
ImGui::End();
}

Expand Down Expand Up @@ -619,6 +636,8 @@ void exportAll(const std::filesystem::path &base_path, const VanillaData *data)
save_json_to_file(data->item_tags, "item_tags.json");
save_json_to_file(data->biomes, "biomes.json");

save_nbt_to_file(data->item_components, "item_components.nbt");

auto block_palette = CompoundTag();
block_palette.put("blocks", data->block_palette.copy());
save_nbt_to_file(block_palette, "block_palette.nbt");
Expand Down
10 changes: 10 additions & 0 deletions src/endstone/core/devtools/vanilla_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ void dumpItemData(VanillaData &data, const ::Level &level)
{"maxStackSize", item->getMaxStackSize(ItemDescriptor())},
{"furnaceBurnDuration", FurnaceBlockActor::getBurnDuration(::ItemStack(*item), 200)},
{"furnaceXPMultiplier", item->getFurnaceXPmultiplier(nullptr)}};

if (const auto components = item->buildNetworkTag()) {
CompoundTag tag;
tag.putCompound("components", components->clone());
tag.putBoolean("isComponentBased", item->isComponentBased());
tag.putInt("version", static_cast<std::int32_t>(item->getItemVersion()));
data.item_components.put(name, tag.clone());
}

if (!tags.is_null()) {
data.items[name]["tags"] = tags;
}
Expand All @@ -154,6 +163,7 @@ void dumpItemData(VanillaData &data, const ::Level &level)
CompoundTag tag;
tag.putString("name", item_instance.getItem()->getFullItemName());
tag.putShort("damage", static_cast<std::int16_t>(item_instance.getAuxValue()));
tag.putString("group", item_instance.getItem()->getCreativeGroup());

if (const auto *user_data = item_instance.getUserData(); user_data) {
tag.putCompound("tag", user_data->clone());
Expand Down
2 changes: 1 addition & 1 deletion src/endstone/core/devtools/vanilla_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ struct VanillaData {
nlohmann::json block_states;
nlohmann::json block_tags;
::ListTag block_palette;
// nlohmann::json materials;
nlohmann::json items;
::ListTag creative_items;
nlohmann::json creative_groups;
nlohmann::json item_tags;
::CompoundTag item_components;
nlohmann::json biomes;
struct {
nlohmann::json shapeless;
Expand Down
Loading