-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement firework rocket & firework star #5455
Open
IvanCraft623
wants to merge
63
commits into
pmmp:minor-next
Choose a base branch
from
IvanCraft623:firework
base: minor-next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 60 commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
ba76a33
Implement Firework Rocket & Firework Star
IvanCraft623 06a9da3
Fix PHPStan
IvanCraft623 bd83e99
Make PHPStan happy
IvanCraft623 58605e7
...
IvanCraft623 d01a8c3
Implement explosion multi-color & firework star custom color
IvanCraft623 fd04e93
Add TODO comment
IvanCraft623 15b1281
Some API improvements
IvanCraft623 a0a4ace
Make PHPStan happy
IvanCraft623 21f0edf
shut up!
IvanCraft623 ce28e49
Simplification
IvanCraft623 d4e8692
Firework types name parity with vanilla
IvanCraft623 d20f685
FireworkRocketTypeIdMap: fixed uninitialized fields
IvanCraft623 80557d7
oops
IvanCraft623 98291ec
Remove unused var
IvanCraft623 6e22547
Call parent::onFirstUpdate()
IvanCraft623 66a8145
Merge branch 'next-major' into firework
IvanCraft623 4f6f667
Merge branch 'next-major' into firework
IvanCraft623 0ce16d8
Implement firework death message
IvanCraft623 a4e412e
Implement Explosive interface
IvanCraft623 6c3522c
Merge branch 'major-next' into firework
IvanCraft623 bb7ca1e
Use `addMotion` instead of mutating the vector directly
IvanCraft623 ff080d7
Use appropriate constant for firework item metadata
IvanCraft623 c850a7e
Throw `SavedDataLoadingException` on finding an unknown color
IvanCraft623 15b4c95
Make `encodeColors` static and move it near to `decodeColors`
IvanCraft623 252cfd6
Fix typo on `getColorMix` doc
IvanCraft623 e2fbb8e
Remove useless closures for sound getter
IvanCraft623 e90f3ad
Better use the new `Color::equals()` method :P
IvanCraft623 5a50525
Remove `clearCustomColor()` in favour of passing `null` to `setCustom…
IvanCraft623 1df07e9
Merge branch 'firework' of https://github.com/IvanCraft623/PocketMine…
IvanCraft623 1122009
Fix little cs
IvanCraft623 291c086
Apply dylan's CS suggestion
IvanCraft623 0b710a2
Fix flight duaration range to wrap into a signed byte range
IvanCraft623 69501b2
Document flight duration
IvanCraft623 87504e4
Make FireworkRocket setters fluent
IvanCraft623 d093d22
Make FireworkRocketExplosion immutable
IvanCraft623 4139342
Use lists instead of arrays for PHPStan
IvanCraft623 12dc6b2
Improve FireworkRocketExplosion documentation
IvanCraft623 1a2715d
Rename getMainColor method
IvanCraft623 70d3d7a
Remove hasCustomColor() method
IvanCraft623 43ccb80
Improve FireworkStar documentation
IvanCraft623 07ffb21
Fix typo in TAG_FLIGH_DURATION
IvanCraft623 8e1b661
Rename `FireworkTwinkleSound` to `FireworkCrackleSound`
IvanCraft623 05e5565
Fix PHPStan lints
IvanCraft623 c4ce574
Remove unused import
IvanCraft623 7390c7f
Implement default values
IvanCraft623 1b0d74b
Fix tipo
IvanCraft623 5295e0c
Merge branch 'firework' of https://github.com/IvanCraft623/PocketMine…
IvanCraft623 0f32e84
Accept explosions instead of the whole item
IvanCraft623 9d08d9b
Update getFlightDuration and setFlightDuration
IvanCraft623 086eeea
Merge branch 'major-next' into firework
dktapps eff8d85
Rename flightDuration => flightDurationMultiplier
IvanCraft623 b1e8ceb
Rename $fireworksTag=> $fireworkData
IvanCraft623 3a0b96a
Merge branch 'minor-next' into firework
IvanCraft623 2437e64
Merge branch 'minor-next' into firework
dktapps 82b6ba9
Merge branch 'minor-next' into firework
IvanCraft623 fdbefd0
Don't flagForDespawn inside explode()
IvanCraft623 e6c52fd
Use of native enum case accessor
IvanCraft623 93147f0
Merge branch 'minor-next' into firework
IvanCraft623 8273978
Modernize the FireworkRocketType enum
IvanCraft623 d2b0fd5
Merge branch 'minor-next' into firework
IvanCraft623 609c4c6
Group some rocket types in a single case
IvanCraft623 60d9650
Merge branch 'minor-next' into firework
dktapps b112c59
Merge branch 'minor-next' into firework
IvanCraft623 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?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\item\FireworkRocketType; | ||
use pocketmine\utils\SingletonTrait; | ||
|
||
final class FireworkRocketTypeIdMap{ | ||
use SingletonTrait; | ||
/** @phpstan-use IntSaveIdMapTrait<FireworkRocketType> */ | ||
use IntSaveIdMapTrait; | ||
|
||
private function __construct(){ | ||
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?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; | ||
|
||
final class FireworkRocketTypeIds{ | ||
public const SMALL_BALL = 0; | ||
public const LARGE_BALL = 1; | ||
public const STAR = 2; | ||
public const CREEPER = 3; | ||
public const BURST = 4; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?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\entity\animation; | ||
|
||
use pocketmine\entity\object\FireworkRocket; | ||
use pocketmine\network\mcpe\protocol\ActorEventPacket; | ||
use pocketmine\network\mcpe\protocol\types\ActorEvent; | ||
|
||
final class FireworkParticlesAnimation implements Animation{ | ||
|
||
public function __construct( | ||
private FireworkRocket $entity | ||
){} | ||
|
||
public function encode() : array{ | ||
return [ | ||
ActorEventPacket::create($this->entity->getId(), ActorEvent::FIREWORK_PARTICLES, 0) | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
<?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\entity\object; | ||
|
||
use pocketmine\entity\animation\FireworkParticlesAnimation; | ||
use pocketmine\entity\Entity; | ||
use pocketmine\entity\EntitySizeInfo; | ||
use pocketmine\entity\Explosive; | ||
use pocketmine\entity\Living; | ||
use pocketmine\entity\Location; | ||
use pocketmine\event\entity\EntityDamageByEntityEvent; | ||
use pocketmine\event\entity\EntityDamageEvent; | ||
use pocketmine\item\FireworkRocket as FireworkItem; | ||
use pocketmine\item\FireworkRocketExplosion; | ||
use pocketmine\math\VoxelRayTrace; | ||
use pocketmine\nbt\tag\CompoundTag; | ||
use pocketmine\nbt\tag\ListTag; | ||
use pocketmine\network\mcpe\protocol\types\CacheableNbt; | ||
use pocketmine\network\mcpe\protocol\types\entity\EntityIds; | ||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection; | ||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties; | ||
use pocketmine\utils\Utils; | ||
use pocketmine\world\sound\FireworkCrackleSound; | ||
use pocketmine\world\sound\FireworkLaunchSound; | ||
use function count; | ||
use function sqrt; | ||
|
||
class FireworkRocket extends Entity implements Explosive{ | ||
|
||
public static function getNetworkTypeId() : string{ return EntityIds::FIREWORKS_ROCKET; } | ||
|
||
/* Maximum number of ticks this will live for. */ | ||
protected int $lifeTicks; | ||
|
||
/** @var FireworkRocketExplosion[] */ | ||
protected array $explosions = []; | ||
|
||
/** | ||
* @param FireworkRocketExplosion[] $explosions | ||
*/ | ||
public function __construct(Location $location, int $lifeTicks, array $explosions, ?CompoundTag $nbt = null){ | ||
if ($lifeTicks < 0) { | ||
throw new \InvalidArgumentException("Life ticks cannot be negative"); | ||
} | ||
$this->lifeTicks = $lifeTicks; | ||
$this->setExplosions($explosions); | ||
|
||
parent::__construct($location, $nbt); | ||
} | ||
|
||
protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.25, 0.25); } | ||
|
||
protected function getInitialDragMultiplier() : float{ return 0.0; } | ||
|
||
protected function getInitialGravity() : float{ return 0.0; } | ||
|
||
/** | ||
* Returns maximum number of ticks this will live for. | ||
*/ | ||
public function getLifeTicks() : int{ | ||
return $this->lifeTicks; | ||
} | ||
|
||
/** | ||
* Sets maximum number of ticks this will live for. | ||
* | ||
* @return $this | ||
*/ | ||
public function setLifeTicks(int $lifeTicks) : self{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto here |
||
if ($lifeTicks < 0) { | ||
throw new \InvalidArgumentException("Life ticks cannot be negative"); | ||
} | ||
$this->lifeTicks = $lifeTicks; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return FireworkRocketExplosion[] | ||
*/ | ||
public function getExplosions() : array{ | ||
return $this->explosions; | ||
} | ||
|
||
/** | ||
* @param FireworkRocketExplosion[] $explosions | ||
* | ||
* @return $this | ||
*/ | ||
public function setExplosions(array $explosions) : self{ | ||
Utils::validateArrayValueType($explosions, function(FireworkRocketExplosion $_) : void{}); | ||
$this->explosions = $explosions; | ||
return $this; | ||
} | ||
|
||
/** | ||
* TODO: The entity should be saved and loaded, but this is not possible. | ||
* @see https://bugs.mojang.com/browse/MCPE-165230 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not liking this. We should still save & restore them in PM, regardless of vanilla bugs that don't store them. |
||
*/ | ||
public function canSaveWithChunk() : bool{ | ||
return false; | ||
} | ||
|
||
protected function onFirstUpdate(int $currentTick) : void{ | ||
parent::onFirstUpdate($currentTick); | ||
|
||
$this->broadcastSound(new FireworkLaunchSound()); | ||
} | ||
|
||
protected function entityBaseTick(int $tickDiff = 1) : bool{ | ||
$hasUpdate = parent::entityBaseTick($tickDiff); | ||
|
||
if(!$this->isFlaggedForDespawn()){ | ||
$this->addMotion($this->motion->x * 0.15, 0.04, $this->motion->z * 0.15); | ||
|
||
if($this->ticksLived >= $this->lifeTicks){ | ||
$this->flagForDespawn(); | ||
$this->explode(); | ||
} | ||
} | ||
|
||
return $hasUpdate; | ||
} | ||
|
||
public function explode() : void{ | ||
if(($expCount = count($this->explosions)) !== 0){ | ||
$this->broadcastAnimation(new FireworkParticlesAnimation($this)); | ||
foreach($this->explosions as $explosion){ | ||
$this->broadcastSound($explosion->getType()->getExplosionSound()); | ||
if($explosion->willTwinkle()){ | ||
$this->broadcastSound(new FireworkCrackleSound()); | ||
} | ||
} | ||
|
||
$force = ($expCount * 2) + 5; | ||
foreach($this->getWorld()->getCollidingEntities($this->getBoundingBox()->expandedCopy(5, 5, 5), $this) as $entity){ | ||
if(!$entity instanceof Living){ | ||
continue; | ||
} | ||
|
||
$position = $entity->getEyePos(); | ||
$distance = $position->distance($this->location); | ||
if($distance > 5){ | ||
continue; | ||
} | ||
|
||
$world = $this->getWorld(); | ||
|
||
//check for obstructing blocks | ||
foreach(VoxelRayTrace::betweenPoints($this->location, $position) as $pos){ | ||
if($world->getBlockAt((int) $pos->x, (int) $pos->y, (int) $pos->z)->isSolid()){ | ||
continue 2; | ||
} | ||
} | ||
|
||
$ev = new EntityDamageByEntityEvent($this, $entity, EntityDamageEvent::CAUSE_ENTITY_EXPLOSION, $force * sqrt((5 - $distance) / 5)); | ||
$entity->attack($ev); | ||
} | ||
} | ||
} | ||
|
||
public function canBeCollidedWith() : bool{ | ||
return false; | ||
} | ||
|
||
protected function syncNetworkData(EntityMetadataCollection $properties) : void{ | ||
parent::syncNetworkData($properties); | ||
|
||
$explosions = new ListTag(); | ||
foreach($this->explosions as $explosion){ | ||
$explosions->push($explosion->toCompoundTag()); | ||
} | ||
$fireworksData = CompoundTag::create() | ||
->setTag(FireworkItem::TAG_FIREWORK_DATA, CompoundTag::create() | ||
->setTag(FireworkItem::TAG_EXPLOSIONS, $explosions) | ||
) | ||
; | ||
|
||
$properties->setCompoundTag(EntityMetadataProperties::FIREWORK_ITEM, new CacheableNbt($fireworksData)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getMaxAgeTicks()
would be more clear IMO