PocketMine-MP 5.21.2 git-b2aa6396c3cc2cafdd815eacc360e1ad89599899
Loading...
Searching...
No Matches
ReleaseItemTransactionData.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_RELEASE_ITEM;
26
27 public const ACTION_RELEASE = 0; //bow shoot
28 public const ACTION_CONSUME = 1; //eat food, drink potion
29
30 private int $actionType;
31 private int $hotbarSlot;
32 private ItemStackWrapper $itemInHand;
33 private Vector3 $headPosition;
34
35 public function getActionType() : int{
36 return $this->actionType;
37 }
38
39 public function getHotbarSlot() : int{
40 return $this->hotbarSlot;
41 }
42
43 public function getItemInHand() : ItemStackWrapper{
44 return $this->itemInHand;
45 }
46
47 public function getHeadPosition() : Vector3{
48 return $this->headPosition;
49 }
50
51 protected function decodeData(PacketSerializer $stream) : void{
52 $this->actionType = $stream->getUnsignedVarInt();
53 $this->hotbarSlot = $stream->getVarInt();
54 $this->itemInHand = $stream->getItemStackWrapper();
55 $this->headPosition = $stream->getVector3();
56 }
57
58 protected function encodeData(PacketSerializer $stream) : void{
59 $stream->putUnsignedVarInt($this->actionType);
60 $stream->putVarInt($this->hotbarSlot);
61 $stream->putItemStackWrapper($this->itemInHand);
62 $stream->putVector3($this->headPosition);
63 }
64
68 public static function new(array $actions, int $actionType, int $hotbarSlot, ItemStackWrapper $itemInHand, Vector3 $headPosition) : self{
69 $result = new self;
70 $result->actions = $actions;
71 $result->actionType = $actionType;
72 $result->hotbarSlot = $hotbarSlot;
73 $result->itemInHand = $itemInHand;
74 $result->headPosition = $headPosition;
75
76 return $result;
77 }
78}