Rewrite cClientHandle::HandleRightClick (#4089)
* Add hand parameter to distinguish main hand/off hand. * Add a new function cClientHandle::HandleUseItem to separate the functionality of using an item without a target block. This matches the protocol with client version >= 1.9 * Always actively update the status of a block if the placement fails (by out of reach or rejected by plugin). * Do not call plugin callback CallHookPlayerRightClick(-1, 255, -1, -1, 0, 0, 0) when using item. The CallHookPlayerUsingItem will still be called. Now at most one of CallHookPlayerRightClick, CallHookPlayerUsingBlock, CallHookPlayerUsingItem and CallHookPlayerEating will be called based on the type of action (not including the used version of callbacks). * Do not count using item as BlockInteractionsRate check (Using item takes time). * Now we can open chests(etc.) when sneaking as long as the player's hand is empty. This is what vanilla server does.
This commit is contained in:
@@ -66,6 +66,7 @@ static const Int16 SLOT_NUM_OUTSIDE = -999;
|
||||
|
||||
/** Value for main hand in Hand parameter for Protocol 1.9. */
|
||||
static const UInt32 MAIN_HAND = 0;
|
||||
static const UInt32 OFF_HAND = 1;
|
||||
|
||||
|
||||
|
||||
@@ -2384,7 +2385,7 @@ void cProtocol_1_9_0::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer)
|
||||
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorX);
|
||||
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorY);
|
||||
HANDLE_READ(a_ByteBuffer, ReadBEUInt8, UInt8, CursorZ);
|
||||
m_Client->HandleRightClick(BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), CursorX, CursorY, CursorZ, m_Client->GetPlayer()->GetEquippedItem());
|
||||
m_Client->HandleRightClick(BlockX, BlockY, BlockZ, FaceIntToBlockFace(Face), CursorX, CursorY, CursorZ, HandIntToEnum(Hand));
|
||||
}
|
||||
|
||||
|
||||
@@ -2784,10 +2785,9 @@ void cProtocol_1_9_0::HandlePacketUseEntity(cByteBuffer & a_ByteBuffer)
|
||||
|
||||
void cProtocol_1_9_0::HandlePacketUseItem(cByteBuffer & a_ByteBuffer)
|
||||
{
|
||||
HANDLE_READ(a_ByteBuffer, ReadVarInt, UInt64, Hand);
|
||||
HANDLE_READ(a_ByteBuffer, ReadVarInt, Int32, Hand);
|
||||
|
||||
// Didn't click a block - emulate old values used with place block of -1, -1, -1 (and BLOCK_FACE_NONE).
|
||||
m_Client->HandleRightClick(-1, 255, -1, BLOCK_FACE_NONE, 0, 0, 0, m_Client->GetPlayer()->GetEquippedItem());
|
||||
m_Client->HandleUseItem(HandIntToEnum(Hand));
|
||||
}
|
||||
|
||||
|
||||
@@ -3267,6 +3267,25 @@ eBlockFace cProtocol_1_9_0::FaceIntToBlockFace(Int32 a_BlockFace)
|
||||
|
||||
|
||||
|
||||
eHand cProtocol_1_9_0::HandIntToEnum(Int32 a_Hand)
|
||||
{
|
||||
// Convert hand parameter into eHand enum
|
||||
switch (a_Hand)
|
||||
{
|
||||
case MAIN_HAND: return eHand::hMain;
|
||||
case OFF_HAND: return eHand::hOff;
|
||||
default:
|
||||
{
|
||||
ASSERT(!"Unknown hand value");
|
||||
return eHand::hMain;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// cProtocol_1_9_0::cPacketizer:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user