PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
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
17use pmmp\encoding\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
21
23
24 public function __construct(
25 private int $xOffset,
26 private int $yOffset,
27 private int $zOffset,
28 ){
29 self::clampOffset($this->xOffset);
30 self::clampOffset($this->yOffset);
31 self::clampOffset($this->zOffset);
32 }
33
34 private static function clampOffset(int $v) : void{
35 if($v < Limits::INT8_MIN || $v > Limits::INT8_MAX){
36 throw new \InvalidArgumentException("Offsets must be within the range of a byte (" . Limits::INT8_MIN . " ... " . Limits::INT8_MAX . ")");
37 }
38 }
39
40 public function getXOffset() : int{ return $this->xOffset; }
41
42 public function getYOffset() : int{ return $this->yOffset; }
43
44 public function getZOffset() : int{ return $this->zOffset; }
45
46 public static function read(ByteBufferReader $in) : self{
47 $xOffset = Byte::readSigned($in);
48 $yOffset = Byte::readSigned($in);
49 $zOffset = Byte::readSigned($in);
50
51 return new self($xOffset, $yOffset, $zOffset);
52 }
53
54 public function write(ByteBufferWriter $out) : void{
55 Byte::writeSigned($out, $this->xOffset);
56 Byte::writeSigned($out, $this->yOffset);
57 Byte::writeSigned($out, $this->zOffset);
58 }
59}