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'm working on my first mod, and I'm trying to make it so that when you craft item A with item B, you get item C, but you also get item A back, such as the bucket back from the milk bucket in the cake recipe. I'm using the this.setContainerItem, but it doesn't work. This is the code from my item A, Gemcutter's Knife, class:

package thegoldcrayon.thegoldcrayonsgemstonesmod;

import net.minecraft.item.Item;

public class ItemGemcuttersKnife extends Item {
public ItemGemcuttersKnife(){
	this.setFull3D();
	this.setMaxStackSize(1);
	this.setContainerItem(TheGoldCrayonsGemstonesMod.itemGemcuttersKnife);
}


}

I can't seem to figure this out. Any help?

"War doesn't determine who is right. Only who is left." -Bertrand Russell

You need to set the container item for the OTHER item, so if you craft A + B = C and B is consumed, then you need to set C's container item to A. You don't set A's container item to A, nor C's to C, which it looks like you are doing with your knife.

 

Also, if you want to force the container item to remain in the crafting grid rather than getting added to the player's inventory, you can override Item#doesContainerItemLeaveCraftingGrid to return false (in item C).

  • Author

I put the .setContainerItem(A) in C's class, but that didn't do anything. How would I set up the #doesContainerItemLeaveCraftingGrid?

"War doesn't determine who is right. Only who is left." -Bertrand Russell

I put the .setContainerItem(A) in C's class, but that didn't do anything. How would I set up the #doesContainerItemLeaveCraftingGrid?

Override it in your Item class and return false. If you don't know what that means, Google it.

 

C.setContainerItem(A) should have worked - are both A and C your items (i.e. not vanilla)? If so, then it's possible that you didn't initialize A before C, in which case when you initialize C the container item is simply set to null:

public static Item A, B, C; // these are all null right now
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
C = new ItemC(); // C is initialized first, but right now A is still null!!! uh oh!
A = new ItemA(); // now A is initialized, but it's too late - C has already been initialized with a null container item
B = new ItemB();
}

Obviously, switching the order of initialization should fix your problem.

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.