Example #1
0
 static {
   NON_CREEPER_FIREWORK_TYPES = new FireworkEffect.Type[FireworkEffect.Type.values().length - 1];
   for (int i = 0; i < NON_CREEPER_FIREWORK_TYPES.length; ++i) {
     FireworkEffect.Type type = FireworkEffect.Type.values()[i];
     if (type != FireworkEffect.Type.CREEPER) {
       NON_CREEPER_FIREWORK_TYPES[i] = type;
     }
   }
 }
Example #2
0
  /**
   * Return a random firework effect.
   *
   * @param boolean allowCreeperType if true, creeper shaped firework explosion types are allowed.
   * @return a FireworkEffect instance.
   */
  protected FireworkEffect randomFireworkFffect(boolean allowCreeperType) {
    FireworkEffect.Builder builder = FireworkEffect.builder();
    if (Math.random() < 0.3) {
      builder.withFlicker();
    }
    if (Math.random() < 0.3) {
      builder.withTrail();
    }

    final FireworkEffect.Type[] TYPES =
        allowCreeperType ? FireworkEffect.Type.values() : NON_CREEPER_FIREWORK_TYPES;
    builder.with(TYPES[random(0, TYPES.length - 1)]);

    final int primaryColors = random(1, 4);
    for (int i = 0; i < primaryColors; ++i) {
      builder.withColor(Color.fromRGB(random(0, 255), random(0, 255), random(0, 255)));
    }

    final int fadeColors = random(1, 4);
    for (int i = 0; i < fadeColors; ++i) {
      builder.withFade(Color.fromRGB(random(0, 255), random(0, 255), random(0, 255)));
    }

    return builder.build();
  }