diff --git a/res/content/base/blocks/coal_ore.json b/res/content/base/blocks/coal_ore.json index c73998ec..ae2bd25b 100644 --- a/res/content/base/blocks/coal_ore.json +++ b/res/content/base/blocks/coal_ore.json @@ -1,4 +1,5 @@ { "texture": "coal_ore", + "tags": ["base:ore"], "base:durability": 16.0 } diff --git a/res/content/base/blocks/water.json b/res/content/base/blocks/water.json index f7785044..0c2fa020 100644 --- a/res/content/base/blocks/water.json +++ b/res/content/base/blocks/water.json @@ -7,5 +7,6 @@ "obstacle": false, "selectable": false, "replaceable": true, - "translucent": true + "translucent": true, + "tags": ["base:liquid"] } diff --git a/src/content/ContentBuilder.cpp b/src/content/ContentBuilder.cpp index ff0bb18a..448adc27 100644 --- a/src/content/ContentBuilder.cpp +++ b/src/content/ContentBuilder.cpp @@ -28,6 +28,9 @@ std::unique_ptr ContentBuilder::build() { // Generating runtime info def.rt.id = blockDefsIndices.size(); def.rt.emissive = *reinterpret_cast(def.emission); + for (const auto& tag : def.tags) { + def.rt.tags.push_back(tags.add(tag)); + } if (def.variants) { for (auto& variant : def.variants->variants) { diff --git a/src/content/ContentBuilder.hpp b/src/content/ContentBuilder.hpp index 7d3df1f6..8a938819 100644 --- a/src/content/ContentBuilder.hpp +++ b/src/content/ContentBuilder.hpp @@ -62,6 +62,27 @@ public: } }; +struct TagsIndices { + int nextIndex = 1; + std::unordered_map map; + + int add(const std::string& tag) { + const auto& found = map.find(tag); + if (found != map.end()) { + return found->second; + } + return map[tag] = nextIndex++; + } + + int indexOf(const std::string& tag) { + const auto& found = map.find(tag); + if (found == map.end()) { + return -1; + } + return found->second; + } +}; + class ContentBuilder { UptrsMap blockMaterials; UptrsMap skeletons; @@ -74,6 +95,7 @@ public: ContentUnitBuilder generators {allNames, ContentType::GENERATOR}; ResourceIndicesSet resourceIndices {}; dv::value defaults = nullptr; + TagsIndices tags {}; ~ContentBuilder(); diff --git a/src/content/loading/BlockLoader.cpp b/src/content/loading/BlockLoader.cpp index bde250a5..a8615e3f 100644 --- a/src/content/loading/BlockLoader.cpp +++ b/src/content/loading/BlockLoader.cpp @@ -89,6 +89,7 @@ template<> void ContentUnitLoader::loadUnit( ) { auto root = io::read_json(file); process_properties(def, name, root); + process_tags(def, root); if (root.has("parent")) { const auto& parentName = root["parent"].asString(); diff --git a/src/content/loading/ContentLoadingCommons.hpp b/src/content/loading/ContentLoadingCommons.hpp index 652b550f..a4a81c98 100644 --- a/src/content/loading/ContentLoadingCommons.hpp +++ b/src/content/loading/ContentLoadingCommons.hpp @@ -21,3 +21,17 @@ inline void process_properties(T& def, const std::string& name, const dv::value& process_method(def.properties, suffix, field, value); } } + +template +inline void process_tags(T& def, const dv::value& root) { + if (!root.has("tags")) { + return; + } + const auto& tags = root["tags"]; + for (const auto& tagValue : tags) { + if (!tagValue.isString()) { + continue; + } + def.tags.push_back(tagValue.asString()); + } +} diff --git a/src/content/loading/ItemLoader.cpp b/src/content/loading/ItemLoader.cpp index 97ddd334..cba07771 100644 --- a/src/content/loading/ItemLoader.cpp +++ b/src/content/loading/ItemLoader.cpp @@ -19,6 +19,7 @@ template<> void ContentUnitLoader::loadUnit( ) { auto root = io::read_json(file); process_properties(def, name, root); + process_tags(def, root); if (root.has("parent")) { const auto& parentName = root["parent"].asString(); diff --git a/src/items/ItemDef.hpp b/src/items/ItemDef.hpp index 4e7e120c..52ebd835 100644 --- a/src/items/ItemDef.hpp +++ b/src/items/ItemDef.hpp @@ -2,6 +2,7 @@ #include #include +#include #include "data/dv.hpp" #include "typedefs.hpp" @@ -64,11 +65,15 @@ struct ItemDef { std::string scriptFile; + std::vector tags; + struct { itemid_t id; blockid_t placingBlock; ItemFuncsSet funcsset {}; bool emissive = false; + + std::vector tags; } rt {}; ItemDef(const std::string& name); diff --git a/src/voxels/Block.hpp b/src/voxels/Block.hpp index 875d6bf4..3d5a86a9 100644 --- a/src/voxels/Block.hpp +++ b/src/voxels/Block.hpp @@ -261,6 +261,8 @@ public: std::unique_ptr variants; + std::vector tags; + /// @brief Runtime indices (content indexing results) struct { /// @brief block runtime integer id @@ -285,6 +287,8 @@ public: itemid_t pickingItem = 0; blockid_t surfaceReplacement = 0; + + std::vector tags; } rt {}; Block(const std::string& name);