28 use GetTypeIdFromConstTrait;
30 public const ID = InventoryTransactionPacket::TYPE_USE_ITEM;
32 public const ACTION_CLICK_BLOCK = 0;
33 public const ACTION_CLICK_AIR = 1;
34 public const ACTION_BREAK_BLOCK = 2;
35 public const ACTION_USE_AS_ATTACK = 3;
37 private int $actionType;
38 private TriggerType $triggerType;
41 private int $hotbarSlot;
43 private Vector3 $playerPosition;
45 private int $blockRuntimeId;
46 private PredictedResult $clientInteractPrediction;
47 private int $clientCooldownState;
49 public function getActionType() :
int{
50 return $this->actionType;
53 public function getTriggerType() : TriggerType{
return $this->triggerType; }
56 return $this->blockPosition;
59 public function getFace() :
int{
63 public function getHotbarSlot() :
int{
64 return $this->hotbarSlot;
68 return $this->itemInHand;
71 public function getPlayerPosition() :
Vector3{
72 return $this->playerPosition;
75 public function getClickPosition() :
Vector3{
76 return $this->clickPosition;
79 public function getBlockRuntimeId() :
int{
80 return $this->blockRuntimeId;
83 public function getClientInteractPrediction() : PredictedResult{
return $this->clientInteractPrediction; }
85 public function getClientCooldownState() :
int{
return $this->clientCooldownState; }
87 protected function decodeData(ByteBufferReader $in) : void{
88 $this->actionType = VarInt::readUnsignedInt($in);
89 $this->triggerType = TriggerType::fromPacket(VarInt::readUnsignedInt($in));
90 $this->blockPosition = CommonTypes::getBlockPosition($in);
91 $this->face = VarInt::readSignedInt($in);
92 $this->hotbarSlot = VarInt::readSignedInt($in);
93 $this->itemInHand = CommonTypes::getItemStackWrapper($in);
94 $this->playerPosition = CommonTypes::getVector3($in);
95 $this->clickPosition = CommonTypes::getVector3($in);
96 $this->blockRuntimeId = VarInt::readUnsignedInt($in);
97 $this->clientInteractPrediction = PredictedResult::fromPacket(VarInt::readUnsignedInt($in));
98 $this->clientCooldownState = Byte::readUnsigned($in);
101 protected function encodeData(ByteBufferWriter $out) : void{
102 VarInt::writeUnsignedInt($out, $this->actionType);
103 VarInt::writeUnsignedInt($out, $this->triggerType->value);
104 CommonTypes::putBlockPosition($out, $this->blockPosition);
105 VarInt::writeSignedInt($out, $this->face);
106 VarInt::writeSignedInt($out, $this->hotbarSlot);
107 CommonTypes::putItemStackWrapper($out, $this->itemInHand);
108 CommonTypes::putVector3($out, $this->playerPosition);
109 CommonTypes::putVector3($out, $this->clickPosition);
110 VarInt::writeUnsignedInt($out, $this->blockRuntimeId);
111 VarInt::writeUnsignedInt($out, $this->clientInteractPrediction->value);
112 Byte::writeUnsigned($out, $this->clientCooldownState);
118 private static function initSelf(
120 TriggerType $triggerType,
128 PredictedResult $clientInteractPrediction,
129 int $clientCooldownState,
132 $result->actionType = $actionType;
133 $result->triggerType = $triggerType;
134 $result->blockPosition = $blockPosition;
135 $result->face = $face;
136 $result->hotbarSlot = $hotbarSlot;
137 $result->itemInHand = $itemInHand;
138 $result->playerPosition = $playerPosition;
139 $result->clickPosition = $clickPosition;
140 $result->blockRuntimeId = $blockRuntimeId;
141 $result->clientInteractPrediction = $clientInteractPrediction;
142 $result->clientCooldownState = $clientCooldownState;
149 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,
int $clientCooldownState) : self{
150 $result = self::initSelf($actionType, $triggerType, $blockPosition, $face, $hotbarSlot, $itemInHand, $playerPosition, $clickPosition, $blockRuntimeId, $clientInteractPrediction, $clientCooldownState);
151 $result->actions = $actions;