PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
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
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_RELEASE_ITEM;
29
30 public const ACTION_RELEASE = 0; //bow shoot
31 public const ACTION_CONSUME = 1; //eat food, drink potion
32
33 private int $actionType;
34 private int $hotbarSlot;
35 private ItemStackWrapper $itemInHand;
36 private Vector3 $headPosition;
37
38 public function getActionType() : int{
39 return $this->actionType;
40 }
41
42 public function getHotbarSlot() : int{
43 return $this->hotbarSlot;
44 }
45
46 public function getItemInHand() : ItemStackWrapper{
47 return $this->itemInHand;
48 }
49
50 public function getHeadPosition() : Vector3{
51 return $this->headPosition;
52 }
53
54 protected function decodeData(ByteBufferReader $in) : void{
55 $this->actionType = VarInt::readUnsignedInt($in);
56 $this->hotbarSlot = VarInt::readSignedInt($in);
57 $this->itemInHand = CommonTypes::getItemStackWrapper($in);
58 $this->headPosition = CommonTypes::getVector3($in);
59 }
60
61 protected function encodeData(ByteBufferWriter $out) : void{
62 VarInt::writeUnsignedInt($out, $this->actionType);
63 VarInt::writeSignedInt($out, $this->hotbarSlot);
64 CommonTypes::putItemStackWrapper($out, $this->itemInHand);
65 CommonTypes::putVector3($out, $this->headPosition);
66 }
67
71 public static function new(array $actions, int $actionType, int $hotbarSlot, ItemStackWrapper $itemInHand, Vector3 $headPosition) : self{
72 $result = new self;
73 $result->actions = $actions;
74 $result->actionType = $actionType;
75 $result->hotbarSlot = $hotbarSlot;
76 $result->itemInHand = $itemInHand;
77 $result->headPosition = $headPosition;
78
79 return $result;
80 }
81}