Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Types | Public Member Functions | Private Attributes | List of all members
BlockInfo Class Reference

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 AStringblockTypeName () const
 
std::shared_ptr< cBlockHandlerhandler () 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 AStringpluginName () 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< cBlockHandlerm_Handler
 The callbacks to call for various interaction. More...
 
std::map< AString, HintCallbackm_HintCallbacks
 The callbacks for dynamic evaluation of hints, such as "LightValue" -> function(BlockTypeName, BlockState). More...
 
std::map< AString, AStringm_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...
 

Detailed Description

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.

Member Typedef Documentation

◆ HintCallback

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.

Constructor & Destructor Documentation

◆ BlockInfo()

BlockInfo::BlockInfo ( const AString aPluginName,
const AString aBlockTypeName,
std::shared_ptr< cBlockHandler aHandler,
const std::map< AString, AString > &  aHints = std::map<AStringAString>(),
const std::map< AString, HintCallback > &  aHintCallbacks = std::map<AStringHintCallback>() 
)

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.

Member Function Documentation

◆ blockTypeName()

const AString& BlockInfo::blockTypeName ( ) const
inline

Definition at line 54 of file BlockTypeRegistry.h.

◆ handler()

std::shared_ptr<cBlockHandler> BlockInfo::handler ( ) const
inline

Definition at line 55 of file BlockTypeRegistry.h.

◆ hintValue()

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.

◆ pluginName()

const AString& BlockInfo::pluginName ( ) const
inline

Definition at line 53 of file BlockTypeRegistry.h.

◆ removeHint()

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.

◆ setHint()

void BlockInfo::setHint ( const AString aHintKey,
const AString aHintValue 
)

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.

Member Data Documentation

◆ m_BlockTypeName

AString BlockInfo::m_BlockTypeName
private

The name of the block type, such as "minecraft:redstone_lamp".

Definition at line 73 of file BlockTypeRegistry.h.

◆ m_Handler

std::shared_ptr<cBlockHandler> BlockInfo::m_Handler
private

The callbacks to call for various interaction.

Definition at line 76 of file BlockTypeRegistry.h.

◆ m_HintCallbacks

std::map<AString, HintCallback> BlockInfo::m_HintCallbacks
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.

◆ m_Hints

std::map<AString, AString> BlockInfo::m_Hints
private

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.

◆ m_PluginName

AString BlockInfo::m_PluginName
private

The name of the plugin that registered the block.

Definition at line 70 of file BlockTypeRegistry.h.


The documentation for this class was generated from the following files: