Jump to content

Recommended Posts

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

Posted

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

Posted

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

Posted

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

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