PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
SubChunkPositionOffset.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
20
22
23 public function __construct(
24 private int $xOffset,
25 private int $yOffset,
26 private int $zOffset,
27 ){
28 self::clampOffset($this->xOffset);
29 self::clampOffset($this->yOffset);
30 self::clampOffset($this->zOffset);
31 }
32
33 private static function clampOffset(int $v) : void{
34 if($v < Limits::INT8_MIN || $v > Limits::INT8_MAX){
35 throw new \InvalidArgumentException("Offsets must be within the range of a byte (" . Limits::INT8_MIN . " ... " . Limits::INT8_MAX . ")");
36 }
37 }
38
39 public function getXOffset() : int{ return $this->xOffset; }
40
41 public function getYOffset() : int{ return $this->yOffset; }
42
43 public function getZOffset() : int{ return $this->zOffset; }
44
45 public static function read(PacketSerializer $in) : self{
46 $xOffset = Binary::signByte($in->getByte());
47 $yOffset = Binary::signByte($in->getByte());
48 $zOffset = Binary::signByte($in->getByte());
49
50 return new self($xOffset, $yOffset, $zOffset);
51 }
52
53 public function write(PacketSerializer $out) : void{
54 $out->putByte($this->xOffset);
55 $out->putByte($this->yOffset);
56 $out->putByte($this->zOffset);
57 }
58}