PocketMine-MP 5.33.2 git-919492bdcad8510eb6606439eb77e1c604f1d1ea
Loading...
Searching...
No Matches
ValueMappings.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
27use pocketmine\block\utils\BellAttachmentType;
28use pocketmine\block\utils\DirtType;
29use pocketmine\block\utils\DripleafState;
30use pocketmine\block\utils\DyeColor;
31use pocketmine\block\utils\FroglightType;
32use pocketmine\block\utils\HorizontalFacingOption;
33use pocketmine\block\utils\LeverFacing;
34use pocketmine\block\utils\MobHeadType;
35use pocketmine\block\utils\MushroomBlockType;
41use pocketmine\utils\SingletonTrait;
42
43final class ValueMappings{
44 use SingletonTrait; //???
45
56
63
66
79
96
103
104 public function __construct(){
105 //flattened ID components - we can't generate constants for these
106 $this->dyeColor = EnumFromRawStateMap::string(DyeColor::class, fn(DyeColor $case) => match ($case) {
107 DyeColor::BLACK => "black",
108 DyeColor::BLUE => "blue",
109 DyeColor::BROWN => "brown",
110 DyeColor::CYAN => "cyan",
111 DyeColor::GRAY => "gray",
112 DyeColor::GREEN => "green",
113 DyeColor::LIGHT_BLUE => "light_blue",
114 DyeColor::LIGHT_GRAY => "light_gray",
115 DyeColor::LIME => "lime",
116 DyeColor::MAGENTA => "magenta",
117 DyeColor::ORANGE => "orange",
118 DyeColor::PINK => "pink",
119 DyeColor::PURPLE => "purple",
120 DyeColor::RED => "red",
121 DyeColor::WHITE => "white",
122 DyeColor::YELLOW => "yellow"
123 });
124 $this->dyeColorWithSilver = EnumFromRawStateMap::string(DyeColor::class, fn(DyeColor $case) => match ($case) {
125 DyeColor::LIGHT_GRAY => "silver",
126 default => $this->dyeColor->valueToRaw($case)
127 });
128
129 $this->mobHeadType = EnumFromRawStateMap::string(MobHeadType::class, fn(MobHeadType $case) => match ($case) {
130 MobHeadType::CREEPER => Ids::CREEPER_HEAD,
131 MobHeadType::DRAGON => Ids::DRAGON_HEAD,
132 MobHeadType::PIGLIN => Ids::PIGLIN_HEAD,
133 MobHeadType::PLAYER => Ids::PLAYER_HEAD,
134 MobHeadType::SKELETON => Ids::SKELETON_SKULL,
135 MobHeadType::WITHER_SKELETON => Ids::WITHER_SKELETON_SKULL,
136 MobHeadType::ZOMBIE => Ids::ZOMBIE_HEAD
137 });
138 $this->froglightType = EnumFromRawStateMap::string(FroglightType::class, fn(FroglightType $case) => match ($case) {
139 FroglightType::OCHRE => Ids::OCHRE_FROGLIGHT,
140 FroglightType::PEARLESCENT => Ids::PEARLESCENT_FROGLIGHT,
141 FroglightType::VERDANT => Ids::VERDANT_FROGLIGHT,
142 });
143 $this->dirtType = EnumFromRawStateMap::string(DirtType::class, fn(DirtType $case) => match ($case) {
144 DirtType::NORMAL => Ids::DIRT,
145 DirtType::COARSE => Ids::COARSE_DIRT,
146 DirtType::ROOTED => Ids::DIRT_WITH_ROOTS,
147 });
148
149 //state value mappings
150 $this->dripleafState = EnumFromRawStateMap::string(DripleafState::class, fn(DripleafState $case) => match ($case) {
151 DripleafState::STABLE => StringValues::BIG_DRIPLEAF_TILT_NONE,
152 DripleafState::UNSTABLE => StringValues::BIG_DRIPLEAF_TILT_UNSTABLE,
153 DripleafState::PARTIAL_TILT => StringValues::BIG_DRIPLEAF_TILT_PARTIAL_TILT,
154 DripleafState::FULL_TILT => StringValues::BIG_DRIPLEAF_TILT_FULL_TILT
155 });
156 $this->bellAttachmentType = EnumFromRawStateMap::string(BellAttachmentType::class, fn(BellAttachmentType $case) => match ($case) {
157 BellAttachmentType::FLOOR => StringValues::ATTACHMENT_STANDING,
158 BellAttachmentType::CEILING => StringValues::ATTACHMENT_HANGING,
159 BellAttachmentType::ONE_WALL => StringValues::ATTACHMENT_SIDE,
160 BellAttachmentType::TWO_WALLS => StringValues::ATTACHMENT_MULTIPLE,
161 });
162 $this->leverFacing = EnumFromRawStateMap::string(LeverFacing::class, fn(LeverFacing $case) => match ($case) {
163 LeverFacing::DOWN_AXIS_Z => StringValues::LEVER_DIRECTION_DOWN_NORTH_SOUTH,
164 LeverFacing::DOWN_AXIS_X => StringValues::LEVER_DIRECTION_DOWN_EAST_WEST,
165 LeverFacing::UP_AXIS_Z => StringValues::LEVER_DIRECTION_UP_NORTH_SOUTH,
166 LeverFacing::UP_AXIS_X => StringValues::LEVER_DIRECTION_UP_EAST_WEST,
167 LeverFacing::NORTH => StringValues::LEVER_DIRECTION_NORTH,
168 LeverFacing::SOUTH => StringValues::LEVER_DIRECTION_SOUTH,
169 LeverFacing::WEST => StringValues::LEVER_DIRECTION_WEST,
170 LeverFacing::EAST => StringValues::LEVER_DIRECTION_EAST
171 });
172
173 $this->mushroomBlockType = EnumFromRawStateMap::int(
174 MushroomBlockType::class,
175 fn(MushroomBlockType $case) => match ($case) {
176 MushroomBlockType::PORES => LegacyMeta::MUSHROOM_BLOCK_ALL_PORES,
177 MushroomBlockType::CAP_NORTHWEST => LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHWEST_CORNER,
178 MushroomBlockType::CAP_NORTH => LegacyMeta::MUSHROOM_BLOCK_CAP_NORTH_SIDE,
179 MushroomBlockType::CAP_NORTHEAST => LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHEAST_CORNER,
180 MushroomBlockType::CAP_WEST => LegacyMeta::MUSHROOM_BLOCK_CAP_WEST_SIDE,
181 MushroomBlockType::CAP_MIDDLE => LegacyMeta::MUSHROOM_BLOCK_CAP_TOP_ONLY,
182 MushroomBlockType::CAP_EAST => LegacyMeta::MUSHROOM_BLOCK_CAP_EAST_SIDE,
183 MushroomBlockType::CAP_SOUTHWEST => LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHWEST_CORNER,
184 MushroomBlockType::CAP_SOUTH => LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTH_SIDE,
185 MushroomBlockType::CAP_SOUTHEAST => LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHEAST_CORNER,
186 MushroomBlockType::ALL_CAP => LegacyMeta::MUSHROOM_BLOCK_ALL_CAP,
187 },
188 fn(MushroomBlockType $case) => match ($case) {
189 MushroomBlockType::ALL_CAP => [11, 12, 13],
190 default => []
191 }
192 );
193
194 //TODO: this can't use EnumFromRawStateMap until we have a dedicated HorizontalFacing enum
195 $this->cardinalDirection = EnumFromRawStateMap::string(HorizontalFacingOption::class, fn(HorizontalFacingOption $case) => match ($case) {
196 HorizontalFacingOption::NORTH => StringValues::MC_CARDINAL_DIRECTION_NORTH,
197 HorizontalFacingOption::SOUTH => StringValues::MC_CARDINAL_DIRECTION_SOUTH,
198 HorizontalFacingOption::WEST => StringValues::MC_CARDINAL_DIRECTION_WEST,
199 HorizontalFacingOption::EAST => StringValues::MC_CARDINAL_DIRECTION_EAST,
200 });
201 $this->blockFace = EnumFromRawStateMap::string(Facing::class, fn(Facing $case) => match ($case) {
202 Facing::DOWN => StringValues::MC_BLOCK_FACE_DOWN,
203 Facing::UP => StringValues::MC_BLOCK_FACE_UP,
204 Facing::NORTH => StringValues::MC_BLOCK_FACE_NORTH,
205 Facing::SOUTH => StringValues::MC_BLOCK_FACE_SOUTH,
206 Facing::WEST => StringValues::MC_BLOCK_FACE_WEST,
207 Facing::EAST => StringValues::MC_BLOCK_FACE_EAST,
208 });
209 $this->pillarAxis = EnumFromRawStateMap::string(Axis::class, fn(Axis $case) => match ($case) {
210 Axis::X => StringValues::PILLAR_AXIS_X,
211 Axis::Y => StringValues::PILLAR_AXIS_Y,
212 Axis::Z => StringValues::PILLAR_AXIS_Z
213 });
214 $this->torchFacing = IntFromRawStateMap::string([
215 //TODO: horizontal directions are flipped (MCPE bug: https://bugs.mojang.com/browse/MCPE-152036)
216 Facing::WEST->value => StringValues::TORCH_FACING_DIRECTION_EAST,
217 Facing::SOUTH->value => StringValues::TORCH_FACING_DIRECTION_NORTH,
218 Facing::NORTH->value => StringValues::TORCH_FACING_DIRECTION_SOUTH,
219 Facing::UP->value => StringValues::TORCH_FACING_DIRECTION_TOP,
220 Facing::EAST->value => StringValues::TORCH_FACING_DIRECTION_WEST,
221 ], deserializeAliases: [
222 Facing::UP->value => StringValues::TORCH_FACING_DIRECTION_UNKNOWN //should be illegal, but still supported
223 ]);
224 $this->portalAxis = IntFromRawStateMap::string([
225 Axis::X->value => StringValues::PORTAL_AXIS_X,
226 Axis::Z->value => StringValues::PORTAL_AXIS_Z,
227 ], deserializeAliases: [
228 Axis::X->value => StringValues::PORTAL_AXIS_UNKNOWN,
229 ]);
230 $this->bambooLeafSize = IntFromRawStateMap::string([
231 Bamboo::NO_LEAVES => StringValues::BAMBOO_LEAF_SIZE_NO_LEAVES,
232 Bamboo::SMALL_LEAVES => StringValues::BAMBOO_LEAF_SIZE_SMALL_LEAVES,
233 Bamboo::LARGE_LEAVES => StringValues::BAMBOO_LEAF_SIZE_LARGE_LEAVES,
234 ]);
235
236 $this->horizontalFacing5Minus = EnumFromRawStateMap::int(HorizontalFacingOption::class, fn(HorizontalFacingOption $case) => match ($case) {
237 HorizontalFacingOption::EAST => 0,
238 HorizontalFacingOption::WEST => 1,
239 HorizontalFacingOption::SOUTH => 2,
240 HorizontalFacingOption::NORTH => 3
241 });
242 $this->horizontalFacingSWNE = EnumFromRawStateMap::int(HorizontalFacingOption::class, fn(HorizontalFacingOption $case) => match ($case) {
243 HorizontalFacingOption::SOUTH => 0,
244 HorizontalFacingOption::WEST => 1,
245 HorizontalFacingOption::NORTH => 2,
246 HorizontalFacingOption::EAST => 3
247 });
248 $this->horizontalFacingSWNEInverted = EnumFromRawStateMap::int(HorizontalFacingOption::class, fn(HorizontalFacingOption $case) => match ($case) {
249 HorizontalFacingOption::NORTH => 0,
250 HorizontalFacingOption::EAST => 1,
251 HorizontalFacingOption::SOUTH => 2,
252 HorizontalFacingOption::WEST => 3,
253 });
254 $this->horizontalFacingCoral = EnumFromRawStateMap::int(HorizontalFacingOption::class, fn(HorizontalFacingOption $case) => match ($case) {
255 HorizontalFacingOption::WEST => 0,
256 HorizontalFacingOption::EAST => 1,
257 HorizontalFacingOption::NORTH => 2,
258 HorizontalFacingOption::SOUTH => 3
259 });
260 $this->horizontalFacingClassic = EnumFromRawStateMap::int(HorizontalFacingOption::class, fn(HorizontalFacingOption $case) => match ($case) {
261 HorizontalFacingOption::NORTH => 2,
262 HorizontalFacingOption::SOUTH => 3,
263 HorizontalFacingOption::WEST => 4,
264 HorizontalFacingOption::EAST => 5
265 }, aliasMapper: fn(HorizontalFacingOption $case) => $case === HorizontalFacingOption::NORTH ? [0, 1] : []); //should be illegal but still technically possible
266
267 $this->facing = EnumFromRawStateMap::int(Facing::class, fn(Facing $case) => match ($case) {
268 Facing::DOWN => 0,
269 Facing::UP => 1,
270 Facing::NORTH => 2,
271 Facing::SOUTH => 3,
272 Facing::WEST => 4,
273 Facing::EAST => 5
274 });
275
276 //end rods have all the horizontal facing values opposite to classic facing
277 $this->facingEndRod = EnumFromRawStateMap::int(Facing::class, fn(Facing $case) => match ($case) {
278 Facing::DOWN => 0,
279 Facing::UP => 1,
280 Facing::SOUTH => 2,
281 Facing::NORTH => 3,
282 Facing::EAST => 4,
283 Facing::WEST => 5,
284 });
285
286 //these can't be migrated to enums yet
287 $horizontalFacingClassicTable = [
288 Facing::NORTH->value => 2,
289 Facing::SOUTH->value => 3,
290 Facing::WEST->value => 4,
291 Facing::EAST->value => 5
292 ];
293 $this->coralAxis = IntFromRawStateMap::int([
294 Axis::X->value => 0,
295 Axis::Z->value => 1,
296 ]);
297
298 //TODO: shitty copy pasta job, we can do this better but this is good enough for now
299 $this->facingExceptDown = IntFromRawStateMap::int(
300 [Facing::UP->value => 1] + $horizontalFacingClassicTable,
301 deserializeAliases: [Facing::UP->value => 0]);
302 $this->facingExceptUp = IntFromRawStateMap::int(
303 [Facing::DOWN->value => 0] + $horizontalFacingClassicTable,
304 deserializeAliases: [Facing::DOWN->value => 1]
305 );
306
307 //In PM, we use Facing::UP to indicate that the stem is not attached to a pumpkin/melon, since this makes the
308 //most intuitive sense (the stem is pointing at the sky). However, Bedrock uses the DOWN state for this, which
309 //is absurd, and I refuse to make our API similarly absurd.
310 $this->facingStem = IntFromRawStateMap::int(
311 [Facing::UP->value => 0] + $horizontalFacingClassicTable,
312 deserializeAliases: [Facing::UP->value => 1]
313 );
314 }
315}
static string(string $class, \Closure $mapper, ?\Closure $aliasMapper=null)
static int(string $class, \Closure $mapper, ?\Closure $aliasMapper=null)
static int(array $serializeMap, array $deserializeAliases=[])
static string(array $serializeMap, array $deserializeAliases=[])