mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-16 03:51:37 +00:00
Generalize runtime block data serialization
we want to reuse this code for item type data
This commit is contained in:
28
src/data/runtime/InvalidSerializedRuntimeDataException.php
Normal file
28
src/data/runtime/InvalidSerializedRuntimeDataException.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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\data\runtime;
|
||||
|
||||
final class InvalidSerializedRuntimeDataException extends \UnexpectedValueException{
|
||||
|
||||
}
|
@@ -21,15 +21,14 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\data\runtime\block;
|
||||
namespace pocketmine\data\runtime;
|
||||
|
||||
use pocketmine\block\utils\InvalidBlockStateException;
|
||||
use pocketmine\block\utils\WallConnectionType;
|
||||
use pocketmine\math\Axis;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\utils\AssumptionFailedError;
|
||||
|
||||
final class BlockDataReader{
|
||||
final class RuntimeDataReader{
|
||||
|
||||
private int $offset = 0;
|
||||
|
||||
@@ -52,7 +51,7 @@ final class BlockDataReader{
|
||||
public function readBoundedInt(int $bits, int $min, int $max) : int{
|
||||
$result = $this->readInt($bits);
|
||||
if($result < $min || $result > $max){
|
||||
throw new InvalidBlockStateException("Value is outside the range $min - $max");
|
||||
throw new InvalidSerializedRuntimeDataException("Value is outside the range $min - $max");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
@@ -79,7 +78,7 @@ final class BlockDataReader{
|
||||
3 => Facing::SOUTH,
|
||||
4 => Facing::WEST,
|
||||
5 => Facing::EAST,
|
||||
default => throw new InvalidBlockStateException("Invalid facing value")
|
||||
default => throw new InvalidSerializedRuntimeDataException("Invalid facing value")
|
||||
};
|
||||
}
|
||||
|
||||
@@ -88,7 +87,7 @@ final class BlockDataReader{
|
||||
0 => Axis::X,
|
||||
1 => Axis::Z,
|
||||
2 => Axis::Y,
|
||||
default => throw new InvalidBlockStateException("Invalid axis value")
|
||||
default => throw new InvalidSerializedRuntimeDataException("Invalid axis value")
|
||||
};
|
||||
}
|
||||
|
@@ -21,14 +21,14 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\data\runtime\block;
|
||||
namespace pocketmine\data\runtime;
|
||||
|
||||
use pocketmine\block\utils\WallConnectionType;
|
||||
use pocketmine\math\Axis;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\utils\AssumptionFailedError;
|
||||
|
||||
final class BlockDataWriter{
|
||||
final class RuntimeDataWriter{
|
||||
|
||||
private int $value = 0;
|
||||
private int $offset = 0;
|
108
src/data/runtime/RuntimeEnumDeserializer.php
Normal file
108
src/data/runtime/RuntimeEnumDeserializer.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\data\runtime;
|
||||
|
||||
/**
|
||||
* This class is auto-generated. Do not edit it manually.
|
||||
* @see build/generate-runtime-enum-serializers.php
|
||||
*/
|
||||
final class RuntimeEnumDeserializer{
|
||||
|
||||
public static function readBellAttachmentType(RuntimeDataReader $r) : \pocketmine\block\utils\BellAttachmentType{
|
||||
return match($r->readInt(2)){
|
||||
0 => \pocketmine\block\utils\BellAttachmentType::CEILING(),
|
||||
1 => \pocketmine\block\utils\BellAttachmentType::FLOOR(),
|
||||
2 => \pocketmine\block\utils\BellAttachmentType::ONE_WALL(),
|
||||
3 => \pocketmine\block\utils\BellAttachmentType::TWO_WALLS(),
|
||||
default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for BellAttachmentType")
|
||||
};
|
||||
}
|
||||
|
||||
public static function readCoralType(RuntimeDataReader $r) : \pocketmine\block\utils\CoralType{
|
||||
return match($r->readInt(3)){
|
||||
0 => \pocketmine\block\utils\CoralType::BRAIN(),
|
||||
1 => \pocketmine\block\utils\CoralType::BUBBLE(),
|
||||
2 => \pocketmine\block\utils\CoralType::FIRE(),
|
||||
3 => \pocketmine\block\utils\CoralType::HORN(),
|
||||
4 => \pocketmine\block\utils\CoralType::TUBE(),
|
||||
default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for CoralType")
|
||||
};
|
||||
}
|
||||
|
||||
public static function readDyeColor(RuntimeDataReader $r) : \pocketmine\block\utils\DyeColor{
|
||||
return match($r->readInt(4)){
|
||||
0 => \pocketmine\block\utils\DyeColor::BLACK(),
|
||||
1 => \pocketmine\block\utils\DyeColor::BLUE(),
|
||||
2 => \pocketmine\block\utils\DyeColor::BROWN(),
|
||||
3 => \pocketmine\block\utils\DyeColor::CYAN(),
|
||||
4 => \pocketmine\block\utils\DyeColor::GRAY(),
|
||||
5 => \pocketmine\block\utils\DyeColor::GREEN(),
|
||||
6 => \pocketmine\block\utils\DyeColor::LIGHT_BLUE(),
|
||||
7 => \pocketmine\block\utils\DyeColor::LIGHT_GRAY(),
|
||||
8 => \pocketmine\block\utils\DyeColor::LIME(),
|
||||
9 => \pocketmine\block\utils\DyeColor::MAGENTA(),
|
||||
10 => \pocketmine\block\utils\DyeColor::ORANGE(),
|
||||
11 => \pocketmine\block\utils\DyeColor::PINK(),
|
||||
12 => \pocketmine\block\utils\DyeColor::PURPLE(),
|
||||
13 => \pocketmine\block\utils\DyeColor::RED(),
|
||||
14 => \pocketmine\block\utils\DyeColor::WHITE(),
|
||||
15 => \pocketmine\block\utils\DyeColor::YELLOW(),
|
||||
default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for DyeColor")
|
||||
};
|
||||
}
|
||||
|
||||
public static function readLeverFacing(RuntimeDataReader $r) : \pocketmine\block\utils\LeverFacing{
|
||||
return match($r->readInt(3)){
|
||||
0 => \pocketmine\block\utils\LeverFacing::DOWN_AXIS_X(),
|
||||
1 => \pocketmine\block\utils\LeverFacing::DOWN_AXIS_Z(),
|
||||
2 => \pocketmine\block\utils\LeverFacing::EAST(),
|
||||
3 => \pocketmine\block\utils\LeverFacing::NORTH(),
|
||||
4 => \pocketmine\block\utils\LeverFacing::SOUTH(),
|
||||
5 => \pocketmine\block\utils\LeverFacing::UP_AXIS_X(),
|
||||
6 => \pocketmine\block\utils\LeverFacing::UP_AXIS_Z(),
|
||||
7 => \pocketmine\block\utils\LeverFacing::WEST(),
|
||||
default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for LeverFacing")
|
||||
};
|
||||
}
|
||||
|
||||
public static function readMushroomBlockType(RuntimeDataReader $r) : \pocketmine\block\utils\MushroomBlockType{
|
||||
return match($r->readInt(4)){
|
||||
0 => \pocketmine\block\utils\MushroomBlockType::ALL_CAP(),
|
||||
1 => \pocketmine\block\utils\MushroomBlockType::CAP_EAST(),
|
||||
2 => \pocketmine\block\utils\MushroomBlockType::CAP_MIDDLE(),
|
||||
3 => \pocketmine\block\utils\MushroomBlockType::CAP_NORTH(),
|
||||
4 => \pocketmine\block\utils\MushroomBlockType::CAP_NORTHEAST(),
|
||||
5 => \pocketmine\block\utils\MushroomBlockType::CAP_NORTHWEST(),
|
||||
6 => \pocketmine\block\utils\MushroomBlockType::CAP_SOUTH(),
|
||||
7 => \pocketmine\block\utils\MushroomBlockType::CAP_SOUTHEAST(),
|
||||
8 => \pocketmine\block\utils\MushroomBlockType::CAP_SOUTHWEST(),
|
||||
9 => \pocketmine\block\utils\MushroomBlockType::CAP_WEST(),
|
||||
10 => \pocketmine\block\utils\MushroomBlockType::PORES(),
|
||||
default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for MushroomBlockType")
|
||||
};
|
||||
}
|
||||
|
||||
public static function readSkullType(RuntimeDataReader $r) : \pocketmine\block\utils\SkullType{
|
||||
return match($r->readInt(3)){
|
||||
0 => \pocketmine\block\utils\SkullType::CREEPER(),
|
||||
1 => \pocketmine\block\utils\SkullType::DRAGON(),
|
||||
2 => \pocketmine\block\utils\SkullType::PLAYER(),
|
||||
3 => \pocketmine\block\utils\SkullType::SKELETON(),
|
||||
4 => \pocketmine\block\utils\SkullType::WITHER_SKELETON(),
|
||||
5 => \pocketmine\block\utils\SkullType::ZOMBIE(),
|
||||
default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for SkullType")
|
||||
};
|
||||
}
|
||||
|
||||
public static function readSlabType(RuntimeDataReader $r) : \pocketmine\block\utils\SlabType{
|
||||
return match($r->readInt(2)){
|
||||
0 => \pocketmine\block\utils\SlabType::BOTTOM(),
|
||||
1 => \pocketmine\block\utils\SlabType::DOUBLE(),
|
||||
2 => \pocketmine\block\utils\SlabType::TOP(),
|
||||
default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for SlabType")
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@@ -1,41 +1,16 @@
|
||||
<?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\data\runtime\block;
|
||||
namespace pocketmine\data\runtime;
|
||||
|
||||
use pocketmine\block\utils\BellAttachmentType;
|
||||
use pocketmine\block\utils\CoralType;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\block\utils\LeverFacing;
|
||||
use pocketmine\block\utils\MushroomBlockType;
|
||||
use pocketmine\block\utils\SkullType;
|
||||
use pocketmine\block\utils\SlabType;
|
||||
use pocketmine\block\utils\StairShape;
|
||||
use pocketmine\block\utils\TreeType;
|
||||
/**
|
||||
* This class is auto-generated. Do not edit it manually.
|
||||
* @see build/generate-runtime-enum-serializers.php
|
||||
*/
|
||||
final class RuntimeEnumSerializer{
|
||||
|
||||
final class BlockDataWriterHelper{
|
||||
|
||||
public static function writeBellAttachmentType(BlockDataWriter $w, BellAttachmentType $value) : void{
|
||||
public static function writeBellAttachmentType(RuntimeDataWriter $w, \pocketmine\block\utils\BellAttachmentType $value) : void{
|
||||
$w->writeInt(2, match($value){
|
||||
\pocketmine\block\utils\BellAttachmentType::CEILING() => 0,
|
||||
\pocketmine\block\utils\BellAttachmentType::FLOOR() => 1,
|
||||
@@ -45,21 +20,7 @@ final class BlockDataWriterHelper{
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \pocketmine\block\utils\BrewingStandSlot[] $value
|
||||
* @phpstan-param array<int, \pocketmine\block\utils\BrewingStandSlot> $value
|
||||
*/
|
||||
public static function writeBrewingStandSlotKeySet(BlockDataWriter $w, array $value) : void{
|
||||
foreach([
|
||||
\pocketmine\block\utils\BrewingStandSlot::EAST(),
|
||||
\pocketmine\block\utils\BrewingStandSlot::NORTHWEST(),
|
||||
\pocketmine\block\utils\BrewingStandSlot::SOUTHWEST(),
|
||||
] as $member){
|
||||
$w->writeBool(isset($value[$member->id()]));
|
||||
}
|
||||
}
|
||||
|
||||
public static function writeCoralType(BlockDataWriter $w, CoralType $value) : void{
|
||||
public static function writeCoralType(RuntimeDataWriter $w, \pocketmine\block\utils\CoralType $value) : void{
|
||||
$w->writeInt(3, match($value){
|
||||
\pocketmine\block\utils\CoralType::BRAIN() => 0,
|
||||
\pocketmine\block\utils\CoralType::BUBBLE() => 1,
|
||||
@@ -70,7 +31,7 @@ final class BlockDataWriterHelper{
|
||||
});
|
||||
}
|
||||
|
||||
public static function writeDyeColor(BlockDataWriter $w, DyeColor $value) : void{
|
||||
public static function writeDyeColor(RuntimeDataWriter $w, \pocketmine\block\utils\DyeColor $value) : void{
|
||||
$w->writeInt(4, match($value){
|
||||
\pocketmine\block\utils\DyeColor::BLACK() => 0,
|
||||
\pocketmine\block\utils\DyeColor::BLUE() => 1,
|
||||
@@ -92,7 +53,7 @@ final class BlockDataWriterHelper{
|
||||
});
|
||||
}
|
||||
|
||||
public static function writeLeverFacing(BlockDataWriter $w, LeverFacing $value) : void{
|
||||
public static function writeLeverFacing(RuntimeDataWriter $w, \pocketmine\block\utils\LeverFacing $value) : void{
|
||||
$w->writeInt(3, match($value){
|
||||
\pocketmine\block\utils\LeverFacing::DOWN_AXIS_X() => 0,
|
||||
\pocketmine\block\utils\LeverFacing::DOWN_AXIS_Z() => 1,
|
||||
@@ -106,7 +67,7 @@ final class BlockDataWriterHelper{
|
||||
});
|
||||
}
|
||||
|
||||
public static function writeMushroomBlockType(BlockDataWriter $w, MushroomBlockType $value) : void{
|
||||
public static function writeMushroomBlockType(RuntimeDataWriter $w, \pocketmine\block\utils\MushroomBlockType $value) : void{
|
||||
$w->writeInt(4, match($value){
|
||||
\pocketmine\block\utils\MushroomBlockType::ALL_CAP() => 0,
|
||||
\pocketmine\block\utils\MushroomBlockType::CAP_EAST() => 1,
|
||||
@@ -123,7 +84,7 @@ final class BlockDataWriterHelper{
|
||||
});
|
||||
}
|
||||
|
||||
public static function writeSkullType(BlockDataWriter $w, SkullType $value) : void{
|
||||
public static function writeSkullType(RuntimeDataWriter $w, \pocketmine\block\utils\SkullType $value) : void{
|
||||
$w->writeInt(3, match($value){
|
||||
\pocketmine\block\utils\SkullType::CREEPER() => 0,
|
||||
\pocketmine\block\utils\SkullType::DRAGON() => 1,
|
||||
@@ -135,7 +96,7 @@ final class BlockDataWriterHelper{
|
||||
});
|
||||
}
|
||||
|
||||
public static function writeSlabType(BlockDataWriter $w, SlabType $value) : void{
|
||||
public static function writeSlabType(RuntimeDataWriter $w, \pocketmine\block\utils\SlabType $value) : void{
|
||||
$w->writeInt(2, match($value){
|
||||
\pocketmine\block\utils\SlabType::BOTTOM() => 0,
|
||||
\pocketmine\block\utils\SlabType::DOUBLE() => 1,
|
||||
@@ -144,27 +105,4 @@ final class BlockDataWriterHelper{
|
||||
});
|
||||
}
|
||||
|
||||
public static function writeStairShape(BlockDataWriter $w, StairShape $value) : void{
|
||||
$w->writeInt(3, match($value){
|
||||
\pocketmine\block\utils\StairShape::INNER_LEFT() => 0,
|
||||
\pocketmine\block\utils\StairShape::INNER_RIGHT() => 1,
|
||||
\pocketmine\block\utils\StairShape::OUTER_LEFT() => 2,
|
||||
\pocketmine\block\utils\StairShape::OUTER_RIGHT() => 3,
|
||||
\pocketmine\block\utils\StairShape::STRAIGHT() => 4,
|
||||
default => throw new \pocketmine\utils\AssumptionFailedError("All StairShape cases should be covered")
|
||||
});
|
||||
}
|
||||
|
||||
public static function writeTreeType(BlockDataWriter $w, TreeType $value) : void{
|
||||
$w->writeInt(3, match($value){
|
||||
\pocketmine\block\utils\TreeType::ACACIA() => 0,
|
||||
\pocketmine\block\utils\TreeType::BIRCH() => 1,
|
||||
\pocketmine\block\utils\TreeType::DARK_OAK() => 2,
|
||||
\pocketmine\block\utils\TreeType::JUNGLE() => 3,
|
||||
\pocketmine\block\utils\TreeType::OAK() => 4,
|
||||
\pocketmine\block\utils\TreeType::SPRUCE() => 5,
|
||||
default => throw new \pocketmine\utils\AssumptionFailedError("All TreeType cases should be covered")
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -1,174 +0,0 @@
|
||||
<?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\data\runtime\block;
|
||||
|
||||
use pocketmine\block\utils\BellAttachmentType;
|
||||
use pocketmine\block\utils\CoralType;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\block\utils\LeverFacing;
|
||||
use pocketmine\block\utils\MushroomBlockType;
|
||||
use pocketmine\block\utils\SkullType;
|
||||
use pocketmine\block\utils\SlabType;
|
||||
use pocketmine\block\utils\StairShape;
|
||||
use pocketmine\block\utils\TreeType;
|
||||
|
||||
final class BlockDataReaderHelper{
|
||||
|
||||
public static function readBellAttachmentType(BlockDataReader $r) : BellAttachmentType{
|
||||
return match($r->readInt(2)){
|
||||
0 => \pocketmine\block\utils\BellAttachmentType::CEILING(),
|
||||
1 => \pocketmine\block\utils\BellAttachmentType::FLOOR(),
|
||||
2 => \pocketmine\block\utils\BellAttachmentType::ONE_WALL(),
|
||||
3 => \pocketmine\block\utils\BellAttachmentType::TWO_WALLS(),
|
||||
default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for BellAttachmentType")
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \pocketmine\block\utils\BrewingStandSlot[]
|
||||
* @phpstan-return array<int, \pocketmine\block\utils\BrewingStandSlot>
|
||||
*/
|
||||
public static function readBrewingStandSlotKeySet(BlockDataReader $r) : array{
|
||||
$result = [];
|
||||
foreach([
|
||||
\pocketmine\block\utils\BrewingStandSlot::EAST(),
|
||||
\pocketmine\block\utils\BrewingStandSlot::NORTHWEST(),
|
||||
\pocketmine\block\utils\BrewingStandSlot::SOUTHWEST(),
|
||||
] as $member){
|
||||
if($r->readBool()){
|
||||
$result[$member->id()] = $member;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function readCoralType(BlockDataReader $r) : CoralType{
|
||||
return match($r->readInt(3)){
|
||||
0 => \pocketmine\block\utils\CoralType::BRAIN(),
|
||||
1 => \pocketmine\block\utils\CoralType::BUBBLE(),
|
||||
2 => \pocketmine\block\utils\CoralType::FIRE(),
|
||||
3 => \pocketmine\block\utils\CoralType::HORN(),
|
||||
4 => \pocketmine\block\utils\CoralType::TUBE(),
|
||||
default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for CoralType")
|
||||
};
|
||||
}
|
||||
|
||||
public static function readDyeColor(BlockDataReader $r) : DyeColor{
|
||||
return match($r->readInt(4)){
|
||||
0 => \pocketmine\block\utils\DyeColor::BLACK(),
|
||||
1 => \pocketmine\block\utils\DyeColor::BLUE(),
|
||||
2 => \pocketmine\block\utils\DyeColor::BROWN(),
|
||||
3 => \pocketmine\block\utils\DyeColor::CYAN(),
|
||||
4 => \pocketmine\block\utils\DyeColor::GRAY(),
|
||||
5 => \pocketmine\block\utils\DyeColor::GREEN(),
|
||||
6 => \pocketmine\block\utils\DyeColor::LIGHT_BLUE(),
|
||||
7 => \pocketmine\block\utils\DyeColor::LIGHT_GRAY(),
|
||||
8 => \pocketmine\block\utils\DyeColor::LIME(),
|
||||
9 => \pocketmine\block\utils\DyeColor::MAGENTA(),
|
||||
10 => \pocketmine\block\utils\DyeColor::ORANGE(),
|
||||
11 => \pocketmine\block\utils\DyeColor::PINK(),
|
||||
12 => \pocketmine\block\utils\DyeColor::PURPLE(),
|
||||
13 => \pocketmine\block\utils\DyeColor::RED(),
|
||||
14 => \pocketmine\block\utils\DyeColor::WHITE(),
|
||||
15 => \pocketmine\block\utils\DyeColor::YELLOW(),
|
||||
default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for DyeColor")
|
||||
};
|
||||
}
|
||||
|
||||
public static function readLeverFacing(BlockDataReader $r) : LeverFacing{
|
||||
return match($r->readInt(3)){
|
||||
0 => \pocketmine\block\utils\LeverFacing::DOWN_AXIS_X(),
|
||||
1 => \pocketmine\block\utils\LeverFacing::DOWN_AXIS_Z(),
|
||||
2 => \pocketmine\block\utils\LeverFacing::EAST(),
|
||||
3 => \pocketmine\block\utils\LeverFacing::NORTH(),
|
||||
4 => \pocketmine\block\utils\LeverFacing::SOUTH(),
|
||||
5 => \pocketmine\block\utils\LeverFacing::UP_AXIS_X(),
|
||||
6 => \pocketmine\block\utils\LeverFacing::UP_AXIS_Z(),
|
||||
7 => \pocketmine\block\utils\LeverFacing::WEST(),
|
||||
default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for LeverFacing")
|
||||
};
|
||||
}
|
||||
|
||||
public static function readMushroomBlockType(BlockDataReader $r) : MushroomBlockType{
|
||||
return match($r->readInt(4)){
|
||||
0 => \pocketmine\block\utils\MushroomBlockType::ALL_CAP(),
|
||||
1 => \pocketmine\block\utils\MushroomBlockType::CAP_EAST(),
|
||||
2 => \pocketmine\block\utils\MushroomBlockType::CAP_MIDDLE(),
|
||||
3 => \pocketmine\block\utils\MushroomBlockType::CAP_NORTH(),
|
||||
4 => \pocketmine\block\utils\MushroomBlockType::CAP_NORTHEAST(),
|
||||
5 => \pocketmine\block\utils\MushroomBlockType::CAP_NORTHWEST(),
|
||||
6 => \pocketmine\block\utils\MushroomBlockType::CAP_SOUTH(),
|
||||
7 => \pocketmine\block\utils\MushroomBlockType::CAP_SOUTHEAST(),
|
||||
8 => \pocketmine\block\utils\MushroomBlockType::CAP_SOUTHWEST(),
|
||||
9 => \pocketmine\block\utils\MushroomBlockType::CAP_WEST(),
|
||||
10 => \pocketmine\block\utils\MushroomBlockType::PORES(),
|
||||
default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for MushroomBlockType")
|
||||
};
|
||||
}
|
||||
|
||||
public static function readSkullType(BlockDataReader $r) : SkullType{
|
||||
return match($r->readInt(3)){
|
||||
0 => \pocketmine\block\utils\SkullType::CREEPER(),
|
||||
1 => \pocketmine\block\utils\SkullType::DRAGON(),
|
||||
2 => \pocketmine\block\utils\SkullType::PLAYER(),
|
||||
3 => \pocketmine\block\utils\SkullType::SKELETON(),
|
||||
4 => \pocketmine\block\utils\SkullType::WITHER_SKELETON(),
|
||||
5 => \pocketmine\block\utils\SkullType::ZOMBIE(),
|
||||
default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for SkullType")
|
||||
};
|
||||
}
|
||||
|
||||
public static function readSlabType(BlockDataReader $r) : SlabType{
|
||||
return match($r->readInt(2)){
|
||||
0 => \pocketmine\block\utils\SlabType::BOTTOM(),
|
||||
1 => \pocketmine\block\utils\SlabType::DOUBLE(),
|
||||
2 => \pocketmine\block\utils\SlabType::TOP(),
|
||||
default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for SlabType")
|
||||
};
|
||||
}
|
||||
|
||||
public static function readStairShape(BlockDataReader $r) : StairShape{
|
||||
return match($r->readInt(3)){
|
||||
0 => \pocketmine\block\utils\StairShape::INNER_LEFT(),
|
||||
1 => \pocketmine\block\utils\StairShape::INNER_RIGHT(),
|
||||
2 => \pocketmine\block\utils\StairShape::OUTER_LEFT(),
|
||||
3 => \pocketmine\block\utils\StairShape::OUTER_RIGHT(),
|
||||
4 => \pocketmine\block\utils\StairShape::STRAIGHT(),
|
||||
default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for StairShape")
|
||||
};
|
||||
}
|
||||
|
||||
public static function readTreeType(BlockDataReader $r) : TreeType{
|
||||
return match($r->readInt(3)){
|
||||
0 => \pocketmine\block\utils\TreeType::ACACIA(),
|
||||
1 => \pocketmine\block\utils\TreeType::BIRCH(),
|
||||
2 => \pocketmine\block\utils\TreeType::DARK_OAK(),
|
||||
3 => \pocketmine\block\utils\TreeType::JUNGLE(),
|
||||
4 => \pocketmine\block\utils\TreeType::OAK(),
|
||||
5 => \pocketmine\block\utils\TreeType::SPRUCE(),
|
||||
default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for TreeType")
|
||||
};
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user