PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
RegionLocationTableEntry.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\world\format\io\region;
25
26use function range;
27
29 private int $firstSector;
31 private int $sectorCount;
32 private int $timestamp;
33
37 public function __construct(int $firstSector, int $sectorCount, int $timestamp){
38 if($firstSector < 0 || $firstSector >= 2 ** 24){
39 throw new \InvalidArgumentException("Start sector must be positive, got $firstSector");
40 }
41 $this->firstSector = $firstSector;
42 if($sectorCount < 1){
43 throw new \InvalidArgumentException("Sector count must be positive, got $sectorCount");
44 }
45 $this->sectorCount = $sectorCount;
46 $this->timestamp = $timestamp;
47 }
48
49 public function getFirstSector() : int{
50 return $this->firstSector;
51 }
52
53 public function getLastSector() : int{
54 return $this->firstSector + $this->sectorCount - 1;
55 }
56
61 public function getUsedSectors() : array{
62 return range($this->getFirstSector(), $this->getLastSector());
63 }
64
68 public function getSectorCount() : int{
69 return $this->sectorCount;
70 }
71
72 public function getTimestamp() : int{
73 return $this->timestamp;
74 }
75
76 public function overlaps(RegionLocationTableEntry $other) : bool{
77 $overlapCheck = static function(RegionLocationTableEntry $entry1, RegionLocationTableEntry $entry2) : bool{
78 $entry1Last = $entry1->getLastSector();
79 $entry2Last = $entry2->getLastSector();
80
81 return (
82 ($entry2->firstSector >= $entry1->firstSector && $entry2->firstSector <= $entry1Last) ||
83 ($entry2Last >= $entry1->firstSector && $entry2Last <= $entry1Last)
84 );
85 };
86 return $overlapCheck($this, $other) || $overlapCheck($other, $this);
87 }
88}
getUsedSectors()
getSectorCount()
__construct(int $firstSector, int $sectorCount, int $timestamp)