summaryrefslogtreecommitdiffstats
path: root/src/Items/ItemSign.h
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2021-05-05 15:25:10 +0200
committerGitHub <noreply@github.com>2021-05-05 15:25:10 +0200
commita62b2b1be2103d7de2fd66c7304b7473e369be3c (patch)
treea44f2b43fd90f5c79af5e308b554349e6dc546af /src/Items/ItemSign.h
parentRename files to match code (diff)
downloadcuberite-a62b2b1be2103d7de2fd66c7304b7473e369be3c.tar
cuberite-a62b2b1be2103d7de2fd66c7304b7473e369be3c.tar.gz
cuberite-a62b2b1be2103d7de2fd66c7304b7473e369be3c.tar.bz2
cuberite-a62b2b1be2103d7de2fd66c7304b7473e369be3c.tar.lz
cuberite-a62b2b1be2103d7de2fd66c7304b7473e369be3c.tar.xz
cuberite-a62b2b1be2103d7de2fd66c7304b7473e369be3c.tar.zst
cuberite-a62b2b1be2103d7de2fd66c7304b7473e369be3c.zip
Diffstat (limited to '')
-rw-r--r--src/Items/ItemSign.h89
1 files changed, 39 insertions, 50 deletions
diff --git a/src/Items/ItemSign.h b/src/Items/ItemSign.h
index 64d162f8d..fc5174e0b 100644
--- a/src/Items/ItemSign.h
+++ b/src/Items/ItemSign.h
@@ -3,8 +3,6 @@
#include "ItemHandler.h"
#include "../World.h"
-#include "../Blocks/BlockSignPost.h"
-#include "../Blocks/BlockWallSign.h"
#include "../ClientHandle.h"
@@ -18,77 +16,68 @@ class cItemSignHandler:
public:
- cItemSignHandler(int a_ItemType):
- Super(a_ItemType)
- {
- }
-
+ using Super::Super;
+private:
+ /** Converts the block face of the neighbor to which the wallsign is attached to the wallsign block's meta. */
+ static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_NeighborBlockFace)
+ {
+ switch (a_NeighborBlockFace)
+ {
+ case BLOCK_FACE_ZM: return 0x02;
+ case BLOCK_FACE_ZP: return 0x03;
+ case BLOCK_FACE_XM: return 0x04;
+ case BLOCK_FACE_XP: return 0x05;
+ case BLOCK_FACE_NONE:
+ case BLOCK_FACE_YP:
+ case BLOCK_FACE_YM:
+ {
+ break;
+ }
+ }
+ return 0x02;
+ }
- virtual bool OnPlayerPlace(
- cWorld & a_World,
- cPlayer & a_Player,
- const cItem & a_EquippedItem,
- const Vector3i a_ClickedBlockPos,
- eBlockFace a_ClickedBlockFace,
- const Vector3i a_CursorPos
- ) override
+ virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
{
- // Check if placing on something ignoring build collision to edit the correct sign later on:
- BLOCKTYPE ClickedBlockType;
- NIBBLETYPE ClickedBlockMeta;
- a_World.GetBlockTypeMeta(a_ClickedBlockPos, ClickedBlockType, ClickedBlockMeta);
- cChunkInterface ChunkInterface(a_World.GetChunkMap());
- bool IsReplacingClickedBlock = cBlockHandler::For(ClickedBlockType).DoesIgnoreBuildCollision(ChunkInterface, a_ClickedBlockPos, a_Player, ClickedBlockMeta);
-
- // If the regular placement doesn't work, do no further processing:
- if (!Super::OnPlayerPlace(a_World, a_Player, a_EquippedItem, a_ClickedBlockPos, a_ClickedBlockFace, a_CursorPos))
+ if (a_ClickedBlockFace == BLOCK_FACE_TOP)
+ {
+ if (!a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_SIGN_POST, RotationToMetaData(a_Player.GetYaw())))
+ {
+ return false;
+ }
+ }
+ else if (!a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_WALLSIGN, BlockFaceToMetaData(a_ClickedBlockFace)))
{
return false;
}
- // Use IsReplacingClickedBlock to make sure we will edit the right sign:
- auto SignPos = IsReplacingClickedBlock ? a_ClickedBlockPos : AddFaceDirection(a_ClickedBlockPos, a_ClickedBlockFace);
-
// After successfully placing the sign, open the sign editor for the player:
- a_Player.GetClientHandle()->SendEditSign(SignPos.x, SignPos.y, SignPos.z);
+ a_Player.GetClientHandle()->SendEditSign(a_PlacePosition.x, a_PlacePosition.y, a_PlacePosition.z);
return true;
}
-
-
-
virtual bool IsPlaceable(void) override
{
return true;
}
-
-
-
- virtual bool GetPlacementBlockTypeMeta(
- cWorld * a_World, cPlayer * a_Player,
- const Vector3i a_PlacedBlockPos,
- eBlockFace a_ClickedBlockFace,
- const Vector3i a_CursorPos,
- BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
- ) override
+ /** Converts the (player) rotation to placed-signpost block meta. */
+ static NIBBLETYPE RotationToMetaData(double a_Rotation)
{
- if (a_ClickedBlockFace == BLOCK_FACE_TOP)
+ a_Rotation += 180 + (180.f / 16); // So it's not aligned with axis.
+ if (a_Rotation > 360)
{
- a_BlockMeta = cBlockSignPostHandler::RotationToMetaData(a_Player->GetYaw());
- a_BlockType = E_BLOCK_SIGN_POST;
+ a_Rotation -= 360;
}
- else
- {
- a_BlockMeta = cBlockWallSignHandler::BlockFaceToMetaData(a_ClickedBlockFace);
- a_BlockType = E_BLOCK_WALLSIGN;
- }
- return true;
+
+ a_Rotation = (a_Rotation / 360) * 16;
+
+ return static_cast<char>(a_Rotation) % 16;
}
} ;