Jump to content

[Solved][1.10.2] Spawning fireworks that aren't blank


PegBeard

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.