PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
PlayerBlockActionWithBlockInfo.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;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
21
24 public function __construct(
25 private int $actionType,
26 private BlockPosition $blockPosition,
27 private int $face
28 ){
29 if(!self::isValidActionType($actionType)){
30 throw new \InvalidArgumentException("Invalid action type for " . self::class);
31 }
32 }
33
34 public function getActionType() : int{ return $this->actionType; }
35
36 public function getBlockPosition() : BlockPosition{ return $this->blockPosition; }
37
38 public function getFace() : int{ return $this->face; }
39
40 public static function read(ByteBufferReader $in, int $actionType) : self{
41 $blockPosition = CommonTypes::getSignedBlockPosition($in);
42 $face = VarInt::readSignedInt($in);
43 return new self($actionType, $blockPosition, $face);
44 }
45
46 public function write(ByteBufferWriter $out) : void{
47 CommonTypes::putSignedBlockPosition($out, $this->blockPosition);
48 VarInt::writeSignedInt($out, $this->face);
49 }
50
51 public static function isValidActionType(int $actionType) : bool{
52 return match($actionType){
53 PlayerAction::ABORT_BREAK,
54 PlayerAction::START_BREAK,
55 PlayerAction::CRACK_BREAK,
56 PlayerAction::PREDICT_DESTROY_BLOCK,
57 PlayerAction::CONTINUE_DESTROY_BLOCK => true,
58 default => false
59 };
60 }
61}