From a749b61c6d6c29c94d84837debf36800fdca0352 Mon Sep 17 00:00:00 2001 From: daoge <3523206925@qq.com> Date: Mon, 16 Dec 2024 22:42:56 +0800 Subject: [PATCH] refactor(devtools): remove deprecated material (#109) * 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 --- include/bedrock/world/actor/actor.h | 1 - include/bedrock/world/level/biome/biome.h | 1 + include/bedrock/world/level/block/block.h | 19 +++-- .../bedrock/world/level/block/block_legacy.h | 10 ++- include/bedrock/world/level/block_source.h | 4 +- .../bedrock/world/level/material/material.h | 81 ------------------- .../world/level/material/material_type.h | 76 ----------------- .../endstone/detail/devtools/vanilla_data.h | 2 +- src/endstone_devtools/devtools.cpp | 9 --- src/endstone_devtools/vanilla_data.cpp | 32 ++------ .../world/level/block/block_legacy.cpp | 13 ++- 11 files changed, 36 insertions(+), 212 deletions(-) delete mode 100644 include/bedrock/world/level/material/material.h delete mode 100644 include/bedrock/world/level/material/material_type.h diff --git a/include/bedrock/world/actor/actor.h b/include/bedrock/world/actor/actor.h index 9f25de4e3..82afbe315 100644 --- a/include/bedrock/world/actor/actor.h +++ b/include/bedrock/world/actor/actor.h @@ -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; diff --git a/include/bedrock/world/level/biome/biome.h b/include/bedrock/world/level/biome/biome.h index d159ec123..f99c954f7 100644 --- a/include/bedrock/world/level/biome/biome.h +++ b/include/bedrock/world/level/biome/biome.h @@ -51,6 +51,7 @@ class Biome { } private: + // FIXME: structure needs to be updated HashedString hash_; // +0 float temperature_; // +56 float downfall_; // +60 diff --git a/include/bedrock/world/level/block/block.h b/include/bedrock/world/level/block/block.h index 49da6bbbc..85295ab13 100644 --- a/include/bedrock/world/level/block/block.h +++ b/include/bedrock/world/level/block/block.h @@ -51,9 +51,9 @@ 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 @@ -61,6 +61,11 @@ class Block { 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_; @@ -106,11 +111,6 @@ class Block { return direct_data_.light_emission; } - [[nodiscard]] const Material &getMaterial() const - { - return legacy_block_->getMaterial(); - } - [[nodiscard]] const std::vector &getTags() const { if (!tags_.empty()) { @@ -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_; diff --git a/include/bedrock/world/level/block/block_legacy.h b/include/bedrock/world/level/block/block_legacy.h index d164f5f6a..fccad92f8 100644 --- a/include/bedrock/world/level/block/block_legacy.h +++ b/include/bedrock/world/level/block/block_legacy.h @@ -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; @@ -44,6 +43,8 @@ class IConstBlockSource; class ItemStack; class ItemInstance; class Player; +class Material; +class MaterialType; enum class BlockProperty : std::uint64_t { None = 0x0, @@ -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 &getTags() const; [[nodiscard]] const std::string &getDescriptionId() const; [[nodiscard]] const std::string &getFullNameId() const; @@ -353,6 +355,6 @@ class BlockLegacy { std::unique_ptr block_state_group_; // std::unique_ptr resource_drops_strategy_; // IntRange experience_drop_; // - bool can_drop_with_any_tool_; // + bool requires_correct_tool_for_drops; // // ... }; diff --git a/include/bedrock/world/level/block_source.h b/include/bedrock/world/level/block_source.h index 8fa17117a..c76dbe304 100644 --- a/include/bedrock/world/level/block_source.h +++ b/include/bedrock/world/level/block_source.h @@ -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>; diff --git a/include/bedrock/world/level/material/material.h b/include/bedrock/world/level/material/material.h deleted file mode 100644 index afc322e9a..000000000 --- a/include/bedrock/world/level/material/material.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include "bedrock/world/level/material/material_type.h" - -class Material { -public: - [[nodiscard]] MaterialType getType() const - { - return type_; - } - - [[nodiscard]] bool isNeverBuildable() const - { - return never_buildable_; - } - - [[nodiscard]] bool isAlwaysDestroyable() const - { - return always_destroyable_; - } - - [[nodiscard]] bool isLiquid() const - { - return is_liquid_; - } - - [[nodiscard]] float getTranslucency() const - { - return translucency_; - } - - [[nodiscard]] bool getBlocksMotion() const - { - return blocks_motion_; - } - - [[nodiscard]] bool getBlocksPrecipitation() const - { - return blocks_precipitation_; - } - - [[nodiscard]] bool isSolid() const - { - return solid_; - } - - [[nodiscard]] bool isSuperHot() const - { - return super_hot_; - } - - [[nodiscard]] bool isSolidBlocking() const - { - return !never_buildable_ && blocks_motion_; - } - -private: - MaterialType type_; // +0 - bool never_buildable_; // +4 - bool always_destroyable_; // +5 - bool is_liquid_; // +6 - float translucency_; // +8 - bool blocks_motion_; // +12 - bool blocks_precipitation_; // +13 - bool solid_; // +14 - bool super_hot_; // +15 -}; diff --git a/include/bedrock/world/level/material/material_type.h b/include/bedrock/world/level/material/material_type.h deleted file mode 100644 index a48fee2a4..000000000 --- a/include/bedrock/world/level/material/material_type.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -/** - * Material type from StringFromMaterialType - */ -enum class MaterialType { - Air = 0, - Dirt = 1, - Wood = 2, - Stone = 3, - Metal = 4, - Water = 5, - Lava = 6, - Leaves = 7, - Plant = 8, - SolidPlant = 9, - Sponge = 10, - Cloth = 11, - Bed = 12, - Fire = 13, - Sand = 14, - Decoration = 15, - Glass = 16, - Explosive = 17, - Ice = 18, - PackedIce = 19, - TopSnow = 20, - Snow = 21, - PowderSnow = 22, - Amethyst = 23, - Cactus = 24, - Clay = 25, - Vegetable = 26, - Portal = 27, - Cake = 28, - Web = 29, - RedstoneWire = 30, - Carpet = 31, - BuildableGlass = 32, - Slime = 33, - Piston = 34, - Allow = 35, - Deny = 36, - Netherwart = 37, - StoneDecoration = 38, - Bubble = 39, - Egg = 40, - SoftEgg = 41, - Barrier = 42, - Coral = 43, - DecorationSolid = 44, - Dripstone = 45, - ReinforcedStone = 46, - Sculk = 47, - SculkVein = 48, - ClientRequestPlaceholder = 49, - StructureVoid = 50, - Root = 51, - Shulker = 52, - SurfaceTypeTotal = 53, - Any = 54, -}; diff --git a/include/endstone/detail/devtools/vanilla_data.h b/include/endstone/detail/devtools/vanilla_data.h index bff648add..0b8696228 100644 --- a/include/endstone/detail/devtools/vanilla_data.h +++ b/include/endstone/detail/devtools/vanilla_data.h @@ -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; diff --git a/src/endstone_devtools/devtools.cpp b/src/endstone_devtools/devtools.cpp index c81fd68fa..c621fe591 100644 --- a/src/endstone_devtools/devtools.cpp +++ b/src/endstone_devtools/devtools.cpp @@ -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"); @@ -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)); } @@ -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"); diff --git a/src/endstone_devtools/vanilla_data.cpp b/src/endstone_devtools/vanilla_data.cpp index 84aa58877..f75714404 100644 --- a/src/endstone_devtools/vanilla_data.cpp +++ b/src/endstone_devtools/vanilla_data.cpp @@ -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(); @@ -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; @@ -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", { diff --git a/src/endstone_runtime/bedrock/world/level/block/block_legacy.cpp b/src/endstone_runtime/bedrock/world/level/block/block_legacy.cpp index 9abf485c1..d2558aad0 100644 --- a/src/endstone_runtime/bedrock/world/level/block/block_legacy.cpp +++ b/src/endstone_runtime/bedrock/world/level/block/block_legacy.cpp @@ -14,9 +14,14 @@ #include "bedrock/world/level/block/block_legacy.h" -bool BlockLegacy::canDropWithAnyTool() const +bool BlockLegacy::requiresCorrectToolForDrops() const { - return can_drop_with_any_tool_; + return requires_correct_tool_for_drops; +} + +bool BlockLegacy::isSolid() const +{ + return solid_; } float BlockLegacy::getThickness() const @@ -24,9 +29,9 @@ float BlockLegacy::getThickness() const return thickness_; } -const Material &BlockLegacy::getMaterial() const +float BlockLegacy::getTranslucency() const { - return *material_; + return translucency_; } const std::vector &BlockLegacy::getTags() const