mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-19 15:36:08 +00:00
RuntimeDataDescriber: Support dynamically describing arbitrary enums (#6039)
Previously, we were using codegen to support describing a fixed set of enums. Instead, we implement an enum() function, allowing any native PHP enum to be described. All enums used in runtime data have been migrated to native PHP 8.1 enums in minor-next to facilitate this. This implementation: - is faster (in extreme cases by 40x, such as with PotionType) - requires way less code - does not require a build step - is way more flexible This fixes #5877, increasing the range of stuff that plugins are now able to do. EnumTrait enums are not supported, as it's easier and cleaner to just support native enums. Most core EnumTrait enums have been migrated to native enums by now to facilitate this.
This commit is contained in:
@@ -58,7 +58,7 @@ class Banner extends ItemBlockWallOrFloor{
|
||||
}
|
||||
|
||||
protected function describeState(RuntimeDataDescriber $w) : void{
|
||||
$w->dyeColor($this->color);
|
||||
$w->enum($this->color);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -30,7 +30,7 @@ class Dye extends Item{
|
||||
private DyeColor $color = DyeColor::BLACK;
|
||||
|
||||
protected function describeState(RuntimeDataDescriber $w) : void{
|
||||
$w->dyeColor($this->color);
|
||||
$w->enum($this->color);
|
||||
}
|
||||
|
||||
public function getColor() : DyeColor{
|
||||
|
@@ -32,7 +32,7 @@ class Medicine extends Item implements ConsumableItem{
|
||||
private MedicineType $medicineType = MedicineType::EYE_DROPS;
|
||||
|
||||
protected function describeState(RuntimeDataDescriber $w) : void{
|
||||
$w->medicineType($this->medicineType);
|
||||
$w->enum($this->medicineType);
|
||||
}
|
||||
|
||||
public function getType() : MedicineType{ return $this->medicineType; }
|
||||
|
@@ -32,7 +32,7 @@ class Potion extends Item implements ConsumableItem{
|
||||
private PotionType $potionType = PotionType::WATER;
|
||||
|
||||
protected function describeState(RuntimeDataDescriber $w) : void{
|
||||
$w->potionType($this->potionType);
|
||||
$w->enum($this->potionType);
|
||||
}
|
||||
|
||||
public function getType() : PotionType{ return $this->potionType; }
|
||||
|
@@ -34,7 +34,7 @@ class SplashPotion extends ProjectileItem{
|
||||
private PotionType $potionType = PotionType::WATER;
|
||||
|
||||
protected function describeState(RuntimeDataDescriber $w) : void{
|
||||
$w->potionType($this->potionType);
|
||||
$w->enum($this->potionType);
|
||||
}
|
||||
|
||||
public function getType() : PotionType{ return $this->potionType; }
|
||||
|
@@ -30,7 +30,7 @@ class SuspiciousStew extends Food{
|
||||
private SuspiciousStewType $suspiciousStewType = SuspiciousStewType::POPPY;
|
||||
|
||||
protected function describeState(RuntimeDataDescriber $w) : void{
|
||||
$w->suspiciousStewType($this->suspiciousStewType);
|
||||
$w->enum($this->suspiciousStewType);
|
||||
}
|
||||
|
||||
public function getType() : SuspiciousStewType{ return $this->suspiciousStewType; }
|
||||
|
Reference in New Issue
Block a user