Skip to content

Commit

Permalink
Some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DavyCraft648 committed Feb 7, 2024
1 parent 26bb706 commit dcf9e79
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 36 deletions.
1 change: 1 addition & 0 deletions src/block/utils/MinimumCostFlowCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public function getOptimalFlowDirections(int $originX, int $originY, int $origin
$this->flowCostVisited[World::blockHash($x, $y, $z)] = self::CAN_FLOW;
$opposite = Facing::opposite($j);
$flowCost[$j] = $this->calculateFlowCost($x, $y, $z, 1, $maxCost, $opposite, $opposite);
/** @phpstan-ignore-next-line */
$maxCost = min($maxCost, $flowCost[$j]);
}
}
Expand Down
42 changes: 10 additions & 32 deletions src/data/bedrock/FireworkRocketTypeIdMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,18 @@

final class FireworkRocketTypeIdMap{
use SingletonTrait;

/**
* @var FireworkRocketType[]
* @phpstan-var array<int, FireworkRocketType>
*/
private array $idToEnum = [];

/**
* @var int[]
* @phpstan-var array<int, int>
*/
private array $enumToId = [];
/** @phpstan-use IntSaveIdMapTrait<FireworkRocketType> */
use IntSaveIdMapTrait;

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);
}

private function register(int $id, FireworkRocketType $type) : void{
$this->idToEnum[$id] = $type;
$this->enumToId[$type->id()] = $id;
}

public function fromId(int $id) : ?FireworkRocketType{
return $this->idToEnum[$id] ?? null;
}

public function toId(FireworkRocketType $type) : int{
if(!isset($this->enumToId[$type->id()])){
throw new \InvalidArgumentException("Type does not have a mapped ID");
foreach(FireworkRocketType::cases() as $case){
$this->register(match($case){
FireworkRocketType::SMALL_BALL => FireworkRocketTypeIds::SMALL_BALL,
FireworkRocketType::LARGE_BALL => FireworkRocketTypeIds::LARGE_BALL,
FireworkRocketType::STAR => FireworkRocketTypeIds::STAR,
FireworkRocketType::CREEPER => FireworkRocketTypeIds::CREEPER,
FireworkRocketType::BURST => FireworkRocketTypeIds::BURST,
}, $case);
}
return $this->enumToId[$type->id()];
}
}
2 changes: 1 addition & 1 deletion src/entity/object/FireworkRocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

class FireworkRocket extends Entity implements Explosive{

public static function getNetworkTypeId() : string{ return EntityIds::FIREWORKS_ROCKET; }
public function getNetworkTypeId() : string{ return EntityIds::FIREWORKS_ROCKET; }

/* Maximum number of ticks this will live for. */
protected int $lifeTicks;
Expand Down
2 changes: 0 additions & 2 deletions src/item/FireworkRocketType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@

namespace pocketmine\item;

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

enum FireworkRocketType{
use LegacyEnumShimTrait;

case SMALL_BALL;
case LARGE_BALL;
Expand Down
2 changes: 1 addition & 1 deletion src/world/World.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class World implements ChunkManager{
*/
private array $changedBlocks = [];

/** @phpstan-var ReversePriorityQueue<int, Vector3> */
/** @phpstan-var ReversePriorityQueue<int, array{Vector3, int}> */
private ReversePriorityQueue $scheduledBlockUpdateQueue;
/**
* @var int[] blockHash => tick delay
Expand Down
15 changes: 15 additions & 0 deletions tests/phpstan/configs/actual-problems.neon
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,11 @@ parameters:
count: 1
path: ../../../src/world/World.php

-
message: "#^Parameter \\#1 \\$x of method pocketmine\\\\world\\\\World\\:\\:getBlockAtLayer\\(\\) expects int, float\\|int given\\.$#"
count: 1
path: ../../../src/world/World.php

-
message: "#^Parameter \\#1 \\$x of method pocketmine\\\\world\\\\World\\:\\:getTileAt\\(\\) expects int, float\\|int given\\.$#"
count: 1
Expand All @@ -950,6 +955,11 @@ parameters:
count: 1
path: ../../../src/world/World.php

-
message: "#^Parameter \\#2 \\$y of method pocketmine\\\\world\\\\World\\:\\:getBlockAtLayer\\(\\) expects int, float\\|int given\\.$#"
count: 1
path: ../../../src/world/World.php

-
message: "#^Parameter \\#2 \\$y of method pocketmine\\\\world\\\\World\\:\\:getTileAt\\(\\) expects int, float\\|int given\\.$#"
count: 1
Expand All @@ -975,6 +985,11 @@ parameters:
count: 1
path: ../../../src/world/World.php

-
message: "#^Parameter \\#3 \\$z of method pocketmine\\\\world\\\\World\\:\\:getBlockAtLayer\\(\\) expects int, float\\|int given\\.$#"
count: 1
path: ../../../src/world/World.php

-
message: "#^Parameter \\#3 \\$z of method pocketmine\\\\world\\\\World\\:\\:getTileAt\\(\\) expects int, float\\|int given\\.$#"
count: 1
Expand Down

0 comments on commit dcf9e79

Please sign in to comment.