Cuberite
A lightweight, fast and extensible game server for Minecraft
|
#include <BlockEntity.h>
Public Member Functions | |
OwnedBlockEntity | Clone (Vector3i a_Pos) |
Makes an exact copy of this block entity, except for its m_World (set to nullptr), and at a new position. More... | |
virtual cItems | ConvertToPickups () const |
Returns the contents of this block entity that it would drop if broken. More... | |
virtual void | CopyFrom (const cBlockEntity &a_Src) |
Copies all properties of a_Src into this entity, except for its m_World and location. More... | |
virtual void | Destroy () |
Called when this block entity's associated block is destroyed. More... | |
BLOCKTYPE | GetBlockType () const |
int | GetChunkX () const |
int | GetChunkZ () const |
Vector3i | GetPos () const |
int | GetPosX () const |
int | GetPosY () const |
int | GetPosZ () const |
Vector3i | GetRelPos () const |
int | GetRelX () const |
int | GetRelZ () const |
cWorld * | GetWorld () const |
virtual void | OnAddToWorld (cWorld &a_World, cChunk &a_Chunk) |
Called when the block entity object is added to a world. More... | |
virtual void | OnRemoveFromWorld () |
Called when the block entity object is removed from a world. More... | |
virtual void | SendTo (cClientHandle &a_Client)=0 |
Sends the packet defining the block entity to the client specified. More... | |
void | SetPos (Vector3i a_NewPos) |
Updates the internally stored position. More... | |
void | SetWorld (cWorld *a_World) |
virtual bool | Tick (std::chrono::milliseconds a_Dt, cChunk &a_Chunk) |
Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking. More... | |
virtual bool | UsedBy (cPlayer *a_Player)=0 |
Called when a player uses this entity; should open the UI window. More... | |
virtual | ~cBlockEntity ()=default |
Static Public Member Functions | |
static OwnedBlockEntity | CreateByBlockType (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World=nullptr) |
Creates a new block entity for the specified block type at the specified absolute pos. More... | |
static bool | IsBlockEntityBlockType (BLOCKTYPE a_BlockType) |
Returns true if the specified blocktype is supposed to have an associated block entity. More... | |
Protected Member Functions | |
cBlockEntity (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World) | |
Protected Attributes | |
NIBBLETYPE | m_BlockMeta |
The block meta representing this particular instance in the world Mainly used for directional entities, such as dispensers. More... | |
BLOCKTYPE | m_BlockType |
The blocktype representing this particular instance in the world. More... | |
Vector3i | m_Pos |
Position in absolute block coordinates. More... | |
int | m_RelX |
Position relative to the chunk, used to speed up ticking. More... | |
int | m_RelZ |
cWorld * | m_World |
Definition at line 24 of file BlockEntity.h.
|
protected |
Definition at line 32 of file BlockEntity.cpp.
|
virtualdefault |
OwnedBlockEntity cBlockEntity::Clone | ( | Vector3i | a_Pos | ) |
Makes an exact copy of this block entity, except for its m_World (set to nullptr), and at a new position.
Uses CopyFrom() to copy the properties.
Definition at line 46 of file BlockEntity.cpp.
|
virtual |
Returns the contents of this block entity that it would drop if broken.
Note that the block handler will usually handle pickups for the block itself, in addition to any items returned here.
Reimplemented in cMobHeadEntity, cJukeboxEntity, cFlowerPotEntity, cEnchantingTableEntity, cBlockEntityWithItems, cBedEntity, and cBannerEntity.
Definition at line 57 of file BlockEntity.cpp.
|
virtual |
Copies all properties of a_Src into this entity, except for its m_World and location.
Each non-abstract descendant should override to copy its specific properties, and call Super::CopyFrom(a_Src) to copy the common ones.
Reimplemented in cSignEntity, cNoteEntity, cMobSpawnerEntity, cMobHeadEntity, cJukeboxEntity, cHopperEntity, cFurnaceEntity, cFlowerPotEntity, cEndPortalEntity, cEnchantingTableEntity, cDropSpenserEntity, cCommandBlockEntity, cChestEntity, cBrewingstandEntity, cBlockEntityWithItems, cBedEntity, cBeaconEntity, and cBannerEntity.
Definition at line 66 of file BlockEntity.cpp.
|
static |
Creates a new block entity for the specified block type at the specified absolute pos.
If a_World is valid, then the entity is created bound to that world Returns nullptr for unknown block types.
Definition at line 77 of file BlockEntity.cpp.
|
virtual |
Called when this block entity's associated block is destroyed.
It is guaranteed that this function is called before OnRemoveFromWorld.
Reimplemented in cJukeboxEntity.
Definition at line 122 of file BlockEntity.cpp.
|
inline |
Definition at line 97 of file BlockEntity.h.
|
inline |
Definition at line 101 of file BlockEntity.h.
|
inline |
Definition at line 102 of file BlockEntity.h.
|
inline |
Definition at line 90 of file BlockEntity.h.
|
inline |
Definition at line 91 of file BlockEntity.h.
|
inline |
Definition at line 92 of file BlockEntity.h.
|
inline |
Definition at line 93 of file BlockEntity.h.
|
inline |
Definition at line 95 of file BlockEntity.h.
|
inline |
Definition at line 104 of file BlockEntity.h.
|
inline |
Definition at line 105 of file BlockEntity.h.
|
inline |
Definition at line 99 of file BlockEntity.h.
|
static |
Returns true if the specified blocktype is supposed to have an associated block entity.
Definition at line 130 of file BlockEntity.cpp.
Called when the block entity object is added to a world.
Reimplemented in cChestEntity.
Definition at line 171 of file BlockEntity.cpp.
|
virtual |
Called when the block entity object is removed from a world.
This occurs when the chunk it resides in is unloaded, or when the associated block is destroyed. If it is the latter, Destroy() is guaranteed to be called first.
Reimplemented in cFurnaceEntity, cEnderChestEntity, cDropSpenserEntity, cChestEntity, cBrewingstandEntity, and cBeaconEntity.
Definition at line 180 of file BlockEntity.cpp.
|
pure virtual |
Sends the packet defining the block entity to the client specified.
To send to all eligible clients, use cWorld::BroadcastBlockEntity()
Implemented in cSignEntity, cMobSpawnerEntity, cMobHeadEntity, cHopperEntity, cFurnaceEntity, cFlowerPotEntity, cEndPortalEntity, cEnderChestEntity, cEnchantingTableEntity, cDropSpenserEntity, cCommandBlockEntity, cChestEntity, cBrewingstandEntity, cBedEntity, cBeaconEntity, cBannerEntity, cNoteEntity, and cJukeboxEntity.
void cBlockEntity::SetPos | ( | Vector3i | a_NewPos | ) |
Updates the internally stored position.
Note that this should not ever be used for world-contained block entities, it is meant only for when BEs in a cBlockArea are manipulated. Asserts that the block entity is not assigned to a world.
Definition at line 188 of file BlockEntity.cpp.
void cBlockEntity::SetWorld | ( | cWorld * | a_World | ) |
Definition at line 198 of file BlockEntity.cpp.
|
virtual |
Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking.
By default does nothing.
Reimplemented in cMobSpawnerEntity, cHopperEntity, cFurnaceEntity, cDropSpenserEntity, cCommandBlockEntity, cBrewingstandEntity, and cBeaconEntity.
Definition at line 207 of file BlockEntity.cpp.
|
pure virtual |
Called when a player uses this entity; should open the UI window.
returns true if the use was successful, return false to use the block as a "normal" block
Implemented in cSignEntity, cNoteEntity, cMobSpawnerEntity, cMobHeadEntity, cJukeboxEntity, cHopperEntity, cFurnaceEntity, cFlowerPotEntity, cEndPortalEntity, cEnderChestEntity, cEnchantingTableEntity, cDropSpenserEntity, cCommandBlockEntity, cChestEntity, cBrewingstandEntity, cBedEntity, cBeaconEntity, and cBannerEntity.
|
protected |
The block meta representing this particular instance in the world Mainly used for directional entities, such as dispensers.
Definition at line 124 of file BlockEntity.h.
|
protected |
The blocktype representing this particular instance in the world.
Mainly used for multi-block-type entities, such as furnaces / lit furnaces.
Definition at line 120 of file BlockEntity.h.
|
protected |
Position in absolute block coordinates.
Definition at line 113 of file BlockEntity.h.
|
protected |
Position relative to the chunk, used to speed up ticking.
Definition at line 116 of file BlockEntity.h.
|
protected |
Definition at line 116 of file BlockEntity.h.
|
protected |
Definition at line 126 of file BlockEntity.h.