Skip to content

Commit d7f3f00

Browse files
committed
Easy fixes
1 parent 9a2ee69 commit d7f3f00

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

src/entity/object/FireworkRocket.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class FireworkRocket extends Entity implements Explosive{
5151
public static function getNetworkTypeId() : string{ return EntityIds::FIREWORKS_ROCKET; }
5252

5353
/* Maximum number of ticks this will live for. */
54-
protected int $lifeTicks;
54+
protected int $maxAgeTicks;
5555

5656
/** @var FireworkRocketExplosion[] */
5757
protected array $explosions = [];
@@ -63,7 +63,7 @@ public function __construct(Location $location, int $lifeTicks, array $explosion
6363
if ($lifeTicks < 0) {
6464
throw new \InvalidArgumentException("Life ticks cannot be negative");
6565
}
66-
$this->lifeTicks = $lifeTicks;
66+
$this->maxAgeTicks = $lifeTicks;
6767
$this->setExplosions($explosions);
6868

6969
parent::__construct($location, $nbt);
@@ -78,20 +78,20 @@ protected function getInitialGravity() : float{ return 0.0; }
7878
/**
7979
* Returns maximum number of ticks this will live for.
8080
*/
81-
public function getLifeTicks() : int{
82-
return $this->lifeTicks;
81+
public function getMaxAgeTicks() : int{
82+
return $this->maxAgeTicks;
8383
}
8484

8585
/**
8686
* Sets maximum number of ticks this will live for.
8787
*
8888
* @return $this
8989
*/
90-
public function setLifeTicks(int $lifeTicks) : self{
91-
if ($lifeTicks < 0) {
92-
throw new \InvalidArgumentException("Life ticks cannot be negative");
90+
public function setMaxAgeTicks(int $maxAgeTicks) : self{
91+
if ($maxAgeTicks < 0) {
92+
throw new \InvalidArgumentException("Max age ticks cannot be negative");
9393
}
94-
$this->lifeTicks = $lifeTicks;
94+
$this->maxAgeTicks = $maxAgeTicks;
9595
return $this;
9696
}
9797

@@ -133,7 +133,7 @@ protected function entityBaseTick(int $tickDiff = 1) : bool{
133133
if(!$this->isFlaggedForDespawn()){
134134
$this->addMotion($this->motion->x * 0.15, 0.04, $this->motion->z * 0.15);
135135

136-
if($this->ticksLived >= $this->lifeTicks){
136+
if($this->ticksLived >= $this->maxAgeTicks){
137137
$this->flagForDespawn();
138138
$this->explode();
139139
}

src/item/FireworkRocket.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@
2727
use pocketmine\data\SavedDataLoadingException;
2828
use pocketmine\entity\Location;
2929
use pocketmine\entity\object\FireworkRocket as FireworkEntity;
30-
use pocketmine\math\Facing;
3130
use pocketmine\math\Vector3;
3231
use pocketmine\nbt\tag\CompoundTag;
3332
use pocketmine\nbt\tag\ListTag;
3433
use pocketmine\player\Player;
35-
use pocketmine\utils\AssumptionFailedError;
3634
use pocketmine\utils\Utils;
3735
use function lcg_value;
3836
use function mt_rand;
@@ -95,17 +93,8 @@ public function setExplosions(array $explosions) : self{
9593
}
9694

9795
public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{
98-
$correction = 0.15;
99-
$position = $blockClicked->getPosition()->addVector($clickVector);
100-
$position = match($face){
101-
Facing::DOWN => $position->add(0, -$correction, 0),
102-
Facing::UP => $position->add(0, $correction, 0),
103-
Facing::NORTH => $position->add(0, 0, -$correction),
104-
Facing::SOUTH => $position->add(0, 0, $correction),
105-
Facing::WEST => $position->add(-$correction, 0, 0),
106-
Facing::EAST => $position->add($correction, 0, 0),
107-
default => throw new AssumptionFailedError("Invalid facing $face")
108-
};
96+
//TODO: this would be nicer if Vector3::getSide() accepted floats for distance
97+
$position = $blockClicked->getPosition()->addVector($clickVector)->addVector(Vector3::zero()->getSide($face)->multiply(0.15));
10998

11099
$randomDuration = (($this->flightDurationMultiplier + 1) * 10) + mt_rand(0, 12);
111100

src/item/FireworkRocketExplosion.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class FireworkRocketExplosion{
4343
protected const TAG_TWINKLE = "FireworkFlicker"; //TAG_Byte
4444
protected const TAG_TRAIL = "FireworkTrail"; //TAG_Byte
4545

46+
/**
47+
* @throws SavedDataLoadingException
48+
*/
4649
public static function fromCompoundTag(CompoundTag $tag) : self{
4750
$colors = self::decodeColors($tag->getByteArray(self::TAG_COLORS));
4851
if(count($colors) === 0){
@@ -61,6 +64,7 @@ public static function fromCompoundTag(CompoundTag $tag) : self{
6164
/**
6265
* @return DyeColor[]
6366
* @phpstan-return list<DyeColor>
67+
* @throws SavedDataLoadingException
6468
*/
6569
protected static function decodeColors(string $colorsBytes) : array{
6670
$colors = [];

src/item/FireworkStar.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ class FireworkStar extends Item{
4141
public function __construct(ItemIdentifier $identifier, string $name){
4242
parent::__construct($identifier, $name);
4343

44-
$this->explosion = new FireworkRocketExplosion(FireworkRocketType::SMALL_BALL, [DyeColor::BLACK], [], false, false);
44+
$this->explosion = new FireworkRocketExplosion(
45+
FireworkRocketType::SMALL_BALL,
46+
colors: [DyeColor::BLACK],
47+
fadeColors: [],
48+
twinkle: false,
49+
trail: false
50+
);
4551
}
4652

4753
public function getExplosion() : FireworkRocketExplosion{

0 commit comments

Comments
 (0)