summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2020-04-03 23:23:38 +0200
committerGitHub <noreply@github.com>2020-04-03 23:23:38 +0200
commitaac592f98598aae327d07b2a1bb155e33c6d51b1 (patch)
tree24f90211d753a7ec87585e919ef7c7acdfa49909 /src/BlockEntities
parentNew hotfix to prevent calling OnBroken (#4600) (diff)
downloadcuberite-aac592f98598aae327d07b2a1bb155e33c6d51b1.tar
cuberite-aac592f98598aae327d07b2a1bb155e33c6d51b1.tar.gz
cuberite-aac592f98598aae327d07b2a1bb155e33c6d51b1.tar.bz2
cuberite-aac592f98598aae327d07b2a1bb155e33c6d51b1.tar.lz
cuberite-aac592f98598aae327d07b2a1bb155e33c6d51b1.tar.xz
cuberite-aac592f98598aae327d07b2a1bb155e33c6d51b1.tar.zst
cuberite-aac592f98598aae327d07b2a1bb155e33c6d51b1.zip
Diffstat (limited to 'src/BlockEntities')
-rw-r--r--src/BlockEntities/BlockEntity.cpp49
-rw-r--r--src/BlockEntities/BlockEntity.h9
2 files changed, 29 insertions, 29 deletions
diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp
index ace8e4662..33ab3253d 100644
--- a/src/BlockEntities/BlockEntity.cpp
+++ b/src/BlockEntities/BlockEntity.cpp
@@ -73,29 +73,28 @@ bool cBlockEntity::IsBlockEntityBlockType(BLOCKTYPE a_BlockType)
-cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World)
+OwnedBlockEntity cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World)
{
switch (a_BlockType)
{
- case E_BLOCK_BEACON: return new cBeaconEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_BED: return new cBedEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_BREWING_STAND: return new cBrewingstandEntity(a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_CHEST: return new cChestEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_COMMAND_BLOCK: return new cCommandBlockEntity(a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_FLOWER_POT: return new cFlowerPotEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_HEAD: return new cMobHeadEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_JUKEBOX: return new cJukeboxEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_MOB_SPAWNER: return new cMobSpawnerEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_NOTE_BLOCK: return new cNoteEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_SIGN_POST: return new cSignEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_TRAPPED_CHEST: return new cChestEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
- case E_BLOCK_WALLSIGN: return new cSignEntity (a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_BED: return cpp14::make_unique<cBedEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_BREWING_STAND: return cpp14::make_unique<cBrewingstandEntity>(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_CHEST: return cpp14::make_unique<cChestEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_COMMAND_BLOCK: return cpp14::make_unique<cCommandBlockEntity>(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_DISPENSER: return cpp14::make_unique<cDispenserEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_DROPPER: return cpp14::make_unique<cDropperEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_ENDER_CHEST: return cpp14::make_unique<cEnderChestEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_FLOWER_POT: return cpp14::make_unique<cFlowerPotEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_FURNACE: return cpp14::make_unique<cFurnaceEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_HEAD: return cpp14::make_unique<cMobHeadEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_HOPPER: return cpp14::make_unique<cHopperEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_JUKEBOX: return cpp14::make_unique<cJukeboxEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_LIT_FURNACE: return cpp14::make_unique<cFurnaceEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_MOB_SPAWNER: return cpp14::make_unique<cMobSpawnerEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_NOTE_BLOCK: return cpp14::make_unique<cNoteEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_SIGN_POST: return cpp14::make_unique<cSignEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_TRAPPED_CHEST: return cpp14::make_unique<cChestEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
+ case E_BLOCK_WALLSIGN: return cpp14::make_unique<cSignEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
default:
{
LOGD("%s: Requesting creation of an unknown block entity - block type %d (%s)",
@@ -111,11 +110,11 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE
-cBlockEntity * cBlockEntity::Clone(Vector3i a_Pos)
+OwnedBlockEntity cBlockEntity::Clone(Vector3i a_Pos)
{
- auto res = std::unique_ptr<cBlockEntity>(CreateByBlockType(m_BlockType, m_BlockMeta, a_Pos, nullptr));
+ auto res = CreateByBlockType(m_BlockType, m_BlockMeta, a_Pos, nullptr);
res->CopyFrom(*this);
- return res.release();
+ return res;
}
@@ -128,7 +127,3 @@ void cBlockEntity::CopyFrom(const cBlockEntity & a_Src)
ASSERT(m_BlockType == a_Src.m_BlockType);
ASSERT(m_BlockMeta == a_Src.m_BlockMeta);
}
-
-
-
-
diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h
index cb377422e..2617edfb6 100644
--- a/src/BlockEntities/BlockEntity.h
+++ b/src/BlockEntities/BlockEntity.h
@@ -1,6 +1,7 @@
#pragma once
+#include <unordered_map>
@@ -31,6 +32,10 @@
class cChunk;
class cPlayer;
class cWorld;
+class cBlockEntity;
+
+using OwnedBlockEntity = std::unique_ptr<cBlockEntity>;
+using cBlockEntities = std::unordered_map<size_t, OwnedBlockEntity>;
@@ -73,11 +78,11 @@ public:
/** 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. */
- static cBlockEntity * CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World = nullptr);
+ static OwnedBlockEntity CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World = nullptr);
/** 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. */
- cBlockEntity * Clone(Vector3i a_Pos);
+ OwnedBlockEntity Clone(Vector3i a_Pos);
/** 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