Skip to content

Class endstone::BlockState

ClassList > endstone > BlockState

Represents a captured state of a block, which will not update automatically. More...

  • #include <endstone/block/block_state.h>

Inherits the following classes: std::enable_shared_from_this< BlockState >

Public Functions

Type Name
virtual Result< std::unique_ptr< Block > > getBlock () const = 0
Gets the block represented by this block state.
virtual std::shared_ptr< BlockData > getData () const = 0
Gets the data for this block state.
virtual Dimension & getDimension () const = 0
Gets the dimension which contains the block represented by this block state.
virtual Location getLocation () const = 0
Gets the location of this block state.
virtual std::string getType () const = 0
Gets the type of this block state.
virtual int getX () const = 0
Gets the x-coordinate of this block state.
virtual int getY () const = 0
Gets the y-coordinate of this block state.
virtual int getZ () const = 0
Gets the z-coordinate of this block state.
virtual Result< void > setData (std::shared_ptr< BlockData > data) = 0
Sets the data for this block state.
virtual Result< void > setType (std::string type) = 0
Sets the type of this block state.
virtual Result< bool > update () = 0
Attempts to update the block represented by this state, setting it to yhe new values as defined by this state.
virtual Result< bool > update (bool force) = 0
Attempts to update the block represented by this state, setting it to the new values as defined by this state.
virtual Result< bool > update (bool force, bool apply_physics) = 0
Attempts to update the block represented by this state, setting it to the new values as defined by this state.
virtual ~BlockState () = default

Detailed Description

Unlike Block, which only one object can exist per coordinate, BlockState can exist multiple times for any given Block. Note that another plugin may change the state of the block, and you will not know, or they may change the block to another type entirely, causing your BlockState to become invalid.

Public Functions Documentation

function getBlock

Gets the block represented by this block state.

virtual Result< std::unique_ptr< Block > > endstone::BlockState::getBlock () const = 0

Returns:

the block represented by this block state


function getData

Gets the data for this block state.

virtual std::shared_ptr< BlockData > endstone::BlockState::getData () const = 0

Returns:

block specific data


function getDimension

Gets the dimension which contains the block represented by this block state.

virtual Dimension & endstone::BlockState::getDimension () const = 0

Returns:

the dimension containing the block represented by this block state


function getLocation

Gets the location of this block state.

virtual Location endstone::BlockState::getLocation () const = 0

Returns:

the location


function getType

Gets the type of this block state.

virtual std::string endstone::BlockState::getType () const = 0

Returns:

block type


function getX

Gets the x-coordinate of this block state.

virtual int endstone::BlockState::getX () const = 0

Returns:

x-coordinate


function getY

Gets the y-coordinate of this block state.

virtual int endstone::BlockState::getY () const = 0

Returns:

y-coordinate


function getZ

Gets the z-coordinate of this block state.

virtual int endstone::BlockState::getZ () const = 0

Returns:

z-coordinate


function setData

Sets the data for this block state.

virtual Result< void > endstone::BlockState::setData (
    std::shared_ptr< BlockData > data
) = 0

Parameters:

  • data New block specific data

function setType

Sets the type of this block state.

virtual Result< void > endstone::BlockState::setType (
    std::string type
) = 0

Parameters:

  • type Block type to change this block state to

function update [⅓]

Attempts to update the block represented by this state, setting it to yhe new values as defined by this state.

virtual Result< bool > endstone::BlockState::update () = 0

This has the same effect as calling update(false). That is to say, this will not modify the state of a block if it is no longer the same type as it was when this state was taken. It will return false in this eventuality.

Returns:

true if the update was successful, otherwise false


function update [⅔]

Attempts to update the block represented by this state, setting it to the new values as defined by this state.

virtual Result< bool > endstone::BlockState::update (
    bool force
) = 0

This has the same effect as calling update(force, true). That is to say, this will trigger a physics update to surrounding blocks.

Parameters:

  • force true to forcefully set the state

Returns:

true if the update was successful, otherwise false


function update [3/3]

Attempts to update the block represented by this state, setting it to the new values as defined by this state.

virtual Result< bool > endstone::BlockState::update (
    bool force,
    bool apply_physics
) = 0

Unless force is true, this will not modify the state of a block if it is no longer the same type as it was when this state was taken. It will return false in this eventuality.

If force is true, it will set the type of the block to match the new state, set the state data and then return true.

If apply_physics is true, it will trigger a physics update on surrounding blocks which could cause them to update or disappear.

Parameters:

  • force true to forcefully set the state
  • apply_physics false to cancel updating physics on surrounding blocks

Returns:

true if the update was successful, otherwise false


function ~BlockState

virtual endstone::BlockState::~BlockState () = default


The documentation for this class was generated from the following file include/endstone/block/block_state.h