PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
PlayerToggleCrafterSlotRequestPacket.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\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\LE;
23
25 public const NETWORK_ID = ProtocolInfo::PLAYER_TOGGLE_CRAFTER_SLOT_REQUEST_PACKET;
26
27 private BlockPosition $position;
28 private int $slot;
29 private bool $disabled;
30
34 public static function create(BlockPosition $position, int $slot, bool $disabled) : self{
35 $result = new self;
36 $result->position = $position;
37 $result->slot = $slot;
38 $result->disabled = $disabled;
39 return $result;
40 }
41
42 public function getPosition() : BlockPosition{ return $this->position; }
43
44 public function getSlot() : int{ return $this->slot; }
45
46 public function isDisabled() : bool{ return $this->disabled; }
47
48 protected function decodePayload(ByteBufferReader $in) : void{
49 $x = LE::readSignedInt($in);
50 $y = LE::readSignedInt($in);
51 $z = LE::readSignedInt($in);
52 $this->position = new BlockPosition($x, $y, $z);
53 $this->slot = Byte::readUnsigned($in);
54 $this->disabled = CommonTypes::getBool($in);
55 }
56
57 protected function encodePayload(ByteBufferWriter $out) : void{
58 LE::writeSignedInt($out, $this->position->getX());
59 LE::writeSignedInt($out, $this->position->getY());
60 LE::writeSignedInt($out, $this->position->getZ());
61 Byte::writeUnsigned($out, $this->slot);
62 CommonTypes::putBool($out, $this->disabled);
63 }
64
65 public function handle(PacketHandlerInterface $handler) : bool{
66 return $handler->handlePlayerToggleCrafterSlotRequest($this);
67 }
68}