27 use GetTypeIdFromConstTrait;
29 public const ID = InventoryTransactionPacket::TYPE_USE_ITEM;
31 public const ACTION_CLICK_BLOCK = 0;
32 public const ACTION_CLICK_AIR = 1;
33 public const ACTION_BREAK_BLOCK = 2;
34 public const ACTION_USE_AS_ATTACK = 3;
36 private int $actionType;
37 private TriggerType $triggerType;
40 private int $hotbarSlot;
42 private Vector3 $playerPosition;
44 private int $blockRuntimeId;
45 private PredictedResult $clientInteractPrediction;
47 public function getActionType() :
int{
48 return $this->actionType;
51 public function getTriggerType() : TriggerType{
return $this->triggerType; }
54 return $this->blockPosition;
57 public function getFace() :
int{
61 public function getHotbarSlot() :
int{
62 return $this->hotbarSlot;
66 return $this->itemInHand;
69 public function getPlayerPosition() :
Vector3{
70 return $this->playerPosition;
73 public function getClickPosition() :
Vector3{
74 return $this->clickPosition;
77 public function getBlockRuntimeId() :
int{
78 return $this->blockRuntimeId;
81 public function getClientInteractPrediction() : PredictedResult{
return $this->clientInteractPrediction; }
83 protected function decodeData(ByteBufferReader $in) : void{
84 $this->actionType = VarInt::readUnsignedInt($in);
85 $this->triggerType = TriggerType::fromPacket(VarInt::readUnsignedInt($in));
86 $this->blockPosition = CommonTypes::getBlockPosition($in);
87 $this->face = VarInt::readSignedInt($in);
88 $this->hotbarSlot = VarInt::readSignedInt($in);
89 $this->itemInHand = CommonTypes::getItemStackWrapper($in);
90 $this->playerPosition = CommonTypes::getVector3($in);
91 $this->clickPosition = CommonTypes::getVector3($in);
92 $this->blockRuntimeId = VarInt::readUnsignedInt($in);
93 $this->clientInteractPrediction = PredictedResult::fromPacket(VarInt::readUnsignedInt($in));
96 protected function encodeData(ByteBufferWriter $out) : void{
97 VarInt::writeUnsignedInt($out, $this->actionType);
98 VarInt::writeUnsignedInt($out, $this->triggerType->value);
99 CommonTypes::putBlockPosition($out, $this->blockPosition);
100 VarInt::writeSignedInt($out, $this->face);
101 VarInt::writeSignedInt($out, $this->hotbarSlot);
102 CommonTypes::putItemStackWrapper($out, $this->itemInHand);
103 CommonTypes::putVector3($out, $this->playerPosition);
104 CommonTypes::putVector3($out, $this->clickPosition);
105 VarInt::writeUnsignedInt($out, $this->blockRuntimeId);
106 VarInt::writeUnsignedInt($out, $this->clientInteractPrediction->value);
112 public static function new(array $actions,
int $actionType, TriggerType $triggerType,
BlockPosition $blockPosition,
int $face,
int $hotbarSlot,
ItemStackWrapper $itemInHand,
Vector3 $playerPosition,
Vector3 $clickPosition,
int $blockRuntimeId, PredictedResult $clientInteractPrediction) : self{
114 $result->actions = $actions;
115 $result->actionType = $actionType;
116 $result->triggerType = $triggerType;
117 $result->blockPosition = $blockPosition;
118 $result->face = $face;
119 $result->hotbarSlot = $hotbarSlot;
120 $result->itemInHand = $itemInHand;
121 $result->playerPosition = $playerPosition;
122 $result->clickPosition = $clickPosition;
123 $result->blockRuntimeId = $blockRuntimeId;
124 $result->clientInteractPrediction = $clientInteractPrediction;