PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
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
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
24use pocketmine\network\mcpe\protocol\types\GetTypeIdFromConstTrait;
25
27 use GetTypeIdFromConstTrait;
28
29 public const ID = InventoryTransactionPacket::TYPE_USE_ITEM;
30
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;
35
36 private int $actionType;
37 private TriggerType $triggerType;
38 private BlockPosition $blockPosition;
39 private int $face;
40 private int $hotbarSlot;
41 private ItemStackWrapper $itemInHand;
42 private Vector3 $playerPosition;
43 private Vector3 $clickPosition;
44 private int $blockRuntimeId;
45 private PredictedResult $clientInteractPrediction;
46
47 public function getActionType() : int{
48 return $this->actionType;
49 }
50
51 public function getTriggerType() : TriggerType{ return $this->triggerType; }
52
53 public function getBlockPosition() : BlockPosition{
54 return $this->blockPosition;
55 }
56
57 public function getFace() : int{
58 return $this->face;
59 }
60
61 public function getHotbarSlot() : int{
62 return $this->hotbarSlot;
63 }
64
65 public function getItemInHand() : ItemStackWrapper{
66 return $this->itemInHand;
67 }
68
69 public function getPlayerPosition() : Vector3{
70 return $this->playerPosition;
71 }
72
73 public function getClickPosition() : Vector3{
74 return $this->clickPosition;
75 }
76
77 public function getBlockRuntimeId() : int{
78 return $this->blockRuntimeId;
79 }
80
81 public function getClientInteractPrediction() : PredictedResult{ return $this->clientInteractPrediction; }
82
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));
94 }
95
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);
107 }
108
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{
113 $result = new 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;
125 return $result;
126 }
127}