2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
2017-07-07 03:31:45 -04:00
|
|
|
#include "ChunkInterface.h"
|
2019-10-16 04:06:34 -04:00
|
|
|
#include "../Item.h"
|
|
|
|
#include "../BlockEntities/BlockEntityWithItems.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
/** Wrapper for blocks that have a cBlockEntity descendant attached to them and can be "used" by the player.
|
|
|
|
Forwards the "use" event to the block entity. */
|
|
|
|
class cBlockEntityHandler:
|
|
|
|
public cBlockHandler
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cBlockHandler;
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
public:
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
cBlockEntityHandler(BLOCKTYPE a_BlockType):
|
2020-04-13 12:38:06 -04:00
|
|
|
Super(a_BlockType)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
virtual bool OnUse(
|
|
|
|
cChunkInterface & a_ChunkInterface,
|
|
|
|
cWorldInterface & a_WorldInterface,
|
|
|
|
cPlayer & a_Player,
|
|
|
|
const Vector3i a_BlockPos,
|
|
|
|
eBlockFace a_BlockFace,
|
|
|
|
const Vector3i a_CursorPos
|
|
|
|
) override
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
return a_ChunkInterface.UseBlockEntity(&a_Player, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
virtual bool IsUseable() override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
/** Wrapper for blocks that have a cBlockEntityWithItems descendant attached to them.
|
|
|
|
When converting to pickups, drops self with meta reset to zero, and adds the container contents. */
|
|
|
|
template <typename Base = cBlockEntityHandler>
|
|
|
|
class cContainerEntityHandler:
|
|
|
|
public Base
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
cContainerEntityHandler(BLOCKTYPE a_BlockType):
|
|
|
|
Base(a_BlockType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override
|
|
|
|
{
|
|
|
|
// Reset meta to 0
|
|
|
|
cItems res(cItem(Base::m_BlockType, 1, 0));
|
|
|
|
|
|
|
|
// Drop the contents:
|
|
|
|
if (a_BlockEntity != nullptr)
|
|
|
|
{
|
|
|
|
auto container = static_cast<cBlockEntityWithItems *>(a_BlockEntity);
|
|
|
|
res.AddItemGrid(container->GetContents());
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
};
|