Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.