PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
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
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
23use pocketmine\network\mcpe\protocol\types\GetTypeIdFromConstTrait;
24
26 use GetTypeIdFromConstTrait;
27
28 public const ID = InventoryTransactionPacket::TYPE_USE_ITEM_ON_ENTITY;
29
30 public const ACTION_INTERACT = 0;
31 public const ACTION_ATTACK = 1;
32 public const ACTION_ITEM_INTERACT = 2;
33
34 private int $actorRuntimeId;
35 private int $actionType;
36 private int $hotbarSlot;
37 private ItemStackWrapper $itemInHand;
38 private Vector3 $playerPosition;
39 private Vector3 $clickPosition;
40
41 public function getActorRuntimeId() : int{
42 return $this->actorRuntimeId;
43 }
44
45 public function getActionType() : int{
46 return $this->actionType;
47 }
48
49 public function getHotbarSlot() : int{
50 return $this->hotbarSlot;
51 }
52
53 public function getItemInHand() : ItemStackWrapper{
54 return $this->itemInHand;
55 }
56
57 public function getPlayerPosition() : Vector3{
58 return $this->playerPosition;
59 }
60
61 public function getClickPosition() : Vector3{
62 return $this->clickPosition;
63 }
64
65 protected function decodeData(ByteBufferReader $in) : void{
66 $this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
67 $this->actionType = VarInt::readUnsignedInt($in);
68 $this->hotbarSlot = VarInt::readSignedInt($in);
69 $this->itemInHand = CommonTypes::getItemStackWrapper($in);
70 $this->playerPosition = CommonTypes::getVector3($in);
71 $this->clickPosition = CommonTypes::getVector3($in);
72 }
73
74 protected function encodeData(ByteBufferWriter $out) : void{
75 CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
76 VarInt::writeUnsignedInt($out, $this->actionType);
77 VarInt::writeSignedInt($out, $this->hotbarSlot);
78 CommonTypes::putItemStackWrapper($out, $this->itemInHand);
79 CommonTypes::putVector3($out, $this->playerPosition);
80 CommonTypes::putVector3($out, $this->clickPosition);
81 }
82
86 public static function new(array $actions, int $actorRuntimeId, int $actionType, int $hotbarSlot, ItemStackWrapper $itemInHand, Vector3 $playerPosition, Vector3 $clickPosition) : self{
87 $result = new self;
88 $result->actions = $actions;
89 $result->actorRuntimeId = $actorRuntimeId;
90 $result->actionType = $actionType;
91 $result->hotbarSlot = $hotbarSlot;
92 $result->itemInHand = $itemInHand;
93 $result->playerPosition = $playerPosition;
94 $result->clickPosition = $clickPosition;
95 return $result;
96 }
97}