PocketMine-MP 5.19.1 git-5cc1068cd43264d3363295eb8d6901e02f467897
UseItemTransactionData.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol\types\inventory;
16
21use pocketmine\network\mcpe\protocol\types\GetTypeIdFromConstTrait;
22
24 use GetTypeIdFromConstTrait;
25
26 public const ID = InventoryTransactionPacket::TYPE_USE_ITEM;
27
28 public const ACTION_CLICK_BLOCK = 0;
29 public const ACTION_CLICK_AIR = 1;
30 public const ACTION_BREAK_BLOCK = 2;
31
32 private int $actionType;
33 private TriggerType $triggerType;
34 private BlockPosition $blockPosition;
35 private int $face;
36 private int $hotbarSlot;
37 private ItemStackWrapper $itemInHand;
38 private Vector3 $playerPosition;
39 private Vector3 $clickPosition;
40 private int $blockRuntimeId;
41 private PredictedResult $clientInteractPrediction;
42
43 public function getActionType() : int{
44 return $this->actionType;
45 }
46
47 public function getTriggerType() : TriggerType{ return $this->triggerType; }
48
49 public function getBlockPosition() : BlockPosition{
50 return $this->blockPosition;
51 }
52
53 public function getFace() : int{
54 return $this->face;
55 }
56
57 public function getHotbarSlot() : int{
58 return $this->hotbarSlot;
59 }
60
61 public function getItemInHand() : ItemStackWrapper{
62 return $this->itemInHand;
63 }
64
65 public function getPlayerPosition() : Vector3{
66 return $this->playerPosition;
67 }
68
69 public function getClickPosition() : Vector3{
70 return $this->clickPosition;
71 }
72
73 public function getBlockRuntimeId() : int{
74 return $this->blockRuntimeId;
75 }
76
77 public function getClientInteractPrediction() : PredictedResult{ return $this->clientInteractPrediction; }
78
79 protected function decodeData(PacketSerializer $stream) : void{
80 $this->actionType = $stream->getUnsignedVarInt();
81 $this->triggerType = TriggerType::fromPacket($stream->getUnsignedVarInt());
82 $this->blockPosition = $stream->getBlockPosition();
83 $this->face = $stream->getVarInt();
84 $this->hotbarSlot = $stream->getVarInt();
85 $this->itemInHand = $stream->getItemStackWrapper();
86 $this->playerPosition = $stream->getVector3();
87 $this->clickPosition = $stream->getVector3();
88 $this->blockRuntimeId = $stream->getUnsignedVarInt();
89 $this->clientInteractPrediction = PredictedResult::fromPacket($stream->getUnsignedVarInt());
90 }
91
92 protected function encodeData(PacketSerializer $stream) : void{
93 $stream->putUnsignedVarInt($this->actionType);
94 $stream->putUnsignedVarInt($this->triggerType->value);
95 $stream->putBlockPosition($this->blockPosition);
96 $stream->putVarInt($this->face);
97 $stream->putVarInt($this->hotbarSlot);
98 $stream->putItemStackWrapper($this->itemInHand);
99 $stream->putVector3($this->playerPosition);
100 $stream->putVector3($this->clickPosition);
101 $stream->putUnsignedVarInt($this->blockRuntimeId);
102 $stream->putUnsignedVarInt($this->clientInteractPrediction->value);
103 }
104
108 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{
109 $result = new self;
110 $result->actions = $actions;
111 $result->actionType = $actionType;
112 $result->triggerType = $triggerType;
113 $result->blockPosition = $blockPosition;
114 $result->face = $face;
115 $result->hotbarSlot = $hotbarSlot;
116 $result->itemInHand = $itemInHand;
117 $result->playerPosition = $playerPosition;
118 $result->clickPosition = $clickPosition;
119 $result->blockRuntimeId = $blockRuntimeId;
120 $result->clientInteractPrediction = $clientInteractPrediction;
121 return $result;
122 }
123}