mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-16 03:51:37 +00:00
Implement firework rocket & firework star (#5455)
Co-authored-by: Dylan T <dktapps@pmmp.io> Co-authored-by: ipad54 <63200545+ipad54@users.noreply.github.com>
This commit is contained in:
45
src/data/bedrock/FireworkRocketTypeIdMap.php
Normal file
45
src/data/bedrock/FireworkRocketTypeIdMap.php
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
src/data/bedrock/FireworkRocketTypeIds.php
Normal file
32
src/data/bedrock/FireworkRocketTypeIds.php
Normal file
@@ -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;
|
||||||
|
}
|
@@ -40,6 +40,7 @@ use pocketmine\data\bedrock\PotionTypeIdMap;
|
|||||||
use pocketmine\data\bedrock\SuspiciousStewTypeIdMap;
|
use pocketmine\data\bedrock\SuspiciousStewTypeIdMap;
|
||||||
use pocketmine\item\Banner;
|
use pocketmine\item\Banner;
|
||||||
use pocketmine\item\Dye;
|
use pocketmine\item\Dye;
|
||||||
|
use pocketmine\item\FireworkStar;
|
||||||
use pocketmine\item\GoatHorn;
|
use pocketmine\item\GoatHorn;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\Medicine;
|
use pocketmine\item\Medicine;
|
||||||
@@ -246,6 +247,7 @@ final class ItemSerializerDeserializerRegistrar{
|
|||||||
$this->map1to1Item(Ids::EYE_ARMOR_TRIM_SMITHING_TEMPLATE, Items::EYE_ARMOR_TRIM_SMITHING_TEMPLATE());
|
$this->map1to1Item(Ids::EYE_ARMOR_TRIM_SMITHING_TEMPLATE, Items::EYE_ARMOR_TRIM_SMITHING_TEMPLATE());
|
||||||
$this->map1to1Item(Ids::FEATHER, Items::FEATHER());
|
$this->map1to1Item(Ids::FEATHER, Items::FEATHER());
|
||||||
$this->map1to1Item(Ids::FERMENTED_SPIDER_EYE, Items::FERMENTED_SPIDER_EYE());
|
$this->map1to1Item(Ids::FERMENTED_SPIDER_EYE, Items::FERMENTED_SPIDER_EYE());
|
||||||
|
$this->map1to1Item(Ids::FIREWORK_ROCKET, Items::FIREWORK_ROCKET());
|
||||||
$this->map1to1Item(Ids::FIRE_CHARGE, Items::FIRE_CHARGE());
|
$this->map1to1Item(Ids::FIRE_CHARGE, Items::FIRE_CHARGE());
|
||||||
$this->map1to1Item(Ids::FISHING_ROD, Items::FISHING_ROD());
|
$this->map1to1Item(Ids::FISHING_ROD, Items::FISHING_ROD());
|
||||||
$this->map1to1Item(Ids::FLINT, Items::FLINT());
|
$this->map1to1Item(Ids::FLINT, Items::FLINT());
|
||||||
@@ -501,6 +503,14 @@ final class ItemSerializerDeserializerRegistrar{
|
|||||||
* in a unified manner.
|
* in a unified manner.
|
||||||
*/
|
*/
|
||||||
private function register1to1ItemWithMetaMappings() : void{
|
private function register1to1ItemWithMetaMappings() : void{
|
||||||
|
$this->map1to1ItemWithMeta(
|
||||||
|
Ids::FIREWORK_STAR,
|
||||||
|
Items::FIREWORK_STAR(),
|
||||||
|
function(FireworkStar $item, int $meta) : void{
|
||||||
|
// Colors will be defined by CompoundTag deserialization.
|
||||||
|
},
|
||||||
|
fn(FireworkStar $item) => DyeColorIdMap::getInstance()->toInvertedId($item->getExplosion()->getFlashColor())
|
||||||
|
);
|
||||||
$this->map1to1ItemWithMeta(
|
$this->map1to1ItemWithMeta(
|
||||||
Ids::GOAT_HORN,
|
Ids::GOAT_HORN,
|
||||||
Items::GOAT_HORN(),
|
Items::GOAT_HORN(),
|
||||||
|
41
src/entity/animation/FireworkParticlesAnimation.php
Normal file
41
src/entity/animation/FireworkParticlesAnimation.php
Normal file
@@ -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)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
204
src/entity/object/FireworkRocket.php
Normal file
204
src/entity/object/FireworkRocket.php
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
<?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\entity\NeverSavedWithChunkEntity;
|
||||||
|
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, NeverSavedWithChunkEntity{
|
||||||
|
|
||||||
|
public static function getNetworkTypeId() : string{ return EntityIds::FIREWORKS_ROCKET; }
|
||||||
|
|
||||||
|
protected int $maxFlightTimeTicks;
|
||||||
|
|
||||||
|
/** @var FireworkRocketExplosion[] */
|
||||||
|
protected array $explosions = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param FireworkRocketExplosion[] $explosions
|
||||||
|
*/
|
||||||
|
public function __construct(Location $location, int $maxFlightTimeTicks, array $explosions, ?CompoundTag $nbt = null){
|
||||||
|
if($maxFlightTimeTicks < 0){
|
||||||
|
throw new \InvalidArgumentException("Life ticks cannot be negative");
|
||||||
|
}
|
||||||
|
$this->maxFlightTimeTicks = $maxFlightTimeTicks;
|
||||||
|
$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 the total number of ticks the firework will fly for before it explodes.
|
||||||
|
*/
|
||||||
|
public function getMaxFlightTimeTicks() : int{
|
||||||
|
return $this->maxFlightTimeTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the total number of ticks the firework will fly for before it explodes.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setMaxFlightTimeTicks(int $maxFlightTimeTicks) : self{
|
||||||
|
if($maxFlightTimeTicks < 0){
|
||||||
|
throw new \InvalidArgumentException("Max flight time ticks cannot be negative");
|
||||||
|
}
|
||||||
|
$this->maxFlightTimeTicks = $maxFlightTimeTicks;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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()){
|
||||||
|
//Don't keep accelerating long-lived fireworks - this gets very rapidly out of control and makes the server
|
||||||
|
//die. Vanilla fireworks will only live for about 52 ticks maximum anyway, so this only makes sure plugin
|
||||||
|
//created fireworks don't murder the server
|
||||||
|
if($this->ticksLived < 60){
|
||||||
|
$this->addMotion($this->motion->x * 0.15, 0.04, $this->motion->z * 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->ticksLived >= $this->maxFlightTimeTicks){
|
||||||
|
$this->flagForDespawn();
|
||||||
|
$this->explode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $hasUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function explode() : void{
|
||||||
|
if(($explosionCount = 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 = ($explosionCount * 2) + 5;
|
||||||
|
$world = $this->getWorld();
|
||||||
|
foreach($world->getCollidingEntities($this->getBoundingBox()->expandedCopy(5, 5, 5), $this) as $entity){
|
||||||
|
if(!$entity instanceof Living){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$position = $entity->getPosition();
|
||||||
|
$distance = $position->distanceSquared($this->location);
|
||||||
|
if($distance > 25){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//cast two rays - one to the entity's feet and another to halfway up its body (according to Java, anyway)
|
||||||
|
//this seems like it'd miss some cases but who am I to argue with vanilla logic :>
|
||||||
|
$height = $entity->getBoundingBox()->getYLength();
|
||||||
|
for($i = 0; $i < 2; $i++){
|
||||||
|
$target = $position->add(0, 0.5 * $i * $height, 0);
|
||||||
|
foreach(VoxelRayTrace::betweenPoints($this->location, $target) as $blockPos){
|
||||||
|
if($world->getBlock($blockPos)->calculateIntercept($this->location, $target) !== null){
|
||||||
|
continue 2; //obstruction, try another path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//no obstruction
|
||||||
|
$damage = $force * sqrt((5 - $position->distance($this->location)) / 5);
|
||||||
|
$ev = new EntityDamageByEntityEvent($this, $entity, EntityDamageEvent::CAUSE_ENTITY_EXPLOSION, $damage);
|
||||||
|
$entity->attack($ev);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
@@ -26,6 +26,7 @@ namespace pocketmine\event\player;
|
|||||||
use pocketmine\block\BlockTypeIds;
|
use pocketmine\block\BlockTypeIds;
|
||||||
use pocketmine\entity\Living;
|
use pocketmine\entity\Living;
|
||||||
use pocketmine\entity\object\FallingBlock;
|
use pocketmine\entity\object\FallingBlock;
|
||||||
|
use pocketmine\entity\object\FireworkRocket;
|
||||||
use pocketmine\entity\projectile\Trident;
|
use pocketmine\entity\projectile\Trident;
|
||||||
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
||||||
use pocketmine\event\entity\EntityDamageByChildEntityEvent;
|
use pocketmine\event\entity\EntityDamageByChildEntityEvent;
|
||||||
@@ -164,7 +165,9 @@ class PlayerDeathEvent extends EntityDeathEvent{
|
|||||||
case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION:
|
case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION:
|
||||||
if($deathCause instanceof EntityDamageByEntityEvent){
|
if($deathCause instanceof EntityDamageByEntityEvent){
|
||||||
$e = $deathCause->getDamager();
|
$e = $deathCause->getDamager();
|
||||||
if($e instanceof Living){
|
if($e instanceof FireworkRocket){
|
||||||
|
return KnownTranslationFactory::death_attack_fireworks($name);
|
||||||
|
}elseif($e instanceof Living){
|
||||||
return KnownTranslationFactory::death_attack_explosion_player($name, $e->getDisplayName());
|
return KnownTranslationFactory::death_attack_explosion_player($name, $e->getDisplayName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
141
src/item/FireworkRocket.php
Normal file
141
src/item/FireworkRocket.php
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
<?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\item;
|
||||||
|
|
||||||
|
use pocketmine\block\Block;
|
||||||
|
use pocketmine\data\SavedDataLoadingException;
|
||||||
|
use pocketmine\entity\Location;
|
||||||
|
use pocketmine\entity\object\FireworkRocket as FireworkEntity;
|
||||||
|
use pocketmine\math\Vector3;
|
||||||
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
|
use pocketmine\nbt\tag\ListTag;
|
||||||
|
use pocketmine\player\Player;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
|
use function array_map;
|
||||||
|
use function mt_rand;
|
||||||
|
|
||||||
|
class FireworkRocket extends Item{
|
||||||
|
|
||||||
|
public const TAG_FIREWORK_DATA = "Fireworks"; //TAG_Compound
|
||||||
|
protected const TAG_FLIGHT_TIME_MULTIPLIER = "Flight"; //TAG_Byte
|
||||||
|
public const TAG_EXPLOSIONS = "Explosions"; //TAG_List
|
||||||
|
|
||||||
|
protected int $flightTimeMultiplier = 1;
|
||||||
|
|
||||||
|
/** @var FireworkRocketExplosion[] */
|
||||||
|
protected array $explosions = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value that will be used to calculate a randomized flight duration
|
||||||
|
* for the firework (equals the amount of gunpowder used in crafting the rocket).
|
||||||
|
*
|
||||||
|
* The higher this value, the longer the flight duration.
|
||||||
|
*/
|
||||||
|
public function getFlightTimeMultiplier() : int{
|
||||||
|
return $this->flightTimeMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value that will be used to calculate a randomized flight duration
|
||||||
|
* for the firework.
|
||||||
|
*
|
||||||
|
* The higher this value, the longer the flight duration.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setFlightTimeMultiplier(int $multiplier) : self{
|
||||||
|
if($multiplier < 1 || $multiplier > 127){
|
||||||
|
throw new \InvalidArgumentException("Flight time multiplier must be in range 1-127");
|
||||||
|
}
|
||||||
|
$this->flightTimeMultiplier = $multiplier;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{
|
||||||
|
//TODO: this would be nicer if Vector3::getSide() accepted floats for distance
|
||||||
|
$position = $blockClicked->getPosition()->addVector($clickVector)->addVector(Vector3::zero()->getSide($face)->multiply(0.15));
|
||||||
|
|
||||||
|
$randomDuration = (($this->flightTimeMultiplier + 1) * 10) + mt_rand(0, 12);
|
||||||
|
|
||||||
|
$entity = new FireworkEntity(Location::fromObject($position, $player->getWorld(), Utils::getRandomFloat() * 360, 90), $randomDuration, $this->explosions);
|
||||||
|
$entity->setOwningEntity($player);
|
||||||
|
$entity->setMotion(new Vector3(
|
||||||
|
(Utils::getRandomFloat() - Utils::getRandomFloat()) * 0.0023,
|
||||||
|
0.05,
|
||||||
|
(Utils::getRandomFloat() - Utils::getRandomFloat()) * 0.0023
|
||||||
|
));
|
||||||
|
$entity->spawnToAll();
|
||||||
|
|
||||||
|
$this->pop();
|
||||||
|
|
||||||
|
return ItemUseResult::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function deserializeCompoundTag(CompoundTag $tag) : void{
|
||||||
|
parent::deserializeCompoundTag($tag);
|
||||||
|
|
||||||
|
$fireworkData = $tag->getCompoundTag(self::TAG_FIREWORK_DATA);
|
||||||
|
if($fireworkData === null){
|
||||||
|
throw new SavedDataLoadingException("Missing firework data");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setFlightTimeMultiplier($fireworkData->getByte(self::TAG_FLIGHT_TIME_MULTIPLIER, 1));
|
||||||
|
|
||||||
|
if(($explosions = $fireworkData->getListTag(self::TAG_EXPLOSIONS, CompoundTag::class)) !== null){
|
||||||
|
foreach($explosions as $explosion){
|
||||||
|
$this->explosions[] = FireworkRocketExplosion::fromCompoundTag($explosion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function serializeCompoundTag(CompoundTag $tag) : void{
|
||||||
|
parent::serializeCompoundTag($tag);
|
||||||
|
|
||||||
|
$fireworkData = CompoundTag::create();
|
||||||
|
$fireworkData->setByte(self::TAG_FLIGHT_TIME_MULTIPLIER, $this->flightTimeMultiplier);
|
||||||
|
$fireworkData->setTag(self::TAG_EXPLOSIONS, new ListTag(array_map(fn(FireworkRocketExplosion $e) => $e->toCompoundTag(), $this->explosions)));
|
||||||
|
|
||||||
|
$tag->setTag(self::TAG_FIREWORK_DATA, $fireworkData);
|
||||||
|
}
|
||||||
|
}
|
190
src/item/FireworkRocketExplosion.php
Normal file
190
src/item/FireworkRocketExplosion.php
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
<?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\item;
|
||||||
|
|
||||||
|
use pocketmine\block\utils\DyeColor;
|
||||||
|
use pocketmine\color\Color;
|
||||||
|
use pocketmine\data\bedrock\DyeColorIdMap;
|
||||||
|
use pocketmine\data\bedrock\FireworkRocketTypeIdMap;
|
||||||
|
use pocketmine\data\SavedDataLoadingException;
|
||||||
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
|
use function array_key_first;
|
||||||
|
use function chr;
|
||||||
|
use function count;
|
||||||
|
use function ord;
|
||||||
|
use function strlen;
|
||||||
|
|
||||||
|
class FireworkRocketExplosion{
|
||||||
|
|
||||||
|
protected const TAG_TYPE = "FireworkType"; //TAG_Byte
|
||||||
|
protected const TAG_COLORS = "FireworkColor"; //TAG_ByteArray
|
||||||
|
protected const TAG_FADE_COLORS = "FireworkFade"; //TAG_ByteArray
|
||||||
|
protected const TAG_TWINKLE = "FireworkFlicker"; //TAG_Byte
|
||||||
|
protected const TAG_TRAIL = "FireworkTrail"; //TAG_Byte
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SavedDataLoadingException
|
||||||
|
*/
|
||||||
|
public static function fromCompoundTag(CompoundTag $tag) : self{
|
||||||
|
$colors = self::decodeColors($tag->getByteArray(self::TAG_COLORS));
|
||||||
|
if(count($colors) === 0){
|
||||||
|
throw new SavedDataLoadingException("Colors list cannot be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new self(
|
||||||
|
FireworkRocketTypeIdMap::getInstance()->fromId($tag->getByte(self::TAG_TYPE)) ?? throw new SavedDataLoadingException("Invalid firework type"),
|
||||||
|
$colors,
|
||||||
|
self::decodeColors($tag->getByteArray(self::TAG_FADE_COLORS)),
|
||||||
|
$tag->getByte(self::TAG_TWINKLE, 0) !== 0,
|
||||||
|
$tag->getByte(self::TAG_TRAIL, 0) !== 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return DyeColor[]
|
||||||
|
* @phpstan-return list<DyeColor>
|
||||||
|
* @throws SavedDataLoadingException
|
||||||
|
*/
|
||||||
|
protected static function decodeColors(string $colorsBytes) : array{
|
||||||
|
$colors = [];
|
||||||
|
|
||||||
|
$dyeColorIdMap = DyeColorIdMap::getInstance();
|
||||||
|
for($i = 0, $len = strlen($colorsBytes); $i < $len; $i++){
|
||||||
|
$colorByte = ord($colorsBytes[$i]);
|
||||||
|
$color = $dyeColorIdMap->fromInvertedId($colorByte);
|
||||||
|
if($color !== null){
|
||||||
|
$colors[] = $color;
|
||||||
|
}else{
|
||||||
|
throw new SavedDataLoadingException("Unknown color $colorByte");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param DyeColor[] $colors
|
||||||
|
*/
|
||||||
|
protected static function encodeColors(array $colors) : string{
|
||||||
|
$colorsBytes = "";
|
||||||
|
|
||||||
|
$dyeColorIdMap = DyeColorIdMap::getInstance();
|
||||||
|
foreach($colors as $color){
|
||||||
|
$colorsBytes .= chr($dyeColorIdMap->toInvertedId($color));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $colorsBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param DyeColor[] $colors
|
||||||
|
* @param DyeColor[] $fadeColors
|
||||||
|
* @phpstan-param non-empty-list<DyeColor> $colors
|
||||||
|
* @phpstan-param list<DyeColor> $fadeColors
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
protected FireworkRocketType $type,
|
||||||
|
protected array $colors,
|
||||||
|
protected array $fadeColors = [],
|
||||||
|
protected bool $twinkle = false,
|
||||||
|
protected bool $trail = false
|
||||||
|
){
|
||||||
|
if(count($colors) === 0){
|
||||||
|
throw new \InvalidArgumentException("Colors list cannot be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
$colorsValidator = function(DyeColor $_) : void{};
|
||||||
|
|
||||||
|
Utils::validateArrayValueType($colors, $colorsValidator);
|
||||||
|
Utils::validateArrayValueType($fadeColors, $colorsValidator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType() : FireworkRocketType{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the colors of the particles.
|
||||||
|
*
|
||||||
|
* @return DyeColor[]
|
||||||
|
* @phpstan-return non-empty-list<DyeColor>
|
||||||
|
*/
|
||||||
|
public function getColors() : array{
|
||||||
|
return $this->colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the flash color of the explosion.
|
||||||
|
*/
|
||||||
|
public function getFlashColor() : DyeColor{
|
||||||
|
return $this->colors[array_key_first($this->colors)];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the mixure of colors from {@link FireworkRocketExplosion::getColors()})
|
||||||
|
*/
|
||||||
|
public function getColorMix() : Color{
|
||||||
|
/** @var Color[] $colors */
|
||||||
|
$colors = [];
|
||||||
|
foreach($this->colors as $dyeColor){
|
||||||
|
$colors[] = $dyeColor->getRgbValue();
|
||||||
|
}
|
||||||
|
return Color::mix(...$colors);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the colors to which the particles will change their color after a few seconds.
|
||||||
|
* If it is empty, there will be no color change in the particles.
|
||||||
|
*
|
||||||
|
* @return DyeColor[]
|
||||||
|
* @phpstan-return list<DyeColor>
|
||||||
|
*/
|
||||||
|
public function getFadeColors() : array{
|
||||||
|
return $this->fadeColors;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the explosion has a flickering effect.
|
||||||
|
*/
|
||||||
|
public function willTwinkle() : bool{
|
||||||
|
return $this->twinkle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the particles have a trail effect.
|
||||||
|
*/
|
||||||
|
public function getTrail() : bool{
|
||||||
|
return $this->trail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toCompoundTag() : CompoundTag{
|
||||||
|
return CompoundTag::create()
|
||||||
|
->setByte(self::TAG_TYPE, FireworkRocketTypeIdMap::getInstance()->toId($this->type))
|
||||||
|
->setByteArray(self::TAG_COLORS, self::encodeColors($this->colors))
|
||||||
|
->setByteArray(self::TAG_FADE_COLORS, self::encodeColors($this->fadeColors))
|
||||||
|
->setByte(self::TAG_TWINKLE, $this->twinkle ? 1 : 0)
|
||||||
|
->setByte(self::TAG_TRAIL, $this->trail ? 1 : 0);
|
||||||
|
}
|
||||||
|
}
|
46
src/item/FireworkRocketType.php
Normal file
46
src/item/FireworkRocketType.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?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\item;
|
||||||
|
|
||||||
|
use pocketmine\world\sound\FireworkExplosionSound;
|
||||||
|
use pocketmine\world\sound\FireworkLargeExplosionSound;
|
||||||
|
use pocketmine\world\sound\Sound;
|
||||||
|
|
||||||
|
enum FireworkRocketType{
|
||||||
|
case SMALL_BALL;
|
||||||
|
case LARGE_BALL;
|
||||||
|
case STAR;
|
||||||
|
case CREEPER;
|
||||||
|
case BURST;
|
||||||
|
|
||||||
|
public function getExplosionSound() : Sound{
|
||||||
|
return match($this){
|
||||||
|
self::SMALL_BALL,
|
||||||
|
self::STAR,
|
||||||
|
self::CREEPER,
|
||||||
|
self::BURST => new FireworkExplosionSound(),
|
||||||
|
self::LARGE_BALL => new FireworkLargeExplosionSound(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
112
src/item/FireworkStar.php
Normal file
112
src/item/FireworkStar.php
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
<?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\item;
|
||||||
|
|
||||||
|
use pocketmine\block\utils\DyeColor;
|
||||||
|
use pocketmine\color\Color;
|
||||||
|
use pocketmine\data\SavedDataLoadingException;
|
||||||
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
|
use pocketmine\utils\Binary;
|
||||||
|
|
||||||
|
class FireworkStar extends Item{
|
||||||
|
|
||||||
|
protected const TAG_EXPLOSION = "FireworksItem"; //TAG_Compound
|
||||||
|
protected const TAG_CUSTOM_COLOR = "customColor"; //TAG_Int
|
||||||
|
|
||||||
|
protected FireworkRocketExplosion $explosion;
|
||||||
|
|
||||||
|
protected ?Color $customColor = null;
|
||||||
|
|
||||||
|
public function __construct(ItemIdentifier $identifier, string $name){
|
||||||
|
parent::__construct($identifier, $name);
|
||||||
|
|
||||||
|
$this->explosion = new FireworkRocketExplosion(
|
||||||
|
FireworkRocketType::SMALL_BALL,
|
||||||
|
colors: [DyeColor::BLACK],
|
||||||
|
fadeColors: [],
|
||||||
|
twinkle: false,
|
||||||
|
trail: false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getExplosion() : FireworkRocketExplosion{
|
||||||
|
return $this->explosion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return $this */
|
||||||
|
public function setExplosion(FireworkRocketExplosion $explosion) : self{
|
||||||
|
$this->explosion = $explosion;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the displayed color of the item.
|
||||||
|
* The mixture of explosion colors, or the custom color if it is set.
|
||||||
|
*/
|
||||||
|
public function getColor() : Color{
|
||||||
|
return $this->customColor ?? $this->explosion->getColorMix();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the displayed custom color of the item that overrides
|
||||||
|
* the mixture of explosion colors, or null is it is not set.
|
||||||
|
*/
|
||||||
|
public function getCustomColor() : ?Color{
|
||||||
|
return $this->customColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the displayed custom color of the item that overrides
|
||||||
|
* the mixture of explosion colors, or removes if $color is null.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setCustomColor(?Color $color) : self{
|
||||||
|
$this->customColor = $color;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function deserializeCompoundTag(CompoundTag $tag) : void{
|
||||||
|
parent::deserializeCompoundTag($tag);
|
||||||
|
|
||||||
|
$explosionTag = $tag->getTag(self::TAG_EXPLOSION);
|
||||||
|
if(!$explosionTag instanceof CompoundTag){
|
||||||
|
throw new SavedDataLoadingException("Missing explosion data");
|
||||||
|
}
|
||||||
|
$this->explosion = FireworkRocketExplosion::fromCompoundTag($explosionTag);
|
||||||
|
|
||||||
|
$customColor = Color::fromARGB(Binary::unsignInt($tag->getInt(self::TAG_CUSTOM_COLOR)));
|
||||||
|
$color = $this->explosion->getColorMix();
|
||||||
|
if(!$customColor->equals($color)){ //check that $customColor is actually custom.
|
||||||
|
$this->customColor = $customColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function serializeCompoundTag(CompoundTag $tag) : void{
|
||||||
|
parent::serializeCompoundTag($tag);
|
||||||
|
|
||||||
|
$tag->setTag(self::TAG_EXPLOSION, $this->explosion->toCompoundTag());
|
||||||
|
$tag->setInt(self::TAG_CUSTOM_COLOR, Binary::signInt($this->getColor()->toARGB()));
|
||||||
|
}
|
||||||
|
}
|
@@ -347,8 +347,10 @@ final class ItemTypeIds{
|
|||||||
public const SPRUCE_HANGING_SIGN = 20308;
|
public const SPRUCE_HANGING_SIGN = 20308;
|
||||||
public const WARPED_HANGING_SIGN = 20309;
|
public const WARPED_HANGING_SIGN = 20309;
|
||||||
public const TRIDENT = 20310;
|
public const TRIDENT = 20310;
|
||||||
|
public const FIREWORK_ROCKET = 20311;
|
||||||
|
public const FIREWORK_STAR = 20312;
|
||||||
|
|
||||||
public const FIRST_UNUSED_ITEM_ID = 20311;
|
public const FIRST_UNUSED_ITEM_ID = 20313;
|
||||||
|
|
||||||
private static int $nextDynamicId = self::FIRST_UNUSED_ITEM_ID;
|
private static int $nextDynamicId = self::FIRST_UNUSED_ITEM_ID;
|
||||||
|
|
||||||
|
@@ -1366,6 +1366,9 @@ final class StringToItemParser extends StringToTParser{
|
|||||||
$result->register("eye_drops", fn() => Items::MEDICINE()->setType(MedicineType::EYE_DROPS));
|
$result->register("eye_drops", fn() => Items::MEDICINE()->setType(MedicineType::EYE_DROPS));
|
||||||
$result->register("feather", fn() => Items::FEATHER());
|
$result->register("feather", fn() => Items::FEATHER());
|
||||||
$result->register("fermented_spider_eye", fn() => Items::FERMENTED_SPIDER_EYE());
|
$result->register("fermented_spider_eye", fn() => Items::FERMENTED_SPIDER_EYE());
|
||||||
|
$result->register("firework_rocket", fn() => Items::FIREWORK_ROCKET());
|
||||||
|
$result->register("firework_star", fn() => Items::FIREWORK_STAR());
|
||||||
|
$result->register("fireworks", fn() => Items::FIREWORK_ROCKET());
|
||||||
$result->register("fire_charge", fn() => Items::FIRE_CHARGE());
|
$result->register("fire_charge", fn() => Items::FIRE_CHARGE());
|
||||||
$result->register("fish", fn() => Items::RAW_FISH());
|
$result->register("fish", fn() => Items::RAW_FISH());
|
||||||
$result->register("fishing_rod", fn() => Items::FISHING_ROD());
|
$result->register("fishing_rod", fn() => Items::FISHING_ROD());
|
||||||
|
@@ -168,6 +168,8 @@ use function strtolower;
|
|||||||
* @method static Item EYE_ARMOR_TRIM_SMITHING_TEMPLATE()
|
* @method static Item EYE_ARMOR_TRIM_SMITHING_TEMPLATE()
|
||||||
* @method static Item FEATHER()
|
* @method static Item FEATHER()
|
||||||
* @method static Item FERMENTED_SPIDER_EYE()
|
* @method static Item FERMENTED_SPIDER_EYE()
|
||||||
|
* @method static FireworkRocket FIREWORK_ROCKET()
|
||||||
|
* @method static FireworkStar FIREWORK_STAR()
|
||||||
* @method static FireCharge FIRE_CHARGE()
|
* @method static FireCharge FIRE_CHARGE()
|
||||||
* @method static FishingRod FISHING_ROD()
|
* @method static FishingRod FISHING_ROD()
|
||||||
* @method static Item FLINT()
|
* @method static Item FLINT()
|
||||||
@@ -511,6 +513,8 @@ final class VanillaItems{
|
|||||||
self::register("experience_bottle", fn(IID $id) => new ExperienceBottle($id, "Bottle o' Enchanting"));
|
self::register("experience_bottle", fn(IID $id) => new ExperienceBottle($id, "Bottle o' Enchanting"));
|
||||||
self::register("feather", fn(IID $id) => new Item($id, "Feather"));
|
self::register("feather", fn(IID $id) => new Item($id, "Feather"));
|
||||||
self::register("fermented_spider_eye", fn(IID $id) => new Item($id, "Fermented Spider Eye"));
|
self::register("fermented_spider_eye", fn(IID $id) => new Item($id, "Fermented Spider Eye"));
|
||||||
|
self::register("firework_rocket", fn(IID $id) => new FireworkRocket($id, "Firework Rocket"));
|
||||||
|
self::register("firework_star", fn(IID $id) => new FireworkStar($id, "Firework Star"));
|
||||||
self::register("fire_charge", fn(IID $id) => new FireCharge($id, "Fire Charge"));
|
self::register("fire_charge", fn(IID $id) => new FireCharge($id, "Fire Charge"));
|
||||||
self::register("fishing_rod", fn(IID $id) => new FishingRod($id, "Fishing Rod", [EnchantmentTags::FISHING_ROD]));
|
self::register("fishing_rod", fn(IID $id) => new FishingRod($id, "Fishing Rod", [EnchantmentTags::FISHING_ROD]));
|
||||||
self::register("flint", fn(IID $id) => new Item($id, "Flint"));
|
self::register("flint", fn(IID $id) => new Item($id, "Flint"));
|
||||||
|
35
src/world/sound/FireworkCrackleSound.php
Normal file
35
src/world/sound/FireworkCrackleSound.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?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\world\sound;
|
||||||
|
|
||||||
|
use pocketmine\math\Vector3;
|
||||||
|
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||||
|
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
|
||||||
|
|
||||||
|
class FireworkCrackleSound implements Sound{
|
||||||
|
|
||||||
|
public function encode(Vector3 $pos) : array{
|
||||||
|
return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::TWINKLE, $pos, false)];
|
||||||
|
}
|
||||||
|
}
|
35
src/world/sound/FireworkExplosionSound.php
Normal file
35
src/world/sound/FireworkExplosionSound.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?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\world\sound;
|
||||||
|
|
||||||
|
use pocketmine\math\Vector3;
|
||||||
|
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||||
|
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
|
||||||
|
|
||||||
|
class FireworkExplosionSound implements Sound{
|
||||||
|
|
||||||
|
public function encode(Vector3 $pos) : array{
|
||||||
|
return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::BLAST, $pos, false)];
|
||||||
|
}
|
||||||
|
}
|
35
src/world/sound/FireworkLargeExplosionSound.php
Normal file
35
src/world/sound/FireworkLargeExplosionSound.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?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\world\sound;
|
||||||
|
|
||||||
|
use pocketmine\math\Vector3;
|
||||||
|
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||||
|
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
|
||||||
|
|
||||||
|
class FireworkLargeExplosionSound implements Sound{
|
||||||
|
|
||||||
|
public function encode(Vector3 $pos) : array{
|
||||||
|
return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::LARGE_BLAST, $pos, false)];
|
||||||
|
}
|
||||||
|
}
|
35
src/world/sound/FireworkLaunchSound.php
Normal file
35
src/world/sound/FireworkLaunchSound.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?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\world\sound;
|
||||||
|
|
||||||
|
use pocketmine\math\Vector3;
|
||||||
|
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||||
|
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
|
||||||
|
|
||||||
|
class FireworkLaunchSound implements Sound{
|
||||||
|
|
||||||
|
public function encode(Vector3 $pos) : array{
|
||||||
|
return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::LAUNCH, $pos, false)];
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user