mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-27 13:49:55 +00:00
71 lines
2.4 KiB
PHP
71 lines
2.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
*
|
|
* ____ _ _ __ __ _ __ __ ____
|
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* @author PocketMine Team
|
|
* @link http://www.pocketmine.net/
|
|
*
|
|
*
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\network\mcpe\cache;
|
|
|
|
use pocketmine\network\mcpe\protocol\AvailableActorIdentifiersPacket;
|
|
use pocketmine\network\mcpe\protocol\BiomeDefinitionListPacket;
|
|
use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer;
|
|
use pocketmine\network\mcpe\protocol\types\CacheableNbt;
|
|
use pocketmine\utils\SingletonTrait;
|
|
use Webmozart\PathUtil\Path;
|
|
use function file_get_contents;
|
|
|
|
class StaticPacketCache{
|
|
use SingletonTrait;
|
|
|
|
/** @var BiomeDefinitionListPacket */
|
|
private $biomeDefs;
|
|
/** @var AvailableActorIdentifiersPacket */
|
|
private $availableActorIdentifiers;
|
|
|
|
/**
|
|
* @phpstan-return CacheableNbt<\pocketmine\nbt\tag\CompoundTag>
|
|
*/
|
|
private static function loadCompoundFromFile(string $filePath) : CacheableNbt{
|
|
$rawNbt = @file_get_contents($filePath);
|
|
if($rawNbt === false) throw new \RuntimeException("Failed to read file");
|
|
return new CacheableNbt((new NetworkNbtSerializer())->read($rawNbt)->mustGetCompoundTag());
|
|
}
|
|
|
|
private static function make() : self{
|
|
return new self(
|
|
BiomeDefinitionListPacket::create(self::loadCompoundFromFile(Path::join(\pocketmine\RESOURCE_PATH, 'vanilla', 'biome_definitions.nbt'))),
|
|
AvailableActorIdentifiersPacket::create(self::loadCompoundFromFile(Path::join(\pocketmine\RESOURCE_PATH, 'vanilla', 'entity_identifiers.nbt')))
|
|
);
|
|
}
|
|
|
|
public function __construct(BiomeDefinitionListPacket $biomeDefs, AvailableActorIdentifiersPacket $availableActorIdentifiers){
|
|
$this->biomeDefs = $biomeDefs;
|
|
$this->availableActorIdentifiers = $availableActorIdentifiers;
|
|
}
|
|
|
|
public function getBiomeDefs() : BiomeDefinitionListPacket{
|
|
return $this->biomeDefs;
|
|
}
|
|
|
|
public function getAvailableActorIdentifiers() : AvailableActorIdentifiersPacket{
|
|
return $this->availableActorIdentifiers;
|
|
}
|
|
}
|