34 enum class LookupByNameImplResolve :
int {
39 struct BlockComplexAliasBlockState {
41 BlockComplexAliasBlockState(
HashedString const& stateName,
int value) noexcept
42 : stateName(stateName),
63 ::ll::TypedStorage<8, 64, ::std::function<
::Block const*(int)>> mCallback;
64 ::ll::TypedStorage<8, 32, ::BaseGameVersion> mMinRequiredVersion;
65 ::ll::TypedStorage<8, 24, ::SemVersion> mFlattenedInBlocksJsonVersion;
66 ::ll::TypedStorage<4, 4, int> mStartVariant;
70 struct DirectAccessBlocks {
74 ::ll::TypedStorage<8, 8, ::BlockType const&> mAirBlock;
79 DirectAccessBlocks& operator=(DirectAccessBlocks
const&);
80 DirectAccessBlocks(DirectAccessBlocks
const&);
88 ::ll::TypedStorage<8, 8, ::BlockType const*> mBlockType;
89 ::ll::TypedStorage<8, 8, ::Block const*> mBlock;
93 using BlockAliasLookupMap = ::std::unordered_map<::HashedString, ::HashedString>;
95 using BlockComplexAliasCallback = ::std::function<
::Block const*(int)>;
97 using BlockComplexAliasLookupMap = ::entt::dense_map<::HashedString, ::BlockTypeRegistry::BlockComplexAliasContent>;
99 using BlockComplexAliasPostSplitBlockNames = ::std::vector<::std::reference_wrapper<::HashedString const>>;
101 using BlockComplexAliasPostSplitBlockNamesList =
102 ::std::vector<::std::vector<::std::reference_wrapper<::HashedString const>>>;
104 using BlockComplexAliasPostSplitBlockNamesLookupMap = ::entt::dense_map<uint64, uint64>;
106 using BlockLookupMap = ::std::map<::HashedString, ::std::unique_ptr<::BlockType>>;
108 using BlockNameHashToHashedStringMap = ::entt::dense_map<uint64, ::HashedString>;
113 ::ll::TypedStorage<8, 16, ::std::map<::HashedString, ::std::unique_ptr<::BlockType>>> mBlockLookupMap;
114 ::ll::TypedStorage<8, 64, ::std::unordered_map<::HashedString, ::HashedString>> mBlockAliasLookupMap;
115 ::ll::TypedStorage<8, 72, ::entt::dense_map<::HashedString, ::BlockTypeRegistry::BlockComplexAliasContent>>
116 mBlockComplexAliasLookupMap;
117 ::ll::TypedStorage<8, 24, ::std::vector<::std::vector<::std::reference_wrapper<::HashedString const>>>>
118 mBlockComplexAliasPostSplitBlockNamesList;
119 ::ll::TypedStorage<8, 72, ::entt::dense_map<uint64, uint64>> mBlockComplexAliasPostSplitBlockNamesLookupMap;
120 ::ll::TypedStorage<8, 16, ::std::map<::HashedString, ::HashedString>> mBlockComplexAliasPreSplitBlockNamesLookupMap;
121 ::ll::TypedStorage<8, 16, ::std::set<::std::string>> mKnownNamespaces;
122 ::ll::TypedStorage<8, 72, ::entt::dense_map<uint64, ::HashedString>> mBlockNameHashToStringMap;
123 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::BlockTypeRegistry::DirectAccessBlocks>> mDirectAccessBlocks;
124 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::VoxelShapes::VoxelShapeRegistry>> mShapeRegistry;
128 [[nodiscard]] static ::BlockTypeRegistry& get() {
return mBlockTypeRegistry().mValue; }
131 template <
class TBlockType,
class... Args>
133 ::std::string nameId = blockName.getString();
135 auto* block =
new TBlockType(nameId, ::std::forward<Args>(args)...);
138 ::std::string lowered = ll::string_utils::toLowerCase(block->mNameInfo->mFullName->getString());
139 auto const colon = lowered.find(
':');
141 mKnownNamespaces->emplace(lowered.substr(0, colon));
142 mBlockLookupMap->try_emplace(
::HashedString{lowered}, std::unique_ptr<::BlockType>{block});
145 mBlockNameHashToStringMap->operator[](hashed.getHash()) = hashed;
152 ::std::vector<::BlockTypeRegistry::BlockComplexAliasBlockState>
const& states,
155 auto result = _lookupByNameImpl(name, 0, ::BlockTypeRegistry::LookupByNameImplResolve::Block, logNotFound);
156 if (result.mBlock ==
nullptr) {
163 ::BlockType
const* lookupByName(::HashedString
const& name,
bool logNotFound =
false)
const {
164 return _lookupByNameImpl(name, 0, ::BlockTypeRegistry::LookupByNameImplResolve::BlockType, logNotFound)
168 LLAPI
void finalizeBlockComponentStorage();
175 MCAPI ::BlockTypeRegistry::LookupByNameImplReturnType _lookupByNameImpl(
178 ::BlockTypeRegistry::LookupByNameImplResolve resolve,
184 ::std::vector<::BlockTypeRegistry::BlockComplexAliasBlockState>
const& states
205 MCAPI ::HashedString
const& getBlockNameFromNameHash(uint64 hash)
const;
207 MCNAPI ::std::vector<::std::reference_wrapper<::HashedString const>>
const&
211 MCNAPI ::HashedString
const* getComplexAliasPreSplitBlockName(
::HashedString const& postSplitName)
const;
214 MCAPI ::Block
const& getDefaultBlockState(
::HashedString const& name,
bool logNotFound =
false)
const;
217 MCNAPI
int getStartVariantForComplexAliasBlock(
::HashedString const& blockName)
const;
220 MCAPI
bool isComplexAliasBlock(
::HashedString const& blockName)
const;
233 ::std::function<
::Block const*(
int)> callback,
234 ::std::vector<::std::reference_wrapper<::HashedString const>>
const& postSplitBlockNames,
249 MCAPI static ::Bedrock::Owner<::BlockTypeRegistry>& mBlockTypeRegistry();
MCAPI void registerComplexAlias(::HashedString const &alias, ::std::function<::Block const *(int)> callback, ::std::vector<::std::reference_wrapper<::HashedString const > > const &postSplitBlockNames, ::BaseGameVersion const &minRequiredVersion, ::SemVersion const &blocksJsonFormatVersion, ::HashedString defaultNewBlockName, int startVariant)