/** * 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; }
/** * 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; }