1
0
cuberite-2a/src/Blocks/BlockLadder.h
Tiger Wang a62b2b1be2
Move item placement into item handlers (#5184)
* Move item placement into item handlers

+ Add appropriate CanBeAt checks in cPlayer::PlaceBlocks, into which all placement handlers call.
* Partly addresses #5157
* Fixes #4878
* Fixes #2919
* Fixes #4629
* Fixes #4239
* Fixes #4849

Co-authored-by: changyong guo <guo1487@163.com>
Co-authored-by: Xotheus <shady3300@outlook.com>
Co-authored-by: Krist Pregracke <krist@tiger-scm.com>

* Review fixes

* Update APIDesc.lua

* Rename

Co-authored-by: changyong guo <guo1487@163.com>
Co-authored-by: Xotheus <shady3300@outlook.com>
Co-authored-by: Krist Pregracke <krist@tiger-scm.com>
2021-05-05 13:25:10 +00:00

79 lines
1.6 KiB
C++

#pragma once
#include "BlockHandler.h"
#include "BlockInfo.h"
#include "Mixins.h"
class cBlockLadderHandler final :
public cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x07, 0x02, 0x05, 0x03, 0x04> >
{
using Super = cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x07, 0x02, 0x05, 0x03, 0x04>>;
public:
using Super::Super;
/** Returns true if the ladder will be supported by the block through the given blockface. */
static bool CanBePlacedOn(const BLOCKTYPE a_BlockType, const eBlockFace a_BlockFace)
{
if (
(a_BlockFace == BLOCK_FACE_NONE) ||
(a_BlockFace == BLOCK_FACE_BOTTOM) ||
(a_BlockFace == BLOCK_FACE_TOP)
)
{
return false;
}
return cBlockInfo::IsSolid(a_BlockType);
}
private:
/** Converts the ladder block's meta to the block face of the neighbor to which the ladder is attached. */
static eBlockFace MetaDataToBlockFace(NIBBLETYPE a_MetaData)
{
switch (a_MetaData)
{
case 0x2: return BLOCK_FACE_ZM;
case 0x3: return BLOCK_FACE_ZP;
case 0x4: return BLOCK_FACE_XM;
case 0x5: return BLOCK_FACE_XP;
default: return BLOCK_FACE_ZM;
}
}
virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override
{
auto Face = MetaDataToBlockFace(a_Meta);
auto NeighborRelPos = AddFaceDirection(a_Position, Face, true);
BLOCKTYPE NeighborBlockType;
a_Chunk.UnboundedRelGetBlockType(NeighborRelPos, NeighborBlockType);
return CanBePlacedOn(NeighborBlockType, Face);
}
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
{
UNUSED(a_Meta);
return 0;
}
} ;