Posted October 19, 20169 yr I want to spawn a firework when the player rightclicks with an item. I have looked at the firework item, the firework entity, and the crafting code. Which has gotten me to this point (code below). The problem I am having is that the firework has no effect, just shoots up with a trail then disappears. ItemStack firework = new ItemStack(Items.FIREWORKS); NBTTagCompound nbttagcompound1 = new NBTTagCompound(); NBTTagCompound nbttagcompound2 = new NBTTagCompound(); List<Integer> list = Lists.<Integer>newArrayList(); list.add(Integer.valueOf(ItemDye.DYE_COLORS[0 & 15])); list.add(Integer.valueOf(ItemDye.DYE_COLORS[14 & 15])); int[] aint1 = new int[list.size()]; for (int l2 = 0; l2 < aint1.length; ++l2) { aint1[l2] = ((Integer)list.get(l2)).intValue(); } nbttagcompound2.setIntArray("Colors", aint1); nbttagcompound2.setBoolean("Flicker", true); nbttagcompound1.setTag("Explosion", nbttagcompound2); firework.setTagCompound(nbttagcompound1); EntityFireworkRocket rocket = new EntityFireworkRocket(world, player.posX, player.posY + 0.5F, player.posZ, firework); world.spawnEntityInWorld(rocket); return new ActionResult(EnumActionResult.SUCESS, stack); I have tried dropping the item (player.entityDropItem(firework)), which shows that it does have an NBTtag, but the tag doesn't add anything to the items display information, nor does it add an effect to the firework. Interestingly, if I change the ItemStack to a firework_charge, the NBTtags do work. They add the info and can be crafted into a regular firework. Is there a specific method for adding NBT to fireworks, similar to how you add enchantments to books, or am I just doing it wrong? P.S. I know the code isn't pretty, but I am just trying to brute force it, until I can get it working, then I will do the appropriate checks and conditions.
October 20, 20169 yr You're missing an NBT tag. If you look at EntityFireworkRocket#handleStatusUpdate , you'll see it gets the "Fireworks" compound tag from the ItemStack 's compound tag before passing that to World#makeFireworks and ParticleFirework.Starter . Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.