PocketMine-MP 5.44.4 git-bc94a0da0c87abe7eb99d229a9ec672b3c405d11
Loading...
Searching...
No Matches
SubChunkPosition.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\LE;
20use pmmp\encoding\VarInt;
21
22final class SubChunkPosition{
23
24 public function __construct(
25 private int $x,
26 private int $y,
27 private int $z,
28 ){}
29
30 public function getX() : int{ return $this->x; }
31
32 public function getY() : int{ return $this->y; }
33
34 public function getZ() : int{ return $this->z; }
35
36 public static function readFixedInts(ByteBufferReader $in) : self{
37 $x = LE::readSignedInt($in);
38 $y = LE::readSignedInt($in);
39 $z = LE::readSignedInt($in);
40
41 return new self($x, $y, $z);
42 }
43
44 public static function readVarInts(ByteBufferReader $in) : self{
45 $x = VarInt::readSignedInt($in);
46 $y = VarInt::readSignedInt($in);
47 $z = VarInt::readSignedInt($in);
48
49 return new self($x, $y, $z);
50 }
51
52 public function writeFixedInts(ByteBufferWriter $out) : void{
53 LE::writeSignedInt($out, $this->x);
54 LE::writeSignedInt($out, $this->y);
55 LE::writeSignedInt($out, $this->z);
56 }
57
58 public function writeVarInts(ByteBufferWriter $out) : void{
59 VarInt::writeSignedInt($out, $this->x);
60 VarInt::writeSignedInt($out, $this->y);
61 VarInt::writeSignedInt($out, $this->z);
62 }
63}