PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
UseItemOnEntityTransactionData.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
20use pocketmine\network\mcpe\protocol\types\GetTypeIdFromConstTrait;
21
23 use GetTypeIdFromConstTrait;
24
25 public const ID = InventoryTransactionPacket::TYPE_USE_ITEM_ON_ENTITY;
26
27 public const ACTION_INTERACT = 0;
28 public const ACTION_ATTACK = 1;
29 public const ACTION_ITEM_INTERACT = 2;
30
31 private int $actorRuntimeId;
32 private int $actionType;
33 private int $hotbarSlot;
34 private ItemStackWrapper $itemInHand;
35 private Vector3 $playerPosition;
36 private Vector3 $clickPosition;
37
38 public function getActorRuntimeId() : int{
39 return $this->actorRuntimeId;
40 }
41
42 public function getActionType() : int{
43 return $this->actionType;
44 }
45
46 public function getHotbarSlot() : int{
47 return $this->hotbarSlot;
48 }
49
50 public function getItemInHand() : ItemStackWrapper{
51 return $this->itemInHand;
52 }
53
54 public function getPlayerPosition() : Vector3{
55 return $this->playerPosition;
56 }
57
58 public function getClickPosition() : Vector3{
59 return $this->clickPosition;
60 }
61
62 protected function decodeData(PacketSerializer $stream) : void{
63 $this->actorRuntimeId = $stream->getActorRuntimeId();
64 $this->actionType = $stream->getUnsignedVarInt();
65 $this->hotbarSlot = $stream->getVarInt();
66 $this->itemInHand = $stream->getItemStackWrapper();
67 $this->playerPosition = $stream->getVector3();
68 $this->clickPosition = $stream->getVector3();
69 }
70
71 protected function encodeData(PacketSerializer $stream) : void{
72 $stream->putActorRuntimeId($this->actorRuntimeId);
73 $stream->putUnsignedVarInt($this->actionType);
74 $stream->putVarInt($this->hotbarSlot);
75 $stream->putItemStackWrapper($this->itemInHand);
76 $stream->putVector3($this->playerPosition);
77 $stream->putVector3($this->clickPosition);
78 }
79
83 public static function new(array $actions, int $actorRuntimeId, int $actionType, int $hotbarSlot, ItemStackWrapper $itemInHand, Vector3 $playerPosition, Vector3 $clickPosition) : self{
84 $result = new self;
85 $result->actions = $actions;
86 $result->actorRuntimeId = $actorRuntimeId;
87 $result->actionType = $actionType;
88 $result->hotbarSlot = $hotbarSlot;
89 $result->itemInHand = $itemInHand;
90 $result->playerPosition = $playerPosition;
91 $result->clickPosition = $clickPosition;
92 return $result;
93 }
94}