mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 08:39:53 +00:00
RuntimeBlockMapping: make constructor more useful
this allows providing more customisable data sources.
This commit is contained in:
parent
e27f80fd85
commit
1a598bdfd8
@ -41,8 +41,6 @@ use function file_get_contents;
|
|||||||
final class RuntimeBlockMapping{
|
final class RuntimeBlockMapping{
|
||||||
use SingletonTrait;
|
use SingletonTrait;
|
||||||
|
|
||||||
private BlockStateDictionary $blockStateDictionary;
|
|
||||||
private BlockStateSerializer $blockStateSerializer;
|
|
||||||
/**
|
/**
|
||||||
* @var int[]
|
* @var int[]
|
||||||
* @phpstan-var array<int, int>
|
* @phpstan-var array<int, int>
|
||||||
@ -54,14 +52,18 @@ final class RuntimeBlockMapping{
|
|||||||
private int $fallbackStateId;
|
private int $fallbackStateId;
|
||||||
|
|
||||||
private static function make() : self{
|
private static function make() : self{
|
||||||
return new self(Path::join(\pocketmine\BEDROCK_DATA_PATH, "canonical_block_states.nbt"));
|
$canonicalBlockStatesFile = Path::join(\pocketmine\BEDROCK_DATA_PATH, "canonical_block_states.nbt");
|
||||||
|
$contents = Utils::assumeNotFalse(file_get_contents($canonicalBlockStatesFile), "Missing required resource file");
|
||||||
|
return new self(
|
||||||
|
BlockStateDictionary::loadFromString($contents),
|
||||||
|
GlobalBlockStateHandlers::getSerializer()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct(string $canonicalBlockStatesFile){
|
public function __construct(
|
||||||
$contents = Utils::assumeNotFalse(file_get_contents($canonicalBlockStatesFile), "Missing required resource file");
|
private BlockStateDictionary $blockStateDictionary,
|
||||||
$this->blockStateDictionary = BlockStateDictionary::loadFromString($contents);
|
private BlockStateSerializer $blockStateSerializer
|
||||||
$this->blockStateSerializer = GlobalBlockStateHandlers::getSerializer();
|
){
|
||||||
|
|
||||||
$this->fallbackStateData = new BlockStateData(BlockTypeNames::INFO_UPDATE, CompoundTag::create(), BlockStateData::CURRENT_VERSION);
|
$this->fallbackStateData = new BlockStateData(BlockTypeNames::INFO_UPDATE, CompoundTag::create(), BlockStateData::CURRENT_VERSION);
|
||||||
$this->fallbackStateId = $this->blockStateDictionary->lookupStateIdFromData($this->fallbackStateData) ?? throw new AssumptionFailedError(BlockTypeNames::INFO_UPDATE . " should always exist");
|
$this->fallbackStateId = $this->blockStateDictionary->lookupStateIdFromData($this->fallbackStateData) ?? throw new AssumptionFailedError(BlockTypeNames::INFO_UPDATE . " should always exist");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user