Jump to content

ItemStacks & Recipes?


Captain Hillman

Recommended Posts

Hi all,

 

I'm trying to create a recipe for an item I've made that *should* require a stack of 3 input items (i.e. three X's create one Y). The code I'm using at the moment is below, but when creating the output item, only one of the stacked input is used up, not all three. What have I missed?

 

GameRegistry.addShapelessRecipe(new ItemStack(ItemStore.itemY), new ItemStack(ItemStore.itemX, 3));

Link to comment
Share on other sites

it SHOULD be (itemY, itemX, itemX, itemX)

The inputs don't check the stack size, that is why you can have 2 full stacks of planks and still make sticks.

As for weither or not you should use new Object[] the answer is NO.

That's a decompiler artifact that should not exist in any code that you write. {Quit copy/pasta people -.-}

addRecipe functions take 2 arguments, a itemstack for the output

And then a parameter array for the inputs.

When java compiles a parameter array it converts it to a true array.

So

public void add(ItemStack output, Object... inputs)

add(new ItemStack(ItemX), new ItemStack(ItemY), new ItemStack(ItemY), new ItemStack(ItemY))

gets converted to this by the compiler:

public void add(ItemStack output, Object[] inputs)

add(new ItemStack(ItemX), new Object[]{new ItemStack(ItemY), new ItemStack(ItemY), new ItemStack(ItemY)})

 

So you can see where that decompiler artifact comes from. There is NO reason you should ever do it in your code.

Same goes for Character.valueOf('a') The compiler adds the Character.valueOf automatically to anything in character literals 'a' So you should not need to add them ever.

 

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

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.