14 std::shared_ptr<cBlockHandler> aHandler,
15 const std::map<AString, AString> & aHints,
16 const std::map<AString, BlockInfo::HintCallback> & aHintCallbacks
18 m_PluginName(aPluginName),
19 m_BlockTypeName(aBlockTypeName),
20 m_Handler(
std::move(aHandler)),
22 m_HintCallbacks(aHintCallbacks)
44 auto itr =
m_Hints.find(aHintName);
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>(
98 aPluginName, aBlockTypeName, std::move(aHandler), aHints, aHintCallbacks
106 if (itr->second->pluginName() != aPluginName)
140 if (itr->second->pluginName() == aPluginName)
156 const AString & aBlockTypeName,
167 blockInfo->second->setHint(aHintKey, aHintValue);
175 const AString & aBlockTypeName,
196 const std::shared_ptr<BlockInfo> & aPreviousRegistration,
197 const std::shared_ptr<BlockInfo> & aNewRegistration
199 Super(message(aPreviousRegistration, aNewRegistration)),
200 m_PreviousRegistration(aPreviousRegistration),
201 m_NewRegistration(aNewRegistration)
210 const std::shared_ptr<BlockInfo> & aPreviousRegistration,
211 const std::shared_ptr<BlockInfo> & aNewRegistration
215 FMT_STRING(
"Attempting to register BlockTypeName {} from plugin {}, while it is already registered in plugin {}"),
216 aNewRegistration->blockTypeName(),
217 aNewRegistration->pluginName(),
218 aPreviousRegistration->pluginName()
230 const AString & aBlockTypeName,
235 FMT_STRING(
"Attempting to set a hint of nonexistent BlockTypeName.\n\tBlockTypeName = {}\n\tHintKey = {}\n\tHintValue = {}"),
void LOGINFO(std::string_view a_Format, const Args &... args)
Implements custom fmtlib formatting for cChunkCoords.
Represents the state of a single block (previously known as "block meta").
AString hintValue(const AString &aHintName, const BlockState &aBlockState)
Retrieves the value associated with the specified hint for this specific BlockTypeName and BlockState...
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.
void setHint(const AString &aHintKey, const AString &aHintValue)
Sets (creates or updates) a static hint.
std::map< AString, AString > m_Hints
Optional static hints for any subsystem to use, such as "IsSnowable" -> "1".
std::map< AString, HintCallback > m_HintCallbacks
The callbacks for dynamic evaluation of hints, such as "LightValue" -> function(BlockTypeName,...
AString m_BlockTypeName
The name of the block type, such as "minecraft:redstone_lamp".
void removeHint(const AString &aHintKey)
Removes a hint.
void setBlockTypeHint(const AString &aBlockTypeName, const AString &aHintKey, const AString &aHintValue)
Sets (adds or overwrites) a single Hint value for a BlockType.
cCriticalSection m_CSRegistry
The CS that protects m_Registry against multithreaded access.
void removeAllByPlugin(const AString &aPluginName)
Removes all registrations done by the specified plugin.
std::map< AString, std::shared_ptr< BlockInfo > > m_Registry
The actual block type registry.
std::shared_ptr< BlockInfo > blockInfo(const AString &aBlockTypeName)
Returns the registration information for the specified BlockTypeName.
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.
void removeBlockTypeHint(const AString &aBlockTypeName, const AString &aHintKey)
Removes a previously registered single Hint value for a BlockType.
The exception thrown from BlockTypeRegistry::registerBlockType() if the same block type is being regi...
AlreadyRegisteredException(const std::shared_ptr< BlockInfo > &aPreviousRegistration, const std::shared_ptr< BlockInfo > &aNewRegistration)
Creates a new instance of the exception that provides info on both the original registration and the ...
static AString message(const std::shared_ptr< BlockInfo > &aPreviousRegistration, const std::shared_ptr< BlockInfo > &aNewRegistration)
Returns the general exception message formatted by the two registrations.
The exception thrown from BlockTypeRegistry::setBlockTypeHint() if the block type has not been regist...
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 ...
RAII for cCriticalSection - locks the CS on creation, unlocks on destruction.