summaryrefslogtreecommitdiffstats
path: root/src/ClientHandle.cpp
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-06-17 01:18:09 +0200
committerHowaner <franzi.moos@googlemail.com>2014-06-17 01:18:09 +0200
commit1086b8ba05a3ed604423f8222a8a1834324006d2 (patch)
tree0631f21bb3bc32433087ffa3968d428710c85468 /src/ClientHandle.cpp
parentThe motion is already set in AddBasicEntity() (diff)
downloadcuberite-1086b8ba05a3ed604423f8222a8a1834324006d2.tar
cuberite-1086b8ba05a3ed604423f8222a8a1834324006d2.tar.gz
cuberite-1086b8ba05a3ed604423f8222a8a1834324006d2.tar.bz2
cuberite-1086b8ba05a3ed604423f8222a8a1834324006d2.tar.lz
cuberite-1086b8ba05a3ed604423f8222a8a1834324006d2.tar.xz
cuberite-1086b8ba05a3ed604423f8222a8a1834324006d2.tar.zst
cuberite-1086b8ba05a3ed604423f8222a8a1834324006d2.zip
Diffstat (limited to 'src/ClientHandle.cpp')
-rw-r--r--src/ClientHandle.cpp81
1 files changed, 40 insertions, 41 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 9a7d1cd62..06c389d99 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -1089,49 +1089,11 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
);
cWorld * World = m_Player->GetWorld();
- m_NumBlockChangeInteractionsThisTick++;
-
- if (!CheckBlockInteractionsRate())
- {
- Kick("Too many blocks were placed/interacted with per unit time - hacked client?");
- return;
- }
-
- const cItem & Equipped = m_Player->GetInventory().GetEquippedItem();
- if ((Equipped.m_ItemType != a_HeldItem.m_ItemType) && (a_HeldItem.m_ItemType != -1))
- {
- // Only compare ItemType, not meta (torches have different metas)
- // The -1 check is there because sometimes the client sends -1 instead of the held item
- // ( http://forum.mc-server.org/showthread.php?tid=549&pid=4502#pid4502 )
- LOGWARN("Player %s tried to place a block that was not equipped (exp %d, got %d)",
- m_Username.c_str(), Equipped.m_ItemType, a_HeldItem.m_ItemType
- );
-
- // Let's send the current world block to the client, so that it can immediately "let the user know" that they haven't placed the block
- if (a_BlockFace != BLOCK_FACE_NONE)
- {
- AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
- World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
- }
- return;
- }
-
- BLOCKTYPE BlockType;
- NIBBLETYPE BlockMeta;
- World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta);
- cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType);
- cItemHandler * ItemHandler = cItemHandler::GetItemHandler(Equipped.m_ItemType);
if (
- (
- BlockHandler->IsUseable() ||
- (ItemHandler->IsPlaceable() && (a_BlockFace != BLOCK_FACE_NONE))
- ) &&
- (
- (Diff(m_Player->GetPosX(), (double)a_BlockX) > 6) ||
- (Diff(m_Player->GetPosY(), (double)a_BlockY) > 6) ||
- (Diff(m_Player->GetPosZ(), (double)a_BlockZ) > 6)
- )
+ (Diff(m_Player->GetPosX(), (double)a_BlockX) > 6) ||
+ (Diff(m_Player->GetPosY(), (double)a_BlockY) > 6) ||
+ (Diff(m_Player->GetPosZ(), (double)a_BlockZ) > 6)
)
{
if (a_BlockFace != BLOCK_FACE_NONE)
@@ -1149,6 +1111,8 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
{
// A plugin doesn't agree with the action, replace the block on the client and quit:
cChunkInterface ChunkInterface(World->GetChunkMap());
+ BLOCKTYPE BlockType = World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
+ cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType);
BlockHandler->OnCancelRightClick(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
if (a_BlockFace != BLOCK_FACE_NONE)
@@ -1160,6 +1124,39 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
}
return;
}
+
+ m_NumBlockChangeInteractionsThisTick++;
+
+ if (!CheckBlockInteractionsRate())
+ {
+ Kick("Too many blocks were placed/interacted with per unit time - hacked client?");
+ return;
+ }
+
+ const cItem & Equipped = m_Player->GetInventory().GetEquippedItem();
+
+ if ((Equipped.m_ItemType != a_HeldItem.m_ItemType) && (a_HeldItem.m_ItemType != -1))
+ {
+ // Only compare ItemType, not meta (torches have different metas)
+ // The -1 check is there because sometimes the client sends -1 instead of the held item
+ // ( http://forum.mc-server.org/showthread.php?tid=549&pid=4502#pid4502 )
+ LOGWARN("Player %s tried to place a block that was not equipped (exp %d, got %d)",
+ m_Username.c_str(), Equipped.m_ItemType, a_HeldItem.m_ItemType
+ );
+
+ // Let's send the current world block to the client, so that it can immediately "let the user know" that they haven't placed the block
+ if (a_BlockFace != BLOCK_FACE_NONE)
+ {
+ AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
+ World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
+ }
+ return;
+ }
+
+ BLOCKTYPE BlockType;
+ NIBBLETYPE BlockMeta;
+ World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta);
+ cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType);
if (BlockHandler->IsUseable() && !m_Player->IsCrouched())
{
@@ -1174,6 +1171,8 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
return;
}
+ cItemHandler * ItemHandler = cItemHandler::GetItemHandler(Equipped.m_ItemType);
+
if (ItemHandler->IsPlaceable() && (a_BlockFace != BLOCK_FACE_NONE))
{
HandlePlaceBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, *ItemHandler);