How to spawn a firework

Discussion in 'Development' started by ZackyVN, Mar 3, 2019.

  1. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    131
    I want to spawn a firework with creeper face and green color but idk how. Please help.
     
  2. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    131
    Ok i tried but got this errors
    Code:
    [17:44:49] [Server thread/CRITICAL]: TypeError: "Argument 2 passed to pocketmine\entity\DataPropertyManager::setFloat() must be of the type float, null given, called in phar://C:/Users/Administrator/Desktop/Minecraft/AcidIsland - Pixelz/PocketMine-MP.phar/src/pocketmine/entity/Entity.php on line 581" (EXCEPTION) in "src/pocketmine/entity/DataPropertyManager" at line 119
    [17:44:49] [Server thread/DEBUG]: #0 src/pocketmine/entity/Entity(581): pocketmine\entity\DataPropertyManager->setFloat(integer 53, NULL )
    [17:44:49] [Server thread/DEBUG]: #1 plugins/AcidIsland_/src/MyPlot/subcommand/ClaimSubCommand(155): pocketmine\entity\Entity->__construct(pocketmine\level\Level object, pocketmine\nbt\tag\CompoundTag object)
    [17:44:49] [Server thread/DEBUG]: #2 plugins/AcidIsland_/src/MyPlot/subcommand/ClaimSubCommand(77): MyPlot\subcommand\ClaimSubCommand->Firework(pocketmine\Player object)
    [17:44:49] [Server thread/DEBUG]: #3 plugins/AcidIsland_/src/MyPlot/Commands(85): MyPlot\subcommand\ClaimSubCommand->execute(pocketmine\Player object, array Array())
    [17:44:49] [Server thread/DEBUG]: #4 src/pocketmine/command/SimpleCommandMap(270): MyPlot\Commands->execute(pocketmine\Player object, string ai, array Array())
    [17:44:49] [Server thread/DEBUG]: #5 src/pocketmine/Server(2029): pocketmine\command\SimpleCommandMap->dispatch(pocketmine\Player object, string ai claim)
    [17:44:49] [Server thread/DEBUG]: #6 src/pocketmine/Player(2219): pocketmine\Server->dispatchCommand(pocketmine\Player object, string ai claim)
    [17:44:49] [Server thread/DEBUG]: #7 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(238): pocketmine\Player->chat(string /ai claim)
    [17:44:49] [Server thread/DEBUG]: #8 src/pocketmine/network/mcpe/protocol/CommandRequestPacket(54): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleCommandRequest(pocketmine\network\mcpe\protocol\CommandRequestPacket object)
    [17:44:49] [Server thread/DEBUG]: #9 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(108): pocketmine\network\mcpe\protocol\CommandRequestPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    [17:44:49] [Server thread/DEBUG]: #10 src/pocketmine/network/mcpe/protocol/BatchPacket(119): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\CommandRequestPacket object)
    [17:44:49] [Server thread/DEBUG]: #11 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(108): pocketmine\network\mcpe\protocol\BatchPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    [17:44:49] [Server thread/DEBUG]: #12 src/pocketmine/Player(3111): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object)
    [17:44:49] [Server thread/DEBUG]: #13 src/pocketmine/network/mcpe/RakLibInterface(170): pocketmine\Player->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object)
    [17:44:49] [Server thread/DEBUG]: #14 vendor/pocketmine/raklib/src/server/ServerHandler(99): pocketmine\network\mcpe\RakLibInterface->handleEncapsulated(string 192.168.1.4 61144, raklib\protocol\EncapsulatedPacket object, integer 0)
    [17:44:49] [Server thread/DEBUG]: #15 src/pocketmine/network/mcpe/RakLibInterface(110): raklib\server\ServerHandler->handlePacket()
    [17:44:49] [Server thread/DEBUG]: #16 src/pocketmine/network/mcpe/RakLibInterface(100): pocketmine\network\mcpe\RakLibInterface->process()
    [17:44:49] [Server thread/DEBUG]: #17 vendor/pocketmine/snooze/src/SleeperHandler(123): pocketmine\network\mcpe\RakLibInterface->pocketmine\network\mcpe\{closure}()
    [17:44:49] [Server thread/DEBUG]: #18 vendor/pocketmine/snooze/src/SleeperHandler(85): pocketmine\snooze\SleeperHandler->processNotifications()
    [17:44:49] [Server thread/DEBUG]: #19 src/pocketmine/Server(2345): pocketmine\snooze\SleeperHandler->sleepUntil(double 1551609889.7316)
    [17:44:49] [Server thread/DEBUG]: #20 src/pocketmine/Server(2205): pocketmine\Server->tickProcessor()
    [17:44:49] [Server thread/DEBUG]: #21 src/pocketmine/Server(1784): pocketmine\Server->start()
    [17:44:49] [Server thread/DEBUG]: #22 src/pocketmine/PocketMine(250): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string C:\Users\Administrator\Desktop\Minecraft\AcidIsland - Pixelz\, string C:\Users\Administrator\Desktop\Minecraft\AcidIsland - Pixelz\plugins\)
    [17:44:49] [Server thread/DEBUG]: #23 (1): require(string phar://C:/Users/Administrator/Desktop/Minecraft/AcidIsland - Pixelz/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
    
    My Code
    PHP:
            $nbt = new CompoundTag("", [
                    
    "Pos" => new ListTag("Pos", [
                        new 
    DoubleTag(""$player->x),
                        new 
    DoubleTag(""$player->y),
                        new 
    DoubleTag(""$player->z),
                    ]),
                    
    "Motion" => new ListTag("Motion", [
                        new 
    DoubleTag(""0),
                        new 
    DoubleTag(""0),
                        new 
    DoubleTag(""0),
                    ]),
                    
    "Rotation" => new ListTag("Rotation", [
                        new 
    FloatTag(""$player->yaw),
                        new 
    FloatTag(""$player->pitch),
                    ]),
                    new 
    ByteTag("Flight"1),
                    new 
    CompoundTag("Fireworks", [
                        new 
    ListTag("", [
                            new 
    CompoundTag("", [
                                new 
    ByteTag("FireworkColor"0),
                                new 
    ByteTag("FireworkTrail"0),
                                new 
    ByteTag("FireworkType"1),
                                new 
    ByteTag("FireworkColor"2),
                                new 
    ByteTag("FireworkFade"2),
                            ]),
                        ]),
                    ]),
                ]);
                
    $firework = new Firework($player->level$nbt);
                
    $firework->spawnToAll();
                
    $firework->setImmobile(true);
            }
    }
     
  3. wolfdale

    wolfdale Zombie

    Messages:
    345
    Data property with a value of 53 is DATA_BOUNDING_BOX_WIDTH
    your Firework class is probably missing
    PHP:
    public $width 0.3;
    public 
    $height 0.3;//maybe, check if it exist before copying
     
    Muqsit likes this.
  4. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    131
    Umm Errors
    Code:
    2019-03-03 [22:14:08] [Server thread/CRITICAL]: ErrorException: "Undefined property: MyPlot\subcommand\Firework::$dataProperties" (EXCEPTION) in "src/pocketmine/entity/Entity" at line 2215
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #0 plugins/AcidIsland_/src/MyPlot/subcommand/ClaimSubCommand(175): pocketmine\entity\Entity->__get(string dataProperties)
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #1 src/pocketmine/entity/Entity(2019): MyPlot\subcommand\Firework->spawnTo(pocketmine\Player object)
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #2 plugins/AcidIsland_/src/MyPlot/subcommand/ClaimSubCommand(157): pocketmine\entity\Entity->spawnToAll()
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #3 plugins/AcidIsland_/src/MyPlot/subcommand/ClaimSubCommand(78): MyPlot\subcommand\ClaimSubCommand->Firework(pocketmine\Player object)
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #4 plugins/AcidIsland_/src/MyPlot/Commands(85): MyPlot\subcommand\ClaimSubCommand->execute(pocketmine\Player object, array Array())
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #5 src/pocketmine/command/SimpleCommandMap(270): MyPlot\Commands->execute(pocketmine\Player object, string ai, array Array())
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #6 src/pocketmine/Server(2029): pocketmine\command\SimpleCommandMap->dispatch(pocketmine\Player object, string ai claim)
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #7 src/pocketmine/Player(2219): pocketmine\Server->dispatchCommand(pocketmine\Player object, string ai claim)
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #8 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(238): pocketmine\Player->chat(string /ai claim)
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #9 src/pocketmine/network/mcpe/protocol/CommandRequestPacket(54): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleCommandRequest(pocketmine\network\mcpe\protocol\CommandRequestPacket object)
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #10 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(108): pocketmine\network\mcpe\protocol\CommandRequestPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #11 src/pocketmine/network/mcpe/protocol/BatchPacket(119): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\CommandRequestPacket object)
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #12 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(108): pocketmine\network\mcpe\protocol\BatchPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #13 src/pocketmine/Player(3111): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object)
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #14 src/pocketmine/network/mcpe/RakLibInterface(170): pocketmine\Player->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object)
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #15 vendor/pocketmine/raklib/src/server/ServerHandler(99): pocketmine\network\mcpe\RakLibInterface->handleEncapsulated(string 192.168.1.4 61896, raklib\protocol\EncapsulatedPacket object, integer 0)
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #16 src/pocketmine/network/mcpe/RakLibInterface(110): raklib\server\ServerHandler->handlePacket()
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #17 src/pocketmine/network/mcpe/RakLibInterface(100): pocketmine\network\mcpe\RakLibInterface->process()
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #18 vendor/pocketmine/snooze/src/SleeperHandler(123): pocketmine\network\mcpe\RakLibInterface->pocketmine\network\mcpe\{closure}()
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #19 vendor/pocketmine/snooze/src/SleeperHandler(85): pocketmine\snooze\SleeperHandler->processNotifications()
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #20 src/pocketmine/Server(2345): pocketmine\snooze\SleeperHandler->sleepUntil(double 1551626048.6751)
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #21 src/pocketmine/Server(2205): pocketmine\Server->tickProcessor()
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #22 src/pocketmine/Server(1784): pocketmine\Server->start()
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #23 src/pocketmine/PocketMine(250): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string C:\Users\Administrator\Desktop\Minecraft\AcidIsland - Pixelz\, string C:\Users\Administrator\Desktop\Minecraft\AcidIsland - Pixelz\plugins\)
    2019-03-03 [22:14:08] [Server thread/DEBUG]: #24 (1): require(string phar://C:/Users/Administrator/Desktop/Minecraft/AcidIsland - Pixelz/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
    
    Updated Code
    PHP:
    class Firework extends Creature{

        const 
    NETWORK_ID 72;
        public 
    $width 0.3;
        public 
    $height 0.3;//maybe, check if it exist before copying

        
    public function spawnTo(Player $player) : void{
            
    $pk = new AddEntityPacket;
            
    $pk->entityRuntimeId $this->getId();
            
    $pk->type self::NETWORK_ID;
            
    $pk->position $this->asVector3();
            
    $pk->motion $this->getMotion();
            
    $pk->yaw $this->yaw;
            
    $pk->pitch $this->pitch;
            
    $pk->metadata $this->dataProperties;
            
    $player->dataPacket($pk);
            
    Entity::spawnTo($player);
            
    $this->setMotion(new Vector3(020));
        }
        public function 
    getName() : string{
            return 
    "Firework";
        }
    }
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,555
    GitHub:
    muqsit
    wolfdale and HimbeersaftLP like this.
  6. wolfdale

    wolfdale Zombie

    Messages:
    345
    Just remove spawnTo, pocketmine already does that for you
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.