mirror of
https://github.com/cuberite/cuberite.git
synced 2025-01-08 11:57:39 +08:00
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:
parent
e0a361de2a
commit
60c10ef248
@ -43,6 +43,7 @@ mBornand
|
||||
MeMuXin
|
||||
mgueydan
|
||||
MikeHunsinger
|
||||
morsmordere (Anzhelika Iugai)
|
||||
mtilden
|
||||
nesco
|
||||
NiLSPACE (formerly STR_Warrior)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user