2013-06-23 23:04:46 +02:00
|
|
|
/************************************************************************
|
2013-12-28 09:44:40 +01:00
|
|
|
## Fireworks Module
|
|
|
|
|
2013-06-23 23:04:46 +02:00
|
|
|
The fireworks module makes it easy to create fireworks using
|
|
|
|
ScriptCraft. The module has a single function `firework` which takes
|
|
|
|
a `org.bukkit.Location` as its 1 and only parameter.
|
|
|
|
|
2013-12-28 09:44:40 +01:00
|
|
|
### Examples
|
|
|
|
|
2013-06-23 23:04:46 +02:00
|
|
|
The module also extends the `Drone` object adding a `firework` method
|
|
|
|
so that fireworks can be created as a part of a Drone chain. For
|
|
|
|
Example....
|
|
|
|
|
|
|
|
/js firework()
|
|
|
|
|
|
|
|
... creates a single firework, while ....
|
|
|
|
|
2013-12-24 01:17:33 +01:00
|
|
|
/js firework().fwd(3).times(5)
|
2013-06-23 23:04:46 +02:00
|
|
|
|
|
|
|
... creates 5 fireworks in a row. Fireworks have also been added as a
|
|
|
|
possible option for the `arrow` module. To have a firework launch
|
|
|
|
where an arrow strikes...
|
|
|
|
|
|
|
|
/js arrows.firework()
|
|
|
|
|
|
|
|
To call the fireworks.firework() function directly, you must provide a
|
|
|
|
location. For example...
|
|
|
|
|
2013-12-24 01:17:33 +01:00
|
|
|
/js var fireworks = require('fireworks');
|
2014-01-29 20:49:15 +01:00
|
|
|
/js fireworks.firework( self.location );
|
2013-06-23 23:04:46 +02:00
|
|
|
|
2013-06-24 21:22:39 +02:00
|
|
|
![firework example](img/firework.png)
|
2013-06-23 23:04:46 +02:00
|
|
|
|
|
|
|
***/
|
2013-12-24 01:17:33 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
create a firework at the given location
|
|
|
|
*/
|
2014-01-29 20:49:15 +01:00
|
|
|
var firework = function( location ) {
|
2014-02-19 23:17:19 +01:00
|
|
|
var bkColor = org.bukkit.Color;
|
|
|
|
var bkFireworkEffect = org.bukkit.FireworkEffect;
|
|
|
|
var bkEntityType = org.bukkit.entity.EntityType;
|
2014-01-29 20:49:15 +01:00
|
|
|
|
|
|
|
var randInt = function( n ) {
|
|
|
|
return Math.floor( Math.random() * n );
|
|
|
|
};
|
|
|
|
var getColor = function( i ) {
|
|
|
|
var colors = [
|
2014-02-19 23:17:19 +01:00
|
|
|
bkColor.AQUA, bkColor.BLACK, bkColor.BLUE, bkColor.FUCHSIA, bkColor.GRAY,
|
|
|
|
bkColor.GREEN, bkColor.LIME, bkColor.MAROON, bkColor.NAVY, bkColor.OLIVE,
|
|
|
|
bkColor.ORANGE, bkColor.PURPLE, bkColor.RED, bkColor.SILVER, bkColor.TEAL,
|
|
|
|
bkColor.WHITE, bkColor.YELLOW];
|
2014-01-29 20:49:15 +01:00
|
|
|
return colors[i];
|
|
|
|
};
|
2014-02-19 23:17:19 +01:00
|
|
|
var fw = location.world.spawnEntity(location, bkEntityType.FIREWORK);
|
2014-01-29 20:49:15 +01:00
|
|
|
var fwm = fw.getFireworkMeta();
|
2014-02-19 23:17:19 +01:00
|
|
|
var fwTypes = [
|
|
|
|
bkFireworkEffect.Type.BALL,
|
|
|
|
bkFireworkEffect.Type.BALL_LARGE,
|
|
|
|
bkFireworkEffect.Type.BURST,
|
|
|
|
bkFireworkEffect.Type.CREEPER,
|
|
|
|
bkFireworkEffect.Type.STAR
|
|
|
|
];
|
2014-01-29 20:49:15 +01:00
|
|
|
var type = fwTypes[ randInt( 5 ) ];
|
|
|
|
|
|
|
|
var r1i = randInt( 17 );
|
|
|
|
var r2i = randInt( 17 );
|
|
|
|
var c1 = getColor( r1i );
|
|
|
|
var c2 = getColor( r2i );
|
2014-02-19 23:17:19 +01:00
|
|
|
var effectBuilder = bkFireworkEffect.builder()
|
2014-01-29 20:49:15 +01:00
|
|
|
.flicker( Math.round( Math.random() ) == 0 )
|
|
|
|
.withColor( c1 )
|
|
|
|
.withFade( c2 )
|
|
|
|
.trail( Math.round( Math.random() ) == 0 );
|
|
|
|
effectBuilder['with']( type );
|
|
|
|
var effect = effectBuilder.build();
|
|
|
|
fwm.addEffect( effect );
|
|
|
|
fwm.setPower( randInt( 2 ) + 1 );
|
|
|
|
fw.setFireworkMeta( fwm );
|
2013-12-24 01:17:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.firework = firework;
|
|
|
|
|