Cuberite
A lightweight, fast and extensible game server for Minecraft
|
Complete information about a single block type. More...
#include <BlockTypeRegistry.h>
Public Types | |
using | HintCallback = std::function< AString(const AString &aTypeName, const BlockState &aBlockState)> |
Callback is used to query block hints dynamically, based on the current BlockState. More... | |
Public Member Functions | |
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. More... | |
const AString & | blockTypeName () const |
std::shared_ptr< cBlockHandler > | handler () const |
AString | hintValue (const AString &aHintName, const BlockState &aBlockState) |
Retrieves the value associated with the specified hint for this specific BlockTypeName and BlockState. More... | |
const AString & | pluginName () const |
void | removeHint (const AString &aHintKey) |
Removes a hint. More... | |
void | setHint (const AString &aHintKey, const AString &aHintValue) |
Sets (creates or updates) a static hint. More... | |
Private Attributes | |
AString | m_BlockTypeName |
The name of the block type, such as "minecraft:redstone_lamp". More... | |
std::shared_ptr< cBlockHandler > | m_Handler |
The callbacks to call for various interaction. More... | |
std::map< AString, HintCallback > | m_HintCallbacks |
The callbacks for dynamic evaluation of hints, such as "LightValue" -> function(BlockTypeName, BlockState). More... | |
std::map< AString, AString > | m_Hints |
Optional static hints for any subsystem to use, such as "IsSnowable" -> "1". More... | |
AString | m_PluginName |
The name of the plugin that registered the block. More... | |
Complete information about a single block type.
The BlockTypeRegistry uses this structure to store the registered information.
Definition at line 24 of file BlockTypeRegistry.h.
using BlockInfo::HintCallback = std::function<AString(const AString & aTypeName, const BlockState & aBlockState)> |
Callback is used to query block hints dynamically, based on the current BlockState.
Useful for example for redstone lamps that can be turned on or off.
Definition at line 30 of file BlockTypeRegistry.h.
BlockInfo::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.
aPluginName specifies the name of the plugin to associate with the block type (to allow unload / reload).
Definition at line 11 of file BlockTypeRegistry.cpp.
|
inline |
Definition at line 54 of file BlockTypeRegistry.h.
|
inline |
Definition at line 55 of file BlockTypeRegistry.h.
AString BlockInfo::hintValue | ( | const AString & | aHintName, |
const BlockState & | aBlockState | ||
) |
Retrieves the value associated with the specified hint for this specific BlockTypeName and BlockState.
Queries hint callbacks first, then static hints if a callback doesn't exist. Returns an empty string if hint not found at all.
Definition at line 30 of file BlockTypeRegistry.cpp.
|
inline |
Definition at line 53 of file BlockTypeRegistry.h.
void BlockInfo::removeHint | ( | const AString & | aHintKey | ) |
Removes a hint.
Silently ignored if the hint hasn't been previously set.
Definition at line 77 of file BlockTypeRegistry.cpp.
Sets (creates or updates) a static hint.
Hints provided by callbacks are unaffected by this - callbacks are "higher priority", they overwrite anything set here. Logs an info message if the hint is already provided by a hint callback.
Definition at line 59 of file BlockTypeRegistry.cpp.
|
private |
The name of the block type, such as "minecraft:redstone_lamp".
Definition at line 73 of file BlockTypeRegistry.h.
|
private |
The callbacks to call for various interaction.
Definition at line 76 of file BlockTypeRegistry.h.
|
private |
The callbacks for dynamic evaluation of hints, such as "LightValue" -> function(BlockTypeName, BlockState).
Hint callbacks are of higher priority than m_Hints - if a hint is provided by a m_HintCallback, its value in m_Hints is ignored.
Definition at line 84 of file BlockTypeRegistry.h.
Optional static hints for any subsystem to use, such as "IsSnowable" -> "1".
Hint callbacks are of higher priority than m_Hints - if a hint is provided by a m_HintCallback, its value in m_Hints is ignored.
Definition at line 80 of file BlockTypeRegistry.h.
|
private |
The name of the plugin that registered the block.
Definition at line 70 of file BlockTypeRegistry.h.