Skip to content

Commit

Permalink
migrate FireworkRocketType
Browse files Browse the repository at this point in the history
  • Loading branch information
dries-c committed Sep 26, 2023
1 parent b011589 commit 1a62c9b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 41 deletions.
10 changes: 5 additions & 5 deletions src/data/bedrock/FireworkRocketTypeIdMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ final class FireworkRocketTypeIdMap{
private array $enumToId = [];

private function __construct(){
$this->register(FireworkRocketTypeIds::SMALL_BALL, FireworkRocketType::SMALL_BALL());
$this->register(FireworkRocketTypeIds::LARGE_BALL, FireworkRocketType::LARGE_BALL());
$this->register(FireworkRocketTypeIds::STAR, FireworkRocketType::STAR());
$this->register(FireworkRocketTypeIds::CREEPER, FireworkRocketType::CREEPER());
$this->register(FireworkRocketTypeIds::BURST, FireworkRocketType::BURST());
$this->register(FireworkRocketTypeIds::SMALL_BALL, FireworkRocketType::SMALL_BALL);
$this->register(FireworkRocketTypeIds::LARGE_BALL, FireworkRocketType::LARGE_BALL);
$this->register(FireworkRocketTypeIds::STAR, FireworkRocketType::STAR);
$this->register(FireworkRocketTypeIds::CREEPER, FireworkRocketType::CREEPER);
$this->register(FireworkRocketTypeIds::BURST, FireworkRocketType::BURST);
}

private function register(int $id, FireworkRocketType $type) : void{
Expand Down
53 changes: 19 additions & 34 deletions src/item/FireworkRocketType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,31 @@

namespace pocketmine\item;

use pocketmine\utils\EnumTrait;
use pocketmine\utils\LegacyEnumShimTrait;
use pocketmine\world\sound\FireworkExplosionSound;
use pocketmine\world\sound\FireworkLargeExplosionSound;
use pocketmine\world\sound\Sound;
use function spl_object_id;

/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever registry members are added, removed or changed.
* @see build/generate-registry-annotations.php
* @generate-registry-docblock
*
* @method static FireworkRocketType BURST()
* @method static FireworkRocketType CREEPER()
* @method static FireworkRocketType LARGE_BALL()
* @method static FireworkRocketType SMALL_BALL()
* @method static FireworkRocketType STAR()
*/
final class FireworkRocketType{
use EnumTrait {
__construct as Enum___construct;
}
enum FireworkRocketType{
use LegacyEnumShimTrait;

protected static function setup() : void{
self::registerAll(
new self("small_ball", new FireworkExplosionSound()),
new self("large_ball", new FireworkLargeExplosionSound()),
new self("star", new FireworkExplosionSound()),
new self("creeper", new FireworkExplosionSound()),
new self("burst", new FireworkExplosionSound()),
);
}

private function __construct(
string $enumName,
private Sound $sound
){
$this->Enum___construct($enumName);
}
case SMALL_BALL;
case LARGE_BALL;
case STAR;
case CREEPER;
case BURST;

public function getSound() : Sound{
return $this->sound;
/** @phpstan-var array<int, Sound> $cache */
static $cache = [];

return $cache[spl_object_id($this)] ??= match($this){
self::SMALL_BALL => new FireworkExplosionSound(),
self::LARGE_BALL => new FireworkLargeExplosionSound(),
self::STAR => new FireworkExplosionSound(),
self::CREEPER => new FireworkExplosionSound(),
self::BURST => new FireworkExplosionSound(),
};
}
}
2 changes: 1 addition & 1 deletion src/item/FireworkStar.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class FireworkStar extends Item{
public function __construct(ItemIdentifier $identifier, string $name){
parent::__construct($identifier, $name);

$this->explosion = new FireworkRocketExplosion(FireworkRocketType::SMALL_BALL(), [DyeColor::BLACK], [], false, false);
$this->explosion = new FireworkRocketExplosion(FireworkRocketType::SMALL_BALL, [DyeColor::BLACK], [], false, false);
}

public function getExplosion() : FireworkRocketExplosion{
Expand Down
2 changes: 1 addition & 1 deletion src/network/mcpe/cache/CraftingDataCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private function buildCraftingDataCache(CraftingManager $manager) : CraftingData
}
}

foreach(FurnaceType::getAll() as $furnaceType){
foreach(FurnaceType::cases() as $furnaceType){
try{
$typeTag = match($furnaceType){
FurnaceType::FURNACE => FurnaceRecipeBlockName::FURNACE,
Expand Down

0 comments on commit 1a62c9b

Please sign in to comment.