PocketMine-MP 5.32.2 git-1ebd7d3960d713d56f77f610fe0c15cdee201069
Loading...
Searching...
No Matches
IntFromRawStateMap.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\data\bedrock\block\convert\property;
25
26use function array_flip;
27use function is_array;
28
34
39 private array $deserializeMap;
40
51 public function __construct(
52 private array $serializeMap,
53 array $deserializeAliases = []
54 ){
55 $this->deserializeMap = array_flip($this->serializeMap);
56 foreach($deserializeAliases as $pmValue => $mcValues){
57 if(!is_array($mcValues)){
58 $this->deserializeMap[$mcValues] = $pmValue;
59 }else{
60 foreach($mcValues as $mcValue){
61 $this->deserializeMap[$mcValue] = $pmValue;
62 }
63 }
64 }
65 }
66
76 public static function int(array $serializeMap, array $deserializeAliases = []) : self{ return new self($serializeMap, $deserializeAliases); }
77
87 public static function string(array $serializeMap, array $deserializeAliases = []) : self{ return new self($serializeMap, $deserializeAliases); }
88
89 public function getRawToValueMap() : array{
90 return $this->deserializeMap;
91 }
92
93 public function valueToRaw(mixed $value) : int|string{
94 return $this->serializeMap[$value];
95 }
96
97 public function rawToValue(int|string $raw) : mixed{
98 return $this->deserializeMap[$raw] ?? null;
99 }
100
101 public function printableValue(mixed $value) : string{
102 return "$value";
103 }
104}
static int(array $serializeMap, array $deserializeAliases=[])
__construct(private array $serializeMap, array $deserializeAliases=[])
static string(array $serializeMap, array $deserializeAliases=[])