PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
FireworkStar.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\item;
25
26use pocketmine\block\utils\DyeColor;
31
32class FireworkStar extends Item{
33
34 protected const TAG_EXPLOSION = "FireworksItem"; //TAG_Compound
35 protected const TAG_CUSTOM_COLOR = "customColor"; //TAG_Int
36
37 protected FireworkRocketExplosion $explosion;
38
39 protected ?Color $customColor = null;
40
41 public function __construct(ItemIdentifier $identifier, string $name){
42 parent::__construct($identifier, $name);
43
44 $this->explosion = new FireworkRocketExplosion(
45 FireworkRocketType::SMALL_BALL,
46 colors: [DyeColor::BLACK],
47 fadeColors: [],
48 twinkle: false,
49 trail: false
50 );
51 }
52
53 public function getExplosion() : FireworkRocketExplosion{
54 return $this->explosion;
55 }
56
58 public function setExplosion(FireworkRocketExplosion $explosion) : self{
59 $this->explosion = $explosion;
60 return $this;
61 }
62
67 public function getColor() : Color{
68 return $this->customColor ?? $this->explosion->getColorMix();
69 }
70
75 public function getCustomColor() : ?Color{
76 return $this->customColor;
77 }
78
85 public function setCustomColor(?Color $color) : self{
86 $this->customColor = $color;
87 return $this;
88 }
89
90 protected function deserializeCompoundTag(CompoundTag $tag) : void{
91 parent::deserializeCompoundTag($tag);
92
93 $explosionTag = $tag->getTag(self::TAG_EXPLOSION);
94 if(!$explosionTag instanceof CompoundTag){
95 throw new SavedDataLoadingException("Missing explosion data");
96 }
97 $this->explosion = FireworkRocketExplosion::fromCompoundTag($explosionTag);
98
99 $customColor = Color::fromARGB(Binary::unsignInt($tag->getInt(self::TAG_CUSTOM_COLOR)));
100 $color = $this->explosion->getColorMix();
101 if(!$customColor->equals($color)){ //check that $customColor is actually custom.
102 $this->customColor = $customColor;
103 }
104 }
105
106 protected function serializeCompoundTag(CompoundTag $tag) : void{
107 parent::serializeCompoundTag($tag);
108
109 $tag->setTag(self::TAG_EXPLOSION, $this->explosion->toCompoundTag());
110 $tag->setInt(self::TAG_CUSTOM_COLOR, Binary::signInt($this->getColor()->toARGB()));
111 }
112}
equals(self $other)
Definition Color.php:129
setExplosion(FireworkRocketExplosion $explosion)
deserializeCompoundTag(CompoundTag $tag)