PocketMine-MP
5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
ChunkRequestTask.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
22
declare(strict_types=1);
23
24
namespace
pocketmine\network\mcpe;
25
26
use
pocketmine\network\mcpe\compression\CompressBatchPromise
;
27
use
pocketmine\network\mcpe\compression\Compressor
;
28
use
pocketmine\network\mcpe\convert\TypeConverter
;
29
use
pocketmine\network\mcpe\protocol\LevelChunkPacket
;
30
use
pocketmine\network\mcpe\protocol\serializer\PacketBatch
;
31
use
pocketmine\network\mcpe\protocol\types\ChunkPosition
;
32
use
pocketmine\network\mcpe\protocol\types\DimensionIds
;
33
use
pocketmine\network\mcpe\serializer\ChunkSerializer
;
34
use
pocketmine\scheduler\AsyncTask
;
35
use
pocketmine\thread\NonThreadSafeValue
;
36
use
pocketmine\utils\BinaryStream
;
37
use
pocketmine\world\format\Chunk
;
38
use
pocketmine\world\format\io\FastChunkSerializer
;
39
use
function
chr;
40
41
class
ChunkRequestTask
extends
AsyncTask
{
42
private
const
TLS_KEY_PROMISE =
"promise"
;
43
44
protected
string
$chunk;
45
protected
int
$chunkX;
46
protected
int
$chunkZ;
48
private
int
$dimensionId;
50
protected
NonThreadSafeValue
$compressor
;
51
private
string
$tiles;
52
56
public
function
__construct
(
int
$chunkX,
int
$chunkZ,
int
$dimensionId,
Chunk
$chunk,
CompressBatchPromise
$promise,
Compressor
$compressor
){
57
$this->compressor =
new
NonThreadSafeValue
(
$compressor
);
58
59
$this->chunk =
FastChunkSerializer::serializeTerrain
($chunk);
60
$this->chunkX = $chunkX;
61
$this->chunkZ = $chunkZ;
62
$this->dimensionId = $dimensionId;
63
$this->tiles = ChunkSerializer::serializeTiles($chunk);
64
65
$this->
storeLocal
(self::TLS_KEY_PROMISE, $promise);
66
}
67
68
public
function
onRun
() : void{
69
$chunk =
FastChunkSerializer
::deserializeTerrain($this->chunk);
70
$dimensionId = $this->dimensionId;
71
72
$subCount =
ChunkSerializer::getSubChunkCount
($chunk, $dimensionId);
73
$converter = TypeConverter::getInstance();
74
$payload =
ChunkSerializer::serializeFullChunk
($chunk, $dimensionId, $converter->getBlockTranslator(), $this->tiles);
75
76
$stream =
new
BinaryStream
();
77
PacketBatch::encodePackets($stream, [
LevelChunkPacket::create
(
new
ChunkPosition
($this->chunkX, $this->chunkZ), $dimensionId, $subCount,
false
,
null
, $payload)]);
78
79
$compressor
= $this->compressor->
deserialize
();
80
$this->setResult(chr(
$compressor
->getNetworkId()) .
$compressor
->compress($stream->getBuffer()));
81
}
82
83
public
function
onCompletion
() : void{
85
$promise = $this->fetchLocal(self::TLS_KEY_PROMISE);
86
$promise->resolve($this->getResult());
87
}
88
}
pocketmine\network\mcpe\ChunkRequestTask
Definition
ChunkRequestTask.php:41
pocketmine\network\mcpe\ChunkRequestTask\onCompletion
onCompletion()
Definition
ChunkRequestTask.php:83
pocketmine\network\mcpe\ChunkRequestTask\$compressor
NonThreadSafeValue $compressor
Definition
ChunkRequestTask.php:50
pocketmine\network\mcpe\ChunkRequestTask\onRun
onRun()
Definition
ChunkRequestTask.php:68
pocketmine\network\mcpe\ChunkRequestTask\__construct
__construct(int $chunkX, int $chunkZ, int $dimensionId, Chunk $chunk, CompressBatchPromise $promise, Compressor $compressor)
Definition
ChunkRequestTask.php:56
pocketmine\network\mcpe\compression\CompressBatchPromise
Definition
CompressBatchPromise.php:28
pocketmine\network\mcpe\convert\TypeConverter
Definition
TypeConverter.php:56
pocketmine\network\mcpe\protocol\LevelChunkPacket
Definition
LevelChunkPacket.php:24
pocketmine\network\mcpe\protocol\LevelChunkPacket\create
static create(ChunkPosition $chunkPosition, int $dimensionId, int $subChunkCount, bool $clientSubChunkRequestsEnabled, ?array $usedBlobHashes, string $extraPayload)
Definition
LevelChunkPacket.php:54
pocketmine\network\mcpe\protocol\serializer\PacketBatch
Definition
PacketBatch.php:24
pocketmine\network\mcpe\protocol\types\ChunkPosition
Definition
ChunkPosition.php:19
pocketmine\network\mcpe\protocol\types\DimensionIds
Definition
DimensionIds.php:17
pocketmine\network\mcpe\serializer\ChunkSerializer
Definition
ChunkSerializer.php:41
pocketmine\network\mcpe\serializer\ChunkSerializer\serializeFullChunk
static serializeFullChunk(Chunk $chunk, int $dimensionId, BlockTranslator $blockTranslator, ?string $tiles=null)
Definition
ChunkSerializer.php:86
pocketmine\network\mcpe\serializer\ChunkSerializer\getSubChunkCount
static getSubChunkCount(Chunk $chunk, int $dimensionId)
Definition
ChunkSerializer.php:69
pocketmine\scheduler\AsyncTask
Definition
AsyncTask.php:62
pocketmine\scheduler\AsyncTask\storeLocal
storeLocal(string $key, mixed $complexData)
Definition
AsyncTask.php:230
pocketmine\thread\NonThreadSafeValue
Definition
NonThreadSafeValue.php:38
pocketmine\thread\NonThreadSafeValue\deserialize
deserialize()
Definition
NonThreadSafeValue.php:55
pocketmine\utils\BinaryStream
Definition
BinaryStream.php:31
pocketmine\world\format\Chunk
Definition
Chunk.php:34
pocketmine\world\format\io\FastChunkSerializer
Definition
FastChunkSerializer.php:41
pocketmine\world\format\io\FastChunkSerializer\serializeTerrain
static serializeTerrain(Chunk $chunk)
Definition
FastChunkSerializer.php:63
pocketmine\network\mcpe\compression\Compressor
Definition
Compressor.php:28
src
network
mcpe
ChunkRequestTask.php
Generated by
1.12.0