fadeColors = MathHelper.clamp(fadeColors, 1, Integer.MAX_VALUE); Explosion e = new Explosion(); case 2: case 0: e.setTwinkle(true); if (v == 0) { break; e.setTrail(true); e.setType(MathHelper.RANDOM.nextInt(5)); e.addPrimaryColor(color.getRed(), color.getGreen(), color.getBlue()); e.addFadeColor(color.getRed(), color.getGreen(), color.getBlue());
/** * Creates a fireworks {@link ItemStack}, with the resulting fireworks having a certain flight duration and a variety of {@link Explosion}s. * * @param flightDuration The flight duration of the fireworks. Possible range is between 0 (inclusive) and 3 (inclusive). * @param explosions The explosions that will occur when the fireworks detonate. * @return A fireworks ItemStack. */ public static ItemStack getFireworksStack(int flightDuration, Explosion... explosions) { NBTTagCompound tags = new NBTTagCompound(); NBTTagCompound fireworksTag = new NBTTagCompound(); NBTTagList explosionsList = new NBTTagList(); if (explosions != null) { for (Explosion e : explosions) { if (e == null) { continue; } explosionsList.appendTag(e.getTagCompound()); } } fireworksTag.setByte("Flight", (byte) MathHelper.clamp(flightDuration, 0, 3)); fireworksTag.setTag("Explosions", explosionsList); tags.setTag("Fireworks", fireworksTag); ItemStack stack = new ItemStack(Items.FIREWORKS); stack.setTagCompound(tags); return stack; }
/** * Creates a randomized fireworks {@link ItemStack}. * * @param flightDuration The flight duration of the fireworks. Possible range is between 0 (inclusive) and 3 (inclusive). * @param explosions The amount of {@link Explosion}s that will occur when the fireworks detonate. * @param primaryColors The amount of different primary colors that each Explosion will have. * @param fadeColors The amount of different fade colors that each Explosion will have. * @return A randomized fireworks ItemStack. */ public static ItemStack getRandomFireworks(int flightDuration, int explosions, int primaryColors, int fadeColors) { explosions = MathHelper.clamp(explosions, 0, Integer.MAX_VALUE); Explosion[] explosionsArray = new Explosion[explosions]; for (int i = 0; i < explosions; i++) { explosionsArray[i] = Explosion.getRandom(primaryColors, fadeColors); } return getFireworksStack(flightDuration, explosionsArray); }
/** * Sets the explosion type using an integer. * * @param type The explosion type as an integer. * @return The current Explosion instance. */ public Explosion setType(int type) { this.setType(Type.values()[MathHelper.clamp(type, 0, Type.values().length - 1)]); return this; }
/** * Converts the Explosion to a Firework Star {@link ItemStack}. * * @return A Firework Star ItemStack representing the Explosion. */ public ItemStack getFireworkStarStack() { NBTTagCompound tags = new NBTTagCompound(); NBTTagCompound explosionTag = this.getTagCompound(); tags.setTag("Explosion", explosionTag); ItemStack stack = new ItemStack(Items.FIREWORK_CHARGE); stack.setTagCompound(tags); return stack; }