Exterminate legacy item IDs

This commit is contained in:
Dylan K. Taylor
2022-07-05 15:12:55 +01:00
parent c5282b059b
commit 68cbe46600
19 changed files with 375 additions and 1180 deletions

View File

@@ -1,68 +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\bedrock;
use pocketmine\block\utils\CoralType;
use pocketmine\data\bedrock\block\BlockLegacyMetadata;
use pocketmine\utils\SingletonTrait;
use function array_key_exists;
final class CoralTypeIdMap{
use SingletonTrait;
/**
* @var CoralType[]
* @phpstan-var array<int, CoralType>
*/
private array $idToEnum = [];
/**
* @var int[]
* @phpstan-var array<int, int>
*/
private array $enumToId = [];
public function __construct(){
$this->register(BlockLegacyMetadata::CORAL_VARIANT_TUBE, CoralType::TUBE());
$this->register(BlockLegacyMetadata::CORAL_VARIANT_BRAIN, CoralType::BRAIN());
$this->register(BlockLegacyMetadata::CORAL_VARIANT_BUBBLE, CoralType::BUBBLE());
$this->register(BlockLegacyMetadata::CORAL_VARIANT_FIRE, CoralType::FIRE());
$this->register(BlockLegacyMetadata::CORAL_VARIANT_HORN, CoralType::HORN());
}
public function register(int $id, CoralType $type) : void{
$this->idToEnum[$id] = $type;
$this->enumToId[$type->id()] = $id;
}
public function fromId(int $id) : ?CoralType{
return $this->idToEnum[$id] ?? null;
}
public function toId(CoralType $type) : int{
if(!array_key_exists($type->id(), $this->enumToId)){
throw new \InvalidArgumentException("Coral type does not have a mapped ID"); //this should never happen
}
return $this->enumToId[$type->id()];
}
}

View File

@@ -103,6 +103,54 @@ final class RuntimeEnumDeserializer{
};
}
public static function readPotionType(RuntimeDataReader $r) : \pocketmine\item\PotionType{
return match($r->readInt(6)){
0 => \pocketmine\item\PotionType::AWKWARD(),
1 => \pocketmine\item\PotionType::FIRE_RESISTANCE(),
2 => \pocketmine\item\PotionType::HARMING(),
3 => \pocketmine\item\PotionType::HEALING(),
4 => \pocketmine\item\PotionType::INVISIBILITY(),
5 => \pocketmine\item\PotionType::LEAPING(),
6 => \pocketmine\item\PotionType::LONG_FIRE_RESISTANCE(),
7 => \pocketmine\item\PotionType::LONG_INVISIBILITY(),
8 => \pocketmine\item\PotionType::LONG_LEAPING(),
9 => \pocketmine\item\PotionType::LONG_MUNDANE(),
10 => \pocketmine\item\PotionType::LONG_NIGHT_VISION(),
11 => \pocketmine\item\PotionType::LONG_POISON(),
12 => \pocketmine\item\PotionType::LONG_REGENERATION(),
13 => \pocketmine\item\PotionType::LONG_SLOWNESS(),
14 => \pocketmine\item\PotionType::LONG_SLOW_FALLING(),
15 => \pocketmine\item\PotionType::LONG_STRENGTH(),
16 => \pocketmine\item\PotionType::LONG_SWIFTNESS(),
17 => \pocketmine\item\PotionType::LONG_TURTLE_MASTER(),
18 => \pocketmine\item\PotionType::LONG_WATER_BREATHING(),
19 => \pocketmine\item\PotionType::LONG_WEAKNESS(),
20 => \pocketmine\item\PotionType::MUNDANE(),
21 => \pocketmine\item\PotionType::NIGHT_VISION(),
22 => \pocketmine\item\PotionType::POISON(),
23 => \pocketmine\item\PotionType::REGENERATION(),
24 => \pocketmine\item\PotionType::SLOWNESS(),
25 => \pocketmine\item\PotionType::SLOW_FALLING(),
26 => \pocketmine\item\PotionType::STRENGTH(),
27 => \pocketmine\item\PotionType::STRONG_HARMING(),
28 => \pocketmine\item\PotionType::STRONG_HEALING(),
29 => \pocketmine\item\PotionType::STRONG_LEAPING(),
30 => \pocketmine\item\PotionType::STRONG_POISON(),
31 => \pocketmine\item\PotionType::STRONG_REGENERATION(),
32 => \pocketmine\item\PotionType::STRONG_STRENGTH(),
33 => \pocketmine\item\PotionType::STRONG_SWIFTNESS(),
34 => \pocketmine\item\PotionType::STRONG_TURTLE_MASTER(),
35 => \pocketmine\item\PotionType::SWIFTNESS(),
36 => \pocketmine\item\PotionType::THICK(),
37 => \pocketmine\item\PotionType::TURTLE_MASTER(),
38 => \pocketmine\item\PotionType::WATER(),
39 => \pocketmine\item\PotionType::WATER_BREATHING(),
40 => \pocketmine\item\PotionType::WEAKNESS(),
41 => \pocketmine\item\PotionType::WITHER(),
default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for PotionType")
};
}
public static function readSkullType(RuntimeDataReader $r) : \pocketmine\block\utils\SkullType{
return match($r->readInt(3)){
0 => \pocketmine\block\utils\SkullType::CREEPER(),

View File

@@ -103,6 +103,54 @@ final class RuntimeEnumSerializer{
});
}
public static function writePotionType(RuntimeDataWriter $w, \pocketmine\item\PotionType $value) : void{
$w->writeInt(6, match($value){
\pocketmine\item\PotionType::AWKWARD() => 0,
\pocketmine\item\PotionType::FIRE_RESISTANCE() => 1,
\pocketmine\item\PotionType::HARMING() => 2,
\pocketmine\item\PotionType::HEALING() => 3,
\pocketmine\item\PotionType::INVISIBILITY() => 4,
\pocketmine\item\PotionType::LEAPING() => 5,
\pocketmine\item\PotionType::LONG_FIRE_RESISTANCE() => 6,
\pocketmine\item\PotionType::LONG_INVISIBILITY() => 7,
\pocketmine\item\PotionType::LONG_LEAPING() => 8,
\pocketmine\item\PotionType::LONG_MUNDANE() => 9,
\pocketmine\item\PotionType::LONG_NIGHT_VISION() => 10,
\pocketmine\item\PotionType::LONG_POISON() => 11,
\pocketmine\item\PotionType::LONG_REGENERATION() => 12,
\pocketmine\item\PotionType::LONG_SLOWNESS() => 13,
\pocketmine\item\PotionType::LONG_SLOW_FALLING() => 14,
\pocketmine\item\PotionType::LONG_STRENGTH() => 15,
\pocketmine\item\PotionType::LONG_SWIFTNESS() => 16,
\pocketmine\item\PotionType::LONG_TURTLE_MASTER() => 17,
\pocketmine\item\PotionType::LONG_WATER_BREATHING() => 18,
\pocketmine\item\PotionType::LONG_WEAKNESS() => 19,
\pocketmine\item\PotionType::MUNDANE() => 20,
\pocketmine\item\PotionType::NIGHT_VISION() => 21,
\pocketmine\item\PotionType::POISON() => 22,
\pocketmine\item\PotionType::REGENERATION() => 23,
\pocketmine\item\PotionType::SLOWNESS() => 24,
\pocketmine\item\PotionType::SLOW_FALLING() => 25,
\pocketmine\item\PotionType::STRENGTH() => 26,
\pocketmine\item\PotionType::STRONG_HARMING() => 27,
\pocketmine\item\PotionType::STRONG_HEALING() => 28,
\pocketmine\item\PotionType::STRONG_LEAPING() => 29,
\pocketmine\item\PotionType::STRONG_POISON() => 30,
\pocketmine\item\PotionType::STRONG_REGENERATION() => 31,
\pocketmine\item\PotionType::STRONG_STRENGTH() => 32,
\pocketmine\item\PotionType::STRONG_SWIFTNESS() => 33,
\pocketmine\item\PotionType::STRONG_TURTLE_MASTER() => 34,
\pocketmine\item\PotionType::SWIFTNESS() => 35,
\pocketmine\item\PotionType::THICK() => 36,
\pocketmine\item\PotionType::TURTLE_MASTER() => 37,
\pocketmine\item\PotionType::WATER() => 38,
\pocketmine\item\PotionType::WATER_BREATHING() => 39,
\pocketmine\item\PotionType::WEAKNESS() => 40,
\pocketmine\item\PotionType::WITHER() => 41,
default => throw new \pocketmine\utils\AssumptionFailedError("All PotionType cases should be covered")
});
}
public static function writeSkullType(RuntimeDataWriter $w, \pocketmine\block\utils\SkullType $value) : void{
$w->writeInt(3, match($value){
\pocketmine\block\utils\SkullType::CREEPER() => 0,