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

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));

It should be:

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

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

  • Author

Surely that'll create a recipe that outputs 3 item X's for every input 1 item Y? I'm aiming for the reverse, i.e. outputs 1 item X for every 3 item Y's input. I had thought the code in my original post should do that, but it's only using up 1 input item, not 3.

Does it make a difference if you put the ItemStack in an Object[]?

 

GameRegistry.addShapelessRecipe( new ItemStack(ItemStore.itemY), new Object[]{ 
		new ItemStack(ItemStore.itemX, 3)});

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

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.