14 std::shared_ptr<cBlockHandler> aHandler,
15 const std::map<AString, AString> & aHints,
16 const std::map<AString, BlockInfo::HintCallback> & aHintCallbacks
18 mPluginName(aPluginName),
19 mBlockTypeName(aBlockTypeName),
22 mHintCallbacks(aHintCallbacks)
44 auto itr =
mHints.find(aHintName);
61 mHints[aHintKey] = aHintValue;
67 LOGINFO(
"Setting a static hint %s for block type %s, but there's already a callback for that hint. The static hint will be ignored.",
92 std::shared_ptr<cBlockHandler> aHandler,
93 const std::map<AString, AString> & aHints,
94 const std::map<AString, BlockInfo::HintCallback> & aHintCallbacks
97 auto blockInfo = std::make_shared<BlockInfo>(aPluginName, aBlockTypeName, aHandler, aHints, aHintCallbacks);
101 auto itr = mRegistry.find(aBlockTypeName);
102 if (itr != mRegistry.end())
104 if (itr->second->pluginName() != aPluginName)
111 mRegistry[aBlockTypeName] = blockInfo;
121 auto itr = mRegistry.find(aBlockTypeName);
122 if (itr == mRegistry.end())
136 for (
auto itr = mRegistry.begin(); itr != mRegistry.end();)
138 if (itr->second->pluginName() == aPluginName)
140 itr = mRegistry.erase(itr);
154 const AString & aBlockTypeName,
160 auto blockInfo = mRegistry.find(aBlockTypeName);
161 if (blockInfo == mRegistry.end())
165 blockInfo->second->setHint(aHintKey, aHintValue);
173 const AString & aBlockTypeName,
178 auto blockInfo = mRegistry.find(aBlockTypeName);
179 if (blockInfo == mRegistry.end())
183 blockInfo->second->removeHint(aHintKey);
194 std::shared_ptr<BlockInfo> aPreviousRegistration,
195 std::shared_ptr<BlockInfo> aNewRegistration
197 Super(message(aPreviousRegistration, aNewRegistration)),
198 mPreviousRegistration(aPreviousRegistration),
199 mNewRegistration(aNewRegistration)
208 std::shared_ptr<BlockInfo> aPreviousRegistration,
209 std::shared_ptr<BlockInfo> aNewRegistration
212 return Printf(
"Attempting to register BlockTypeName %s from plugin %s, while it is already registered in plugin %s",
213 aNewRegistration->blockTypeName().c_str(),
214 aNewRegistration->pluginName().c_str(),
215 aPreviousRegistration->pluginName().c_str()
227 const AString & aBlockTypeName,
232 "Attempting to set a hint of nonexistent BlockTypeName.\n\tBlockTypeName = %s\n\tHintKey = %s\n\tHintValue = %s",
233 aBlockTypeName.c_str(),
The exception thrown from BlockTypeRegistry::setBlockTypeHint() if the block type has not been regist...
void removeBlockTypeHint(const AString &aBlockTypeName, const AString &aHintKey)
Removes a previously registered single Hint value for a BlockType.
AlreadyRegisteredException(std::shared_ptr< BlockInfo > aPreviousRegistration, std::shared_ptr< BlockInfo > aNewRegistration)
Creates a new instance of the exception that provides info on both the original registration and the ...
void setHint(const AString &aHintKey, const AString &aHintValue)
Sets (creates or updates) a static hint.
NotRegisteredException(const AString &aBlockTypeName, const AString &aHintKey, const AString &aHintValue)
Creates a new instance of the exception that provides info on both the original registration and the ...
std::shared_ptr< BlockInfo > blockInfo(const AString &aBlockTypeName)
Returns the registration information for the specified BlockTypeName.
BlockInfo(const AString &aPluginName, const AString &aBlockTypeName, std::shared_ptr< cBlockHandler > aHandler, const std::map< AString, AString > &aHints=std::map< AString, AString >(), const std::map< AString, HintCallback > &aHintCallbacks=std::map< AString, HintCallback >())
Creates a new instance with the specified BlockTypeName and handler / hints / callbacks.
std::map< AString, AString > mHints
Optional static hints for any subsystem to use, such as "IsSnowable" -> "1".
static AString message(std::shared_ptr< BlockInfo > aPreviousRegistration, std::shared_ptr< BlockInfo > aNewRegistration)
Returns the general exception message formatted by the two registrations.
AString hintValue(const AString &aHintName, const BlockState &aBlockState)
Retrieves the value associated with the specified hint for this specific BlockTypeName and BlockState...
void removeHint(const AString &aHintKey)
Removes a hint.
void LOGINFO(const char *a_Format, fmt::ArgList a_ArgList)
AString & Printf(AString &str, const char *format, fmt::ArgList args)
Output the formatted text into the string.
void removeAllByPlugin(const AString &aPluginName)
Removes all registrations done by the specified plugin.
AString mBlockTypeName
The name of the block type, such as "minecraft:redstone_lamp".
RAII for cCriticalSection - locks the CS on creation, unlocks on destruction.
void registerBlockType(const AString &aPluginName, const AString &aBlockTypeName, std::shared_ptr< cBlockHandler > aHandler, const std::map< AString, AString > &aHints=std::map< AString, AString >(), const std::map< AString, BlockInfo::HintCallback > &aHintCallbacks=std::map< AString, BlockInfo::HintCallback >())
Registers the specified block type.
The exception thrown from BlockTypeRegistry::registerBlockType() if the same block type is being regi...
void setBlockTypeHint(const AString &aBlockTypeName, const AString &aHintKey, const AString &aHintValue)
Sets (adds or overwrites) a single Hint value for a BlockType.
std::map< AString, HintCallback > mHintCallbacks
The callbacks for dynamic evaluation of hints, such as "LightValue" -> function(BlockTypeName, BlockState).
Represents the state of a single block (previously known as "block meta").