Skip to content

Commit

Permalink
feat: dump special tools required to mine each block type
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Jul 1, 2024
1 parent 511841d commit 5225116
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/bedrock/world/level/block/block_legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ class BlockLegacy : public BlockComponentStorage {
return name_info_.namespace_name;
}

[[nodiscard]] const Block *getDefaultState() const
{
return default_state_;
}

void forEachBlockPermutation(std::function<bool(Block const &)> callback) const
{
for (const auto &block_permutation : block_permutations_) {
Expand Down
2 changes: 1 addition & 1 deletion src/endstone_devtools/devtools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void render()
[&](CompoundTag *arg) {
BigEndianStringByteOutput output;
NbtIo::writeNamedTag("", *arg, output);
zstr::ofstream file(path.string(), std::ios::binary);
zstr::ofstream file(path.string(), std::ios::out | std::ios::binary);
file << output.buffer;
}},
file_to_save);
Expand Down
11 changes: 11 additions & 0 deletions src/endstone_devtools/vanilla_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void dumpBlockData(VanillaData &data, ::Level &level)
{
auto overworld = level.getDimension(VanillaDimensions::Overworld);
auto &region = overworld->getBlockSourceFromMainChunkSource();
auto item_registry = level.getItemRegistry().weak_registry.lock();

::ListTag blocks;
BlockTypeRegistry::forEachBlock([&](const BlockLegacy &block_legacy) {
Expand Down Expand Up @@ -146,6 +147,16 @@ void dumpBlockData(VanillaData &data, ::Level &level)
data.block_types[name]["tags"] = tags;
}

nlohmann::json special_tools;
for (const auto &[key, item] : item_registry->getNameToItemMap()) {
if (item->canDestroySpecial(*block_legacy.getDefaultState())) {
special_tools.push_back(item->getFullItemName());
}
}
if (!special_tools.is_null()) {
data.block_types[name]["specialTools"] = special_tools;
}

block_legacy.forEachBlockPermutation([&](const Block &block) {
AABB collision_shape = {0};
block.getCollisionShape(collision_shape, region, {0, 0, 0}, nullptr);
Expand Down

0 comments on commit 5225116

Please sign in to comment.