| 917 | |
| 918 | |
| 919 | void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, const cItem & a_HeldItem) |
| 920 | { |
| 921 | LOGD("HandleRightClick: {%d, %d, %d}, face %d, HeldItem: %s", |
| 922 | a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, ItemToFullString(a_HeldItem).c_str() |
| 923 | ); |
| 924 | |
| 925 | cWorld * World = m_Player->GetWorld(); |
| 926 | |
| 927 | cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager(); |
| 928 | if (PlgMgr->CallHookPlayerRightClick(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ)) |
| 929 | { |
| 930 | // A plugin doesn't agree with the action, replace the block on the client and quit: |
| 931 | cChunkInterface ChunkInterface(World->GetChunkMap()); |
| 932 | BLOCKTYPE BlockType = World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); |
| 933 | cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType); |
| 934 | BlockHandler->OnCancelRightClick(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); |
| 935 | |
| 936 | if (a_BlockFace != BLOCK_FACE_NONE) |
| 937 | { |
| 938 | AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); |
| 939 | World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); |
| 940 | World->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, m_Player); //2 block high things |
| 941 | } |
| 942 | return; |
| 943 | } |
| 944 | |
| 945 | m_NumBlockChangeInteractionsThisTick++; |
| 946 | |
| 947 | if (!CheckBlockInteractionsRate()) |
| 948 | { |
| 949 | Kick("Too many blocks were placed/interacted with per unit time - hacked client?"); |
| 950 | return; |
| 951 | } |
| 952 | |
| 953 | const cItem & Equipped = m_Player->GetInventory().GetEquippedItem(); |
| 954 | |
| 955 | if ((Equipped.m_ItemType != a_HeldItem.m_ItemType) && (a_HeldItem.m_ItemType != -1)) |
| 956 | { |
| 957 | // Only compare ItemType, not meta (torches have different metas) |
| 958 | // The -1 check is there because sometimes the client sends -1 instead of the held item |
| 959 | // ( http://forum.mc-server.org/showthread.php?tid=549&pid=4502#pid4502 ) |
| 960 | LOGWARN("Player %s tried to place a block that was not equipped (exp %d, got %d)", |
| 961 | m_Username.c_str(), Equipped.m_ItemType, a_HeldItem.m_ItemType |
| 962 | ); |
| 963 | |
| 964 | // 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 |
| 965 | if (a_BlockFace != BLOCK_FACE_NONE) |
| 966 | { |
| 967 | AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); |
| 968 | World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); |
| 969 | } |
| 970 | return; |
| 971 | } |
| 972 | |
| 973 | BLOCKTYPE BlockType; |
| 974 | NIBBLETYPE BlockMeta; |
| 975 | World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta); |
| 976 | cBlockHandler * BlockHandler = cBlockInfo::GetHandler(BlockType); |
no test coverage detected