2013-11-14 09:37:09 -05:00
|
|
|
|
|
|
|
// BlockEntity.cpp
|
|
|
|
|
|
|
|
// Implements the cBlockEntity class that is the common ancestor for all block entities
|
|
|
|
|
|
|
|
#include "Globals.h"
|
2021-03-14 22:47:55 -04:00
|
|
|
#include "BannerEntity.h"
|
2014-04-11 18:01:15 -04:00
|
|
|
#include "BeaconEntity.h"
|
2017-07-07 03:31:45 -04:00
|
|
|
#include "BedEntity.h"
|
2013-11-14 09:37:09 -05:00
|
|
|
#include "BlockEntity.h"
|
2020-09-17 10:16:20 -04:00
|
|
|
#include "EnchantingTableEntity.h"
|
2015-09-24 04:48:33 -04:00
|
|
|
#include "BrewingstandEntity.h"
|
2013-11-14 09:37:09 -05:00
|
|
|
#include "ChestEntity.h"
|
2014-01-18 08:16:47 -05:00
|
|
|
#include "CommandBlockEntity.h"
|
2013-11-14 09:37:09 -05:00
|
|
|
#include "DispenserEntity.h"
|
|
|
|
#include "DropperEntity.h"
|
2013-12-06 19:18:58 -05:00
|
|
|
#include "EnderChestEntity.h"
|
2020-09-17 10:16:20 -04:00
|
|
|
#include "EndPortalEntity.h"
|
2014-03-06 19:30:34 -05:00
|
|
|
#include "FlowerPotEntity.h"
|
2013-11-14 09:37:09 -05:00
|
|
|
#include "FurnaceEntity.h"
|
|
|
|
#include "HopperEntity.h"
|
2014-09-19 17:00:54 -04:00
|
|
|
#include "MobHeadEntity.h"
|
|
|
|
#include "MobSpawnerEntity.h"
|
2013-11-14 09:37:09 -05:00
|
|
|
#include "JukeboxEntity.h"
|
|
|
|
#include "NoteEntity.h"
|
|
|
|
#include "SignEntity.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-02 08:50:34 -05:00
|
|
|
cBlockEntity::cBlockEntity(const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta, const Vector3i a_Pos, cWorld * const a_World) :
|
|
|
|
m_Pos(a_Pos),
|
|
|
|
m_RelX(a_Pos.x - cChunkDef::Width * FAST_FLOOR_DIV(a_Pos.x, cChunkDef::Width)),
|
|
|
|
m_RelZ(a_Pos.z - cChunkDef::Width * FAST_FLOOR_DIV(a_Pos.z, cChunkDef::Width)),
|
|
|
|
m_BlockType(a_BlockType),
|
|
|
|
m_BlockMeta(a_BlockMeta),
|
|
|
|
m_World(a_World)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-02 08:50:34 -05:00
|
|
|
OwnedBlockEntity cBlockEntity::Clone(const Vector3i a_Pos)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
2021-01-02 08:50:34 -05:00
|
|
|
auto res = CreateByBlockType(m_BlockType, m_BlockMeta, a_Pos, nullptr);
|
|
|
|
res->CopyFrom(*this);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cItems cBlockEntity::ConvertToPickups() const
|
|
|
|
{
|
|
|
|
return {};
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-02 08:50:34 -05:00
|
|
|
void cBlockEntity::CopyFrom(const cBlockEntity & a_Src)
|
|
|
|
{
|
|
|
|
// Nothing to copy, but check that we're copying the right entity:
|
|
|
|
ASSERT(m_BlockType == a_Src.m_BlockType);
|
|
|
|
ASSERT(m_BlockMeta == a_Src.m_BlockMeta);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OwnedBlockEntity cBlockEntity::CreateByBlockType(const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta, const Vector3i a_Pos, cWorld * const a_World)
|
2013-11-14 09:37:09 -05:00
|
|
|
{
|
|
|
|
switch (a_BlockType)
|
|
|
|
{
|
2021-03-14 22:47:55 -04:00
|
|
|
// Banners:
|
|
|
|
case E_BLOCK_STANDING_BANNER:
|
|
|
|
case E_BLOCK_WALL_BANNER: return std::make_unique<cBannerEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
|
|
|
|
// Others:
|
2020-09-17 10:16:20 -04:00
|
|
|
case E_BLOCK_BEACON: return std::make_unique<cBeaconEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_BED: return std::make_unique<cBedEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_BREWING_STAND: return std::make_unique<cBrewingstandEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_CHEST: return std::make_unique<cChestEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_COMMAND_BLOCK: return std::make_unique<cCommandBlockEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_DISPENSER: return std::make_unique<cDispenserEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_DROPPER: return std::make_unique<cDropperEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_ENCHANTMENT_TABLE: return std::make_unique<cEnchantingTableEntity>(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_ENDER_CHEST: return std::make_unique<cEnderChestEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_END_PORTAL: return std::make_unique<cEndPortalEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_FLOWER_POT: return std::make_unique<cFlowerPotEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_FURNACE: return std::make_unique<cFurnaceEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_HEAD: return std::make_unique<cMobHeadEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_HOPPER: return std::make_unique<cHopperEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_JUKEBOX: return std::make_unique<cJukeboxEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_LIT_FURNACE: return std::make_unique<cFurnaceEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_MOB_SPAWNER: return std::make_unique<cMobSpawnerEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_NOTE_BLOCK: return std::make_unique<cNoteEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_SIGN_POST: return std::make_unique<cSignEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_TRAPPED_CHEST: return std::make_unique<cChestEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
|
|
|
case E_BLOCK_WALLSIGN: return std::make_unique<cSignEntity >(a_BlockType, a_BlockMeta, a_Pos, a_World);
|
2017-09-14 04:48:57 -04:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
LOGD("%s: Requesting creation of an unknown block entity - block type %d (%s)",
|
|
|
|
__FUNCTION__, a_BlockType, ItemTypeToString(a_BlockType).c_str()
|
|
|
|
);
|
|
|
|
ASSERT(!"Requesting creation of an unknown block entity");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-11-14 09:37:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-15 09:32:33 -04:00
|
|
|
|
2021-01-02 08:50:34 -05:00
|
|
|
void cBlockEntity::Destroy()
|
2017-06-15 09:32:33 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-02 08:50:34 -05:00
|
|
|
bool cBlockEntity::IsBlockEntityBlockType(const BLOCKTYPE a_BlockType)
|
2020-09-23 11:06:27 -04:00
|
|
|
{
|
2021-01-02 08:50:34 -05:00
|
|
|
switch (a_BlockType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_BEACON:
|
|
|
|
case E_BLOCK_BED:
|
|
|
|
case E_BLOCK_BREWING_STAND:
|
|
|
|
case E_BLOCK_CHEST:
|
|
|
|
case E_BLOCK_COMMAND_BLOCK:
|
|
|
|
case E_BLOCK_DISPENSER:
|
|
|
|
case E_BLOCK_DROPPER:
|
|
|
|
case E_BLOCK_ENCHANTMENT_TABLE:
|
|
|
|
case E_BLOCK_ENDER_CHEST:
|
|
|
|
case E_BLOCK_END_PORTAL:
|
|
|
|
case E_BLOCK_FLOWER_POT:
|
|
|
|
case E_BLOCK_FURNACE:
|
|
|
|
case E_BLOCK_HEAD:
|
|
|
|
case E_BLOCK_HOPPER:
|
|
|
|
case E_BLOCK_JUKEBOX:
|
|
|
|
case E_BLOCK_LIT_FURNACE:
|
|
|
|
case E_BLOCK_MOB_SPAWNER:
|
|
|
|
case E_BLOCK_NOTE_BLOCK:
|
|
|
|
case E_BLOCK_SIGN_POST:
|
2021-03-14 22:47:55 -04:00
|
|
|
case E_BLOCK_STANDING_BANNER:
|
2021-01-02 08:50:34 -05:00
|
|
|
case E_BLOCK_TRAPPED_CHEST:
|
2021-03-14 22:47:55 -04:00
|
|
|
case E_BLOCK_WALL_BANNER:
|
2021-01-02 08:50:34 -05:00
|
|
|
case E_BLOCK_WALLSIGN:
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-09-23 11:06:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-30 09:23:46 -04:00
|
|
|
void cBlockEntity::OnAddToWorld(cWorld & a_World, cChunk & a_Chunk)
|
|
|
|
{
|
|
|
|
m_World = &a_World;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-02 08:50:34 -05:00
|
|
|
void cBlockEntity::OnRemoveFromWorld()
|
2017-06-15 09:32:33 -04:00
|
|
|
{
|
2021-01-02 08:50:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockEntity::SetPos(const Vector3i a_NewPos)
|
|
|
|
{
|
|
|
|
ASSERT(m_World == nullptr); // Cannot move block entities that represent world blocks (only use this for cBlockArea's BEs)
|
|
|
|
m_Pos = a_NewPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockEntity::SetWorld(cWorld * const a_World)
|
|
|
|
{
|
|
|
|
m_World = a_World;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cBlockEntity::Tick(const std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
|
|
|
{
|
|
|
|
UNUSED(a_Dt);
|
|
|
|
return false;
|
2017-06-15 09:32:33 -04:00
|
|
|
}
|