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