Skip to content

Commit

Permalink
refactor(devtools): remove deprecated material (#109)
Browse files Browse the repository at this point in the history
* fix: fix material.h and material_type.h

* refactor: rename canDropWithAnyTool to requiresCorrectToolForDrops

* refactor: remove material related things since these things are unused

* docs: add a FIXME notice to biome.h
  • Loading branch information
smartcmd authored Dec 16, 2024
1 parent 692278c commit a749b61
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 212 deletions.
1 change: 0 additions & 1 deletion include/bedrock/world/actor/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include "bedrock/world/actor/actor_unique_id.h"
#include "bedrock/world/actor/synched_actor_data_entity_wrapper.h"
#include "bedrock/world/level/dimension/dimension.h"
#include "bedrock/world/level/material/material_type.h"
#include "endstone/detail/actor/actor.h"

class Player;
Expand Down
1 change: 1 addition & 0 deletions include/bedrock/world/level/biome/biome.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Biome {
}

private:
// FIXME: structure needs to be updated
HashedString hash_; // +0
float temperature_; // +56
float downfall_; // +60
Expand Down
19 changes: 12 additions & 7 deletions include/bedrock/world/level/block/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,21 @@ class Block {
public:
virtual ~Block() = default;

[[nodiscard]] bool canDropWithAnyTool() const
[[nodiscard]] bool requiresCorrectToolForDrops() const
{
return legacy_block_->canDropWithAnyTool();
return legacy_block_->requiresCorrectToolForDrops();
}

[[nodiscard]] bool canContainLiquid() const
{
return direct_data_.water_detection_rule.can_contain_liquid;
}

[[nodiscard]] bool isSolid() const
{
return legacy_block_->isSolid();
}

[[nodiscard]] const CompoundTag &getSerializationId() const
{
return serialization_id_;
Expand Down Expand Up @@ -106,11 +111,6 @@ class Block {
return direct_data_.light_emission;
}

[[nodiscard]] const Material &getMaterial() const
{
return legacy_block_->getMaterial();
}

[[nodiscard]] const std::vector<HashedString> &getTags() const
{
if (!tags_.empty()) {
Expand All @@ -124,6 +124,11 @@ class Block {
return legacy_block_->getThickness();
}

[[nodiscard]] float getTranslucency() const
{
return legacy_block_->getTranslucency();
}

[[nodiscard]] const BlockLegacy &getLegacyBlock() const
{
return *legacy_block_;
Expand Down
10 changes: 6 additions & 4 deletions include/bedrock/world/level/block/block_legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "bedrock/world/level/block/block_state_instance.h"
#include "bedrock/world/level/block/components/block_component_storage.h"
#include "bedrock/world/level/block_pos.h"
#include "bedrock/world/level/material/material.h"
#include "bedrock/world/phys/aabb.h"

class Actor;
Expand All @@ -44,6 +43,8 @@ class IConstBlockSource;
class ItemStack;
class ItemInstance;
class Player;
class Material;
class MaterialType;

enum class BlockProperty : std::uint64_t {
None = 0x0,
Expand Down Expand Up @@ -275,9 +276,10 @@ class BlockLegacy {
virtual void _onHitByActivatingAttack(BlockSource &, BlockPos const &, Actor *) const = 0;
virtual void entityInside(BlockSource &, BlockPos const &, Actor &) const = 0;

[[nodiscard]] bool canDropWithAnyTool() const;
[[nodiscard]] bool requiresCorrectToolForDrops() const;
[[nodiscard]] bool isSolid() const;
[[nodiscard]] float getThickness() const;
[[nodiscard]] const Material &getMaterial() const;
[[nodiscard]] float getTranslucency() const;
[[nodiscard]] const std::vector<HashedString> &getTags() const;
[[nodiscard]] const std::string &getDescriptionId() const;
[[nodiscard]] const std::string &getFullNameId() const;
Expand Down Expand Up @@ -353,6 +355,6 @@ class BlockLegacy {
std::unique_ptr<void *> block_state_group_; //
std::unique_ptr<void *> resource_drops_strategy_; //
IntRange experience_drop_; //
bool can_drop_with_any_tool_; //
bool requires_correct_tool_for_drops; //
// ...
};
4 changes: 2 additions & 2 deletions include/bedrock/world/level/block_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
#include "bedrock/world/level/block_source_interface.h"
#include "bedrock/world/level/chunk/level_chunk.h"
#include "bedrock/world/level/level_seed.h"
#include "bedrock/world/level/material/material.h"
#include "bedrock/world/level/material/material_type.h"

class ILevel;
class Level;
class Material;
class MaterialType;

using ActorSpan = gsl::span<gsl::not_null<Actor *>>;

Expand Down
81 changes: 0 additions & 81 deletions include/bedrock/world/level/material/material.h

This file was deleted.

76 changes: 0 additions & 76 deletions include/bedrock/world/level/material/material_type.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/endstone/detail/devtools/vanilla_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct VanillaData {
nlohmann::json block_states;
nlohmann::json block_tags;
::ListTag block_palette;
nlohmann::json materials;
// nlohmann::json materials;
nlohmann::json items;
::ListTag creative_items;
nlohmann::json item_tags;
Expand Down
9 changes: 0 additions & 9 deletions src/endstone_devtools/devtools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,6 @@ void render()
file_to_save = data->block_tags;
openFileBrowser("Save Block Tags", "block_tags.json");
}
if (ImGui::MenuItem("Materials")) {
file_to_save = data->materials;
openFileBrowser("Save Materials", "materials.json");
}
if (ImGui::MenuItem("Items")) {
file_to_save = data->items;
openFileBrowser("Save Items", "items.json");
Expand Down Expand Up @@ -388,10 +384,6 @@ void showBlockWindow(bool *open)
ImGui::Json(data->block_tags);
}

if (ImGui::CollapsingHeader(fmt::format("{} Materials", data->materials.size()).c_str())) {
ImGui::Json(data->materials);
}

if (ImGui::CollapsingHeader("Block Palette")) {
ImGui::Json(NbtIo::toJson(data->block_palette));
}
Expand Down Expand Up @@ -538,7 +530,6 @@ void exportAll(const std::filesystem::path &base_path, const VanillaData *data)
save_json_to_file(data->block_types, "block_types.json");
save_json_to_file(data->block_states, "block_states.json");
save_json_to_file(data->block_tags, "block_tags.json");
save_json_to_file(data->materials, "materials.json");
save_json_to_file(data->items, "items.json");
save_json_to_file(data->item_tags, "item_tags.json");
save_json_to_file(data->biomes, "biomes.json");
Expand Down
32 changes: 5 additions & 27 deletions src/endstone_devtools/vanilla_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,8 @@ void dumpBlockData(VanillaData &data, ::Level &level)
auto item_registry = level.getItemRegistry();

BlockTypeRegistry::forEachBlock([&](const BlockLegacy &block_legacy) {
const auto &material = block_legacy.getMaterial();
auto material_name = magic_enum::enum_name(material.getType());
data.materials[material_name] = {
{"isNeverBuildable", material.isNeverBuildable()},
{"isAlwaysDestroyable", material.isAlwaysDestroyable()},
{"isLiquid", material.isLiquid()},
{"translucency", round(material.getTranslucency())},
{"blocksMotion", material.getBlocksMotion()},
{"blocksPrecipitation", material.getBlocksPrecipitation()},
{"isSolid", material.isSolid()},
{"isSuperHot", material.isSuperHot()},
{"isSolidBlocking", material.isSolidBlocking()},
};

const auto &name = block_legacy.getFullNameId();

nlohmann::json tags;
for (const auto &tag : block_legacy.getTags()) {
auto tag_name = tag.getString();
Expand All @@ -79,22 +66,11 @@ void dumpBlockData(VanillaData &data, ::Level &level)
data.block_tags[tag_name].push_back(name);
}

data.block_types[name] = {{"material", magic_enum::enum_name(material.getType())}};
data.block_types[name] = {{"defaultBlockStateHash", block_legacy.getDefaultState()->getRuntimeId()}};
if (!tags.is_null()) {
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;
}
data.block_types[name]["defaultBlockStateHash"] = block_legacy.getDefaultState()->getRuntimeId();

block_legacy.forEachBlockPermutation([&](const ::Block &block) {
AABB collision_shape;
AABB outline_shape;
Expand All @@ -119,7 +95,9 @@ void dumpBlockData(VanillaData &data, ::Level &level)
{"friction", round(block.getFriction())},
{"hardness", round(block.getDestroySpeed())},
{"canContainLiquid", block.canContainLiquid()},
// {"canDropWithAnyTool", block.canDropWithAnyTool()},
{"requiresCorrectToolForDrops", block.requiresCorrectToolForDrops()},
{"isSolid", block.isSolid()},
{"translucency", block.getTranslucency()},
{"mapColor", map_color.toHexString()},
{"collisionShape",
{
Expand Down
Loading

0 comments on commit a749b61

Please sign in to comment.