Giter Club home page Giter Club logo

fireworks's Introduction

Fireworks

Adds fireworks to your PocketMine server
Download the compiled .phar format of Fireworks from the Poggit CI.

API

Adding firework items to a player's inventory

Giving players fireworks is easy as pie. Here are some examples (where $player is a \pocketmine\player\Player object):

  • Base firework
/** @var Fireworks $fw */
$fw = ItemFactory::get(Item::FIREWORKS);
$player->getInventory()->addItem($fw);
  • Sphere firework with color fade from blue to cyan
/** @var Fireworks $fw */
$fw = ItemFactory::get(Item::FIREWORKS);

// addExplosion Parameters:
// int $type: Type of explosion, 0 - 4, see Fireworks::TYPE_* constants
// string $color: Color of explosion, see Fireworks::COLOR_* constants
// string $fade = "": Color to fade to, none if an empty string is passed
// bool $flicker = false: If the particles should flicker
// bool $trail = false: If the particles leave a trail behind
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_BLUE, Fireworks::COLOR_DARK_AQUA, false, false);

$player->getInventory()->addItem($fw);
  • Green creeper firework, flying higher
/** @var Fireworks $fw */
$fw = ItemFactory::get(Item::FIREWORKS);
$fw->addExplosion(Fireworks::TYPE_CREEPER_HEAD, Fireworks::COLOR_GREEN, "", false, false);
$fw->setFlightDuration(2);
$player->getInventory()->addItem($fw);
  • High flying flashing star firework with trail
/** @var Fireworks $fw */
$fw = ItemFactory::get(Item::FIREWORKS);
$fw->addExplosion(Fireworks::TYPE_STAR, Fireworks::COLOR_YELLOW, "", true, true);
$fw->setFlightDuration(3);
$player->getInventory()->addItem($fw);
  • All-colored sphere firework with trail
/** @var Fireworks $fw */
$fw = ItemFactory::get(Item::FIREWORKS);
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_BLACK, "", false, true);
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_RED, "", false, true);
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_DARK_GREEN, "", false, true);
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_BROWN, "", false, true);
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_BLUE, "", false, true);
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_DARK_PURPLE, "", false, true);
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_DARK_AQUA, "", false, true);
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_GRAY, "", false, true);
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_DARK_GRAY, "", false, true);
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_PINK, "", false, true);
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_GREEN, "", false, true);
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_YELLOW, "", false, true);
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_LIGHT_AQUA, "", false, true);
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_DARK_PINK, "", false, true);
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_GOLD, "", false, true);
$fw->addExplosion(Fireworks::TYPE_SMALL_SPHERE, Fireworks::COLOR_WHITE, "", false, true);
$player->getInventory()->addItem($fw);

Launching fireworks

Fireworks can be launched after you created the firework item. This example spawns a green creeper firework at the default world's spawn

// Create the type of firework item to be launched
/** @var Fireworks $fw */
$fw = ItemFactory::get(Item::FIREWORKS);
$fw->addExplosion(Fireworks::TYPE_CREEPER_HEAD, Fireworks::COLOR_GREEN, "", false, false);
$fw->setFlightDuration(2);

// Use whatever level you'd like here. Must be loaded
$level = Server::getInstance()->getDefaultLevel();
// Choose some coordinates
$vector3 = $level->getSpawnLocation()->add(0.5, 1, 0.5);
// Create the NBT data
$nbt = FireworksRocket::createBaseNBT($vector3, new Vector3(0.001, 0.05, 0.001), lcg_value() * 360, 90);
// Construct and spawn
$entity = FireworksRocket::createEntity("FireworksRocket", $level, $nbt, $fw);
if ($entity instanceof FireworksRocket) {
    $entity->spawnToAll();
}

fireworks's People

Contributors

inxomnyaa avatar itstoxicgg avatar muqsit avatar poggit-bot avatar sandertv avatar unickorn avatar zomarrd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.