Cactus cannot be placed on a forbidden blocks (#4767)

Co-authored-by: Franklin T Kong <ftk@umich.edu>
Co-authored-by: aiugai <aiugai@umich.edu>

Fixes #4641

Overrode GetPlacementBlockTypeMeta for CactusBlock, which gets called before a player places the cactus block, so it returns true if the placement is allowed or false if not, in which case the cactus does not drop as a block but stays in the player's hand which is the expected behavior. Tested in Minecraft client 1.12.2.
This commit is contained in:
morsmordere 2020-06-25 20:23:47 -04:00 committed by GitHub
parent e0a361de2a
commit 60c10ef248
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -43,6 +43,7 @@ mBornand
MeMuXin
mgueydan
MikeHunsinger
morsmordere (Anzhelika Iugai)
mtilden
nesco
NiLSPACE (formerly STR_Warrior)

View File

@ -23,6 +23,40 @@ public:
/** Called before a cactus block is placed by a player, overrides cItemHandler::GetPlacementBlockTypeMeta().
Calls CanBeAt function to determine if a cactus block can be placed on a given block. */
bool GetPlacementBlockTypeMeta(
cChunkInterface & a_ChunkInterface,
cPlayer & a_Player,
const Vector3i a_PlacedBlockPos,
eBlockFace a_ClickedBlockFace,
const Vector3i a_CursorPos,
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
) override
{
if (
a_Player.GetWorld()->DoWithChunkAt(a_PlacedBlockPos,
[this, a_PlacedBlockPos, &a_ChunkInterface](cChunk & a_Chunk)
{
auto RelPos = cChunkDef::AbsoluteToRelative(a_PlacedBlockPos);
return CanBeAt(a_ChunkInterface, RelPos, a_Chunk);
}
))
{
a_BlockType = m_BlockType;
// Setting a_BlockMeta to meta copied from the lowest 4 bits of the player's equipped item's damage value.
NIBBLETYPE Meta = static_cast<NIBBLETYPE>(a_Player.GetEquippedItem().m_ItemDamage);
a_BlockMeta = Meta & 0x0f;
return true;
}
return false;
}
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a_RelPos, const cChunk & a_Chunk) override
{
if (a_RelPos.y <= 0)