Skip to content
LeviMC
English
AutoLightDark
LeviLamina
Loading...
Searching...
No Matches
BlockTypeRegistry.h
1#pragma once
2
3#include "ll/api/utils/StringUtils.h"
4#include "mc/_HeaderOutputPredefine.h"
5#include "mc/world/level/block/BlockType.h"
6
7// auto generated inclusion list
8#include "mc/deps/core/sem_ver/SemVersion.h"
9#include "mc/deps/core/string/HashedString.h"
10#include "mc/deps/core/utility/Owner.h"
11#include "mc/platform/brstd/function_ref.h"
12#include "mc/util/BaseGameVersion.h"
13
14// auto generated forward declare list
15// clang-format off
16class Block;
17class BlockType;
20namespace VoxelShapes { class VoxelShapeRegistry; }
21// clang-format on
22
24public:
25 // BlockTypeRegistry inner types declare
26 // clang-format off
29 struct DirectAccessBlocks;
31 // clang-format on
32
33 // BlockTypeRegistry inner types define
34 enum class LookupByNameImplResolve : int {
35 BlockType = 0,
36 Block = 1,
37 };
38
39 struct BlockComplexAliasBlockState {
40 public:
41 BlockComplexAliasBlockState(HashedString const& stateName, int value) noexcept
42 : stateName(stateName),
43 value(value) {}
44
45 public:
46 // member variables
47 // NOLINTBEGIN
48 ::HashedString stateName;
49 int value;
50 // NOLINTEND
51
52 public:
53 // destructor thunk
54 // NOLINTBEGIN
55 MCNAPI void $dtor();
56 // NOLINTEND
57 };
58
60 public:
61 // member variables
62 // NOLINTBEGIN
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;
67 // NOLINTEND
68 };
69
70 struct DirectAccessBlocks {
71 public:
72 // member variables
73 // NOLINTBEGIN
74 ::ll::TypedStorage<8, 8, ::BlockType const&> mAirBlock;
75 // NOLINTEND
76
77 public:
78 // prevent constructor by default
79 DirectAccessBlocks& operator=(DirectAccessBlocks const&);
80 DirectAccessBlocks(DirectAccessBlocks const&);
81 DirectAccessBlocks();
82 };
83
85 public:
86 // member variables
87 // NOLINTBEGIN
88 ::ll::TypedStorage<8, 8, ::BlockType const*> mBlockType;
89 ::ll::TypedStorage<8, 8, ::Block const*> mBlock;
90 // NOLINTEND
91 };
92
93 using BlockAliasLookupMap = ::std::unordered_map<::HashedString, ::HashedString>;
94
95 using BlockComplexAliasCallback = ::std::function<::Block const*(int)>;
96
97 using BlockComplexAliasLookupMap = ::entt::dense_map<::HashedString, ::BlockTypeRegistry::BlockComplexAliasContent>;
98
99 using BlockComplexAliasPostSplitBlockNames = ::std::vector<::std::reference_wrapper<::HashedString const>>;
100
101 using BlockComplexAliasPostSplitBlockNamesList =
102 ::std::vector<::std::vector<::std::reference_wrapper<::HashedString const>>>;
103
104 using BlockComplexAliasPostSplitBlockNamesLookupMap = ::entt::dense_map<uint64, uint64>;
105
106 using BlockLookupMap = ::std::map<::HashedString, ::std::unique_ptr<::BlockType>>;
107
108 using BlockNameHashToHashedStringMap = ::entt::dense_map<uint64, ::HashedString>;
109
110public:
111 // member variables
112 // NOLINTBEGIN
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;
125 // NOLINTEND
126
127public:
128 [[nodiscard]] static ::BlockTypeRegistry& get() { return mBlockTypeRegistry().mValue; }
129
131 template <class TBlockType, class... Args>
132 TBlockType& registerBlock(::HashedString const& blockName, Args&&... args) {
133 ::std::string nameId = blockName.getString();
134
135 auto* block = new TBlockType(nameId, ::std::forward<Args>(args)...);
136
137 // Registration keys on the lowercased full name; the part before ':' is the namespace.
138 ::std::string lowered = ll::string_utils::toLowerCase(block->mNameInfo->mFullName->getString());
139 auto const colon = lowered.find(':');
140
141 mKnownNamespaces->emplace(lowered.substr(0, colon));
142 mBlockLookupMap->try_emplace(::HashedString{lowered}, std::unique_ptr<::BlockType>{block});
143
144 ::HashedString hashed{lowered};
145 mBlockNameHashToStringMap->operator[](hashed.getHash()) = hashed;
146
147 return *block;
148 }
149
150 ::Block const* lookupByName(
151 ::HashedString const& name,
152 ::std::vector<::BlockTypeRegistry::BlockComplexAliasBlockState> const& states,
153 bool logNotFound
154 ) const {
155 auto result = _lookupByNameImpl(name, 0, ::BlockTypeRegistry::LookupByNameImplResolve::Block, logNotFound);
156 if (result.mBlock == nullptr) {
157 return nullptr;
158 }
159
160 return _lookupByNameImplSetNewBlockStates(*result.mBlock, states);
161 }
162
163 ::BlockType const* lookupByName(::HashedString const& name, bool logNotFound = false) const {
164 return _lookupByNameImpl(name, 0, ::BlockTypeRegistry::LookupByNameImplResolve::BlockType, logNotFound)
165 .mBlockType;
166 }
167
168 LLAPI void finalizeBlockComponentStorage();
169
170public:
171 // member functions
172 // NOLINTBEGIN
174
175 MCAPI ::BlockTypeRegistry::LookupByNameImplReturnType _lookupByNameImpl(
176 ::HashedString const& name,
177 int data,
178 ::BlockTypeRegistry::LookupByNameImplResolve resolve,
179 bool logNotFound
180 ) const;
181
183 ::Block const& block,
184 ::std::vector<::BlockTypeRegistry::BlockComplexAliasBlockState> const& states
185 ) const;
186
187#ifdef LL_PLAT_C
188 MCNAPI void addBlocksToValidator(::LinkedAssetValidator& validator, ::BaseGameVersion const& baseGameVersion) const;
189#endif
190
191 MCNAPI void checkBlockPermutationCap() const;
192
193 MCNAPI uint64 computeBlockTypeRegistryChecksum(::BaseGameVersion const& worldBaseGameVersion) const;
194
195#ifdef LL_PLAT_C
196 MCAPI void finalizeBlockComponentStorageForRendering(::brstd::function_ref<void(::BlockType&)> finalizer);
197#endif
198
200
201#ifdef LL_PLAT_C
202 MCNAPI void forEachBlockDEPRECATED(::brstd::function_ref<bool(::BlockType&)> callback);
203#endif
204
205 MCAPI ::HashedString const& getBlockNameFromNameHash(uint64 hash) const;
206
207 MCNAPI ::std::vector<::std::reference_wrapper<::HashedString const>> const&
209
210#ifdef LL_PLAT_C
211 MCNAPI ::HashedString const* getComplexAliasPreSplitBlockName(::HashedString const& postSplitName) const;
212#endif
213
214 MCAPI ::Block const& getDefaultBlockState(::HashedString const& name, bool logNotFound = false) const;
215
216#ifdef LL_PLAT_C
217 MCNAPI int getStartVariantForComplexAliasBlock(::HashedString const& blockName) const;
218#endif
219
220 MCAPI bool isComplexAliasBlock(::HashedString const& blockName) const;
221
222#ifdef LL_PLAT_C
223 MCNAPI bool
224 isExpectFlattenedInBlocksJson(::HashedString const& blockName, ::SemVersion const& currentVersion) const;
225#endif
226
227 MCNAPI void prepareBlocks(uint latestUpdaterVersion);
228
229 MCNAPI void registerAlias(::HashedString const& alias, ::HashedString const& name);
230
232 ::HashedString const& alias,
233 ::std::function<::Block const*(int)> callback,
234 ::std::vector<::std::reference_wrapper<::HashedString const>> const& postSplitBlockNames,
235 ::BaseGameVersion const& minRequiredVersion,
236 ::SemVersion const& blocksJsonFormatVersion,
237 ::HashedString defaultNewBlockName,
238 int startVariant
239 );
240
241 MCNAPI void unregisterBlocks();
242
244 // NOLINTEND
245
246public:
247 // static variables
248 // NOLINTBEGIN
249 MCAPI static ::Bedrock::Owner<::BlockTypeRegistry>& mBlockTypeRegistry();
250 // NOLINTEND
251
252public:
253 // constructor thunks
254 // NOLINTBEGIN
255 MCNAPI void* $ctor();
256 // NOLINTEND
257
258public:
259 // destructor thunk
260 // NOLINTBEGIN
261 MCNAPI void $dtor();
262 // NOLINTEND
263};
Definition BaseGameVersion.h:8
Definition BlockTypeRegistry.h:59
MCAPI void * $ctor()
MCAPI ::std::vector<::std::reference_wrapper<::HashedString const > > const & getComplexAliasPostSplitBlockNames(::HashedString const &oldName) const
MCAPI void unregisterBlocks()
MCAPI void registerAlias(::HashedString const &alias, ::HashedString const &name)
MCAPI::Block const * _lookupByNameImplSetNewBlockStates(::Block const &block, ::std::vector<::BlockTypeRegistry::BlockComplexAliasBlockState > const &states) const
TBlockType & registerBlock(::HashedString const &blockName, Args &&... args)
Constructs a new block of type TBlockType and registers it under blockName.
Definition BlockTypeRegistry.h:132
MCAPI void finalizeBlockCustomComponentEvents(::ServerScriptManager const &scriptManager)
MCAPI void prepareBlocks(uint latestUpdaterVersion)
MCAPI uint64 computeBlockTypeRegistryChecksum(::BaseGameVersion const &worldBaseGameVersion) const
MCAPI BlockTypeRegistry()
MCAPI ~BlockTypeRegistry()
MCAPI void checkBlockPermutationCap() const
MCAPI void $dtor()
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)
Definition BlockType.h:79
Definition Block.h:42
Definition HashedString.h:5
Definition LinkedAssetValidator.h:9
Definition SemVersion.h:15
Definition ServerScriptManager.h:78
Definition VoxelShapeRegistry.h:17
Definition function_ref.h:60
Definition BlockTypeRegistry.h:39
Definition BlockTypeRegistry.h:70
Definition BlockTypeRegistry.h:84