28class BlockTypeRegistry {
39 enum class LookupByNameImplResolve :
int {
44 struct BlockComplexAliasBlockState {
46 BlockComplexAliasBlockState(
HashedString const& stateName,
int value) noexcept
47 : stateName(stateName),
68 ::ll::TypedStorage<8, 64, ::std::function<
::Block const*(int)>> mCallback;
69 ::ll::TypedStorage<8, 32, ::BaseGameVersion> mMinRequiredVersion;
70 ::ll::TypedStorage<8, 24, ::SemVersion> mFlattenedInBlocksJsonVersion;
71 ::ll::TypedStorage<4, 4, int> mStartVariant;
75 struct DirectAccessBlocks {
79 ::ll::TypedStorage<8, 8, ::BlockType const&> mAirBlock;
84 DirectAccessBlocks& operator=(DirectAccessBlocks
const&);
85 DirectAccessBlocks(DirectAccessBlocks
const&);
93 ::ll::TypedStorage<8, 8, ::BlockType const*> mBlockType;
94 ::ll::TypedStorage<8, 8, ::Block const*> mBlock;
98 using BlockAliasLookupMap = ::std::unordered_map<::HashedString, ::HashedString>;
100 using BlockComplexAliasCallback = ::std::function<
::Block const*(int)>;
102 using BlockComplexAliasLookupMap = ::entt::dense_map<::HashedString, ::BlockTypeRegistry::BlockComplexAliasContent>;
104 using BlockComplexAliasPostSplitBlockNames = ::std::vector<::std::reference_wrapper<::HashedString const>>;
106 using BlockComplexAliasPostSplitBlockNamesList =
107 ::std::vector<::std::vector<::std::reference_wrapper<::HashedString const>>>;
109 using BlockComplexAliasPostSplitBlockNamesLookupMap = ::entt::dense_map<uint64, uint64>;
111 using BlockLookupMap = ::std::map<::HashedString, ::std::unique_ptr<::BlockType>>;
113 using BlockNameHashToHashedStringMap = ::entt::dense_map<uint64, ::HashedString>;
118 ::ll::TypedStorage<8, 16, ::std::map<::HashedString, ::std::unique_ptr<::BlockType>>> mBlockLookupMap;
119 ::ll::TypedStorage<8, 64, ::std::unordered_map<::HashedString, ::HashedString>> mBlockAliasLookupMap;
120 ::ll::TypedStorage<8, 72, ::entt::dense_map<::HashedString, ::BlockTypeRegistry::BlockComplexAliasContent>>
121 mBlockComplexAliasLookupMap;
122 ::ll::TypedStorage<8, 24, ::std::vector<::std::vector<::std::reference_wrapper<::HashedString const>>>>
123 mBlockComplexAliasPostSplitBlockNamesList;
124 ::ll::TypedStorage<8, 72, ::entt::dense_map<uint64, uint64>> mBlockComplexAliasPostSplitBlockNamesLookupMap;
125 ::ll::TypedStorage<8, 16, ::std::map<::HashedString, ::HashedString>> mBlockComplexAliasPreSplitBlockNamesLookupMap;
126 ::ll::TypedStorage<8, 16, ::std::set<::std::string>> mKnownNamespaces;
127 ::ll::TypedStorage<8, 72, ::entt::dense_map<uint64, ::HashedString>> mBlockNameHashToStringMap;
128 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::BlockTypeRegistry::DirectAccessBlocks>> mDirectAccessBlocks;
129 ::ll::TypedStorage<8, 16, ::std::weak_ptr<::VoxelShapes::VoxelShapeRegistry>> mShapeRegistry;
130 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::BlockTypeRegistryRWLock>> mRWLock;
134 [[nodiscard]] static ::BlockTypeRegistry& get() {
return mBlockTypeRegistry().mValue; }
137 template <
class TBlockType,
class... Args>
139 ::std::string nameId = blockName.getString();
143 auto* block =
new TBlockType(nameId, ::std::forward<Args>(args)...);
146 ::std::string lowered = ll::string_utils::toLowerCase(block->mNameInfo->mFullName->getString());
147 auto const colon = lowered.find(
':');
149 mKnownNamespaces->emplace(lowered.substr(0, colon));
150 mBlockLookupMap->try_emplace(
::HashedString{lowered}, std::unique_ptr<::BlockType>{block});
153 mBlockNameHashToStringMap->operator[](hashed.getHash()) = hashed;
160 ::std::vector<::BlockTypeRegistry::BlockComplexAliasBlockState>
const& states,
163 auto result = _lookupByNameImpl(name, 0, ::BlockTypeRegistry::LookupByNameImplResolve::Block, logNotFound);
164 if (result.mBlock ==
nullptr) {
168 return _lookupByNameImplSetNewBlockStates(*result.mBlock, states);
171 ::BlockType
const* lookupByName(::HashedString
const& name,
bool logNotFound =
false)
const {
172 return _lookupByNameImpl(name, 0, ::BlockTypeRegistry::LookupByNameImplResolve::BlockType, logNotFound)
179 MCAPI BlockTypeRegistry();
181 MCAPI ::BlockTypeRegistry::LookupByNameImplReturnType _lookupByNameImpl(
182 ::HashedString
const& name,
184 ::BlockTypeRegistry::LookupByNameImplResolve resolve,
188 MCAPI ::Block
const* _lookupByNameImplSetNewBlockStates(
189 ::Block
const& block,
190 ::std::vector<::BlockTypeRegistry::BlockComplexAliasBlockState>
const& states
194 MCAPI
void addBlocksToValidator(::LinkedAssetValidator& validator, ::BaseGameVersion
const& baseGameVersion)
const;
197 MCAPI
void checkBlockPermutationCap()
const;
199 MCAPI uint64 computeBlockTypeRegistryChecksum(::BaseGameVersion
const& worldBaseGameVersion)
const;
201 MCAPI
void finalizeBlockComponentStorage();
204 MCAPI
void finalizeBlockComponentStorageForRendering(::brstd::function_ref<
void(::BlockType&)> finalizer);
207 MCAPI
void finalizeBlockCustomComponentEvents(::ServerScriptManager
const& scriptManager);
210 MCFOLD
void forEachBlockDEPRECATED(::brstd::function_ref<
bool(::BlockType&)> callback);
213 MCAPI
void forEachBlockMutable(::brstd::function_ref<
bool(::Block&)> callback);
215 MCFOLD
void forEachBlockType(::brstd::function_ref<
bool(::BlockType
const&)> callback)
const;
217 MCAPI ::HashedString
const& getBlockNameFromNameHash(uint64 hash)
const;
219 MCAPI ::std::vector<::std::reference_wrapper<::HashedString const>>
const&
220 getComplexAliasPostSplitBlockNames(::HashedString
const& oldName)
const;
223 MCAPI ::HashedString
const* getComplexAliasPreSplitBlockName(::HashedString
const& postSplitName)
const;
226 MCAPI ::Block
const& getDefaultBlockState(::HashedString
const& name,
bool logNotFound =
false)
const;
228 MCAPI ::BlockTypeRegistry::DirectAccessBlocks
const& getDirectAccessBlocks()
const;
231 MCAPI
int getStartVariantForComplexAliasBlock(::HashedString
const& blockName)
const;
234 MCAPI
void initHardCodedBlockComponents(::Experiments
const& experiments);
236 MCAPI
void initRWLock();
238 MCAPI
bool isComplexAliasBlock(::HashedString
const& blockName)
const;
241 MCAPI
bool isExpectFlattenedInBlocksJson(::HashedString
const& blockName, ::SemVersion
const& currentVersion)
const;
244 MCAPI
void prepareBlocks(uint latestUpdaterVersion);
246 MCAPI
void registerAlias(::HashedString
const& alias, ::HashedString
const& name);
248 MCAPI
void registerComplexAlias(
249 ::HashedString
const& alias,
250 ::std::function<::Block
const*(
int)> callback,
251 ::std::vector<::std::reference_wrapper<::HashedString const>>
const& postSplitBlockNames,
252 ::BaseGameVersion
const& minRequiredVersion,
253 ::SemVersion
const& blocksJsonFormatVersion,
254 ::HashedString defaultNewBlockName,
258 MCAPI
void unregisterBlock(::HashedString
const& name);
260 MCAPI
void unregisterBlocks();
262 MCAPI ~BlockTypeRegistry();
268 MCAPI static ::Bedrock::Owner<::BlockTypeRegistry>& mBlockTypeRegistry();