From 9b97d63f8f939dbc431cc2dcd9eddf959f86603a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 30 Apr 2021 14:23:46 +0100 Subject: Chest, weather, crash, and miscellaneous fixes (#5215) * Alpha-sort cChestEntity * Chests: use SendUpdateBlockEntity * Pathfinder: fix out of range Y * 1.13: correct weather packet ID * Chests: fix neighbour scanner + Add OnAddToWorld and overload to scan neighbours there, instead of in the constructor/OnUse. This fixes hoppers accessing newly loaded double chests and seeing a null m_Neighbour, thus thinking its a single chest. * Fix typo in cross coords computation. * Simplify hopper logic. * Block entities: ASSERT that type is correct If you match the block type first before calling DoWithBlockEntity, the corresponding block entity must either be empty or correspond to the block type. * Chunk: fix some forgotten PendingSendBE cleanup + Add cleanup in SetAllData, WriteBlockArea - Remove RemoveBlockEntity (used once), HasBlockEntity (not used) * Replace MakeIndex with MakeIndexNoCheck * Remove extraneous MarkDirty in hopper & chests --- src/BlockEntities/BlockEntity.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/BlockEntities/BlockEntity.h') diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h index 3e9cf38e7..e13600e8c 100644 --- a/src/BlockEntities/BlockEntity.h +++ b/src/BlockEntities/BlockEntity.h @@ -51,12 +51,19 @@ public: Returns nullptr for unknown block types. */ static OwnedBlockEntity CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World = nullptr); + /** Called when this block entity's associated block is destroyed. + It is guaranteed that this function is called before OnRemoveFromWorld. */ virtual void Destroy(); /** Returns true if the specified blocktype is supposed to have an associated block entity. */ static bool IsBlockEntityBlockType(BLOCKTYPE a_BlockType); - /** Called when the block entity is removed from a world. */ + /** Called when the block entity object is added to a world. */ + virtual void OnAddToWorld(cWorld & a_World, cChunk & a_Chunk); + + /** 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. */ virtual void OnRemoveFromWorld(); /** Sends the packet defining the block entity to the client specified. -- cgit v1.2.3