Jump to content

How do I add NBT to a crafting recipe output?


Hardc0r3Br0n3

Recommended Posts

I have this:

 

    GameRegistry.addRecipe(new ItemStack(Items.diamond_sword),

    " E ",

    " E ",

    " S ",

    'E', Items.emerald, 'S', Items.stick);

 

Except I want the diamond sword that comes out to be enchanted, and I'm not sure how to do that.

"It's basically a big ball of wibily wobily timey wimey." - The Doctor

Link to comment
Share on other sites

I did this:

 

    ItemStack stack = new ItemStack(Items.diamond_sword);

    stack.addEnchantment(sharpness, 4);

    GameRegistry.addRecipe(new ItemStack(Items.diamond_sword),

    " E ",

    " E ",

    " S ",

    'E', Items.emerald, 'S', Items.stick);

 

Still have a bunch of errors... help? (Sorry about this.)

"It's basically a big ball of wibily wobily timey wimey." - The Doctor

Link to comment
Share on other sites

I did this:

 

    ItemStack stack = new ItemStack(Items.diamond_sowrd);

    stack.addEnchantment(sharpness, 4);

    GameRegistry.addRecipe(new ItemStack(Items.diamond_sword),

    " E ",

    " E ",

    " S ",

    'E', Items.emerald, 'S', Items.stick);

 

Still have a bunch of errors... help? (Sorry about this.)

Yikes - you probably need to spend some time following Java tutorials.

 

1. Items.diamond_sowrd is misspelled, which your IDE would probably tell you if you hovered over the error

2. GameRegistry.addRecipe(new ItemStack(Items.diamond_sword), <-- not an error, but that is not the stack with the enchanment

 

Well that's it - I only saw one error that your IDE would complain about, so if you're getting a 'bunch', then you've got some work to do.

Link to comment
Share on other sites

I fixed the spelling error a couple of seconds after posting that reply...

So by stack does that mean I put (stack, 1) instead of diamond_sword?

 

I'm new to this and haven't even got around to adding custom Items yet... but recipes where at least easy enough for me to have some fun with it until I learn more so I can go to Items.

Sorry for my noob-y-ness.

"It's basically a big ball of wibily wobily timey wimey." - The Doctor

Link to comment
Share on other sites

You make the ItemStack first, add the enchantment, then create the recipe:

ItemStack stack = new ItemStack(sword, ...);
stack.addEnchantment(whateverEnchantmentYouWant, ...);
GameRegistry.addRecipe(stack, ...);

@OP DO you see what I used for addRecipe? 'stack', because that's the name of the ItemStack to which I added the enchantment, and that's the stack I want as the recipe output.

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.

Announcements



×
×
  • Create New...

Important Information

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