PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
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
18
21 public function __construct(
22 private int $actionType,
23 private BlockPosition $blockPosition,
24 private int $face
25 ){
26 if(!self::isValidActionType($actionType)){
27 throw new \InvalidArgumentException("Invalid action type for " . self::class);
28 }
29 }
30
31 public function getActionType() : int{ return $this->actionType; }
32
33 public function getBlockPosition() : BlockPosition{ return $this->blockPosition; }
34
35 public function getFace() : int{ return $this->face; }
36
37 public static function read(PacketSerializer $in, int $actionType) : self{
38 $blockPosition = $in->getSignedBlockPosition();
39 $face = $in->getVarInt();
40 return new self($actionType, $blockPosition, $face);
41 }
42
43 public function write(PacketSerializer $out) : void{
44 $out->putSignedBlockPosition($this->blockPosition);
45 $out->putVarInt($this->face);
46 }
47
48 public static function isValidActionType(int $actionType) : bool{
49 return match($actionType){
50 PlayerAction::ABORT_BREAK,
51 PlayerAction::START_BREAK,
52 PlayerAction::CRACK_BREAK,
53 PlayerAction::PREDICT_DESTROY_BLOCK,
54 PlayerAction::CONTINUE_DESTROY_BLOCK => true,
55 default => false
56 };
57 }
58}