PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
CompletedUsingItemPacket.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;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
20
22 public const NETWORK_ID = ProtocolInfo::COMPLETED_USING_ITEM_PACKET;
23
24 public const ACTION_UNKNOWN = -1;
25 public const ACTION_EQUIP_ARMOR = 0;
26 public const ACTION_EAT = 1;
27 public const ACTION_ATTACK = 2;
28 public const ACTION_CONSUME = 3;
29 public const ACTION_THROW = 4;
30 public const ACTION_SHOOT = 5;
31 public const ACTION_PLACE = 6;
32 public const ACTION_FILL_BOTTLE = 7;
33 public const ACTION_FILL_BUCKET = 8;
34 public const ACTION_POUR_BUCKET = 9;
35 public const ACTION_USE_TOOL = 10;
36 public const ACTION_INTERACT = 11;
37 public const ACTION_RETRIEVED = 12;
38 public const ACTION_DYED = 13;
39 public const ACTION_TRADED = 14;
40 public const ACTION_BRUSHING_COMPLETED = 15;
41
42 public int $itemId;
43 public int $action;
44
48 public static function create(int $itemId, int $action) : self{
49 $result = new self;
50 $result->itemId = $itemId;
51 $result->action = $action;
52 return $result;
53 }
54
55 public function decodePayload(ByteBufferReader $in) : void{
56 $this->itemId = LE::readSignedShort($in);
57 $this->action = LE::readSignedInt($in);
58 }
59
60 public function encodePayload(ByteBufferWriter $out) : void{
61 LE::writeSignedShort($out, $this->itemId);
62 LE::writeSignedInt($out, $this->action);
63 }
64
65 public function handle(PacketHandlerInterface $handler) : bool{
66 return $handler->handleCompletedUsingItem($this);
67 }
68}