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 a mod at the moment and I'm trying to make a Red Power 2 handsaw or Equivalent Exchange 3 minium stone type item where you can use it in a crafting recipe and it will give it back but more damaged but I cant figure out how, if anybody knew I would be really thankful.

Hey,

you need a crafting handler, create a new class an name it as you want.

Then define it in your mod_xxx.java in the "public void init..." method with

GameRegistry.registerCraftingHandler(new CraftingHandler());

In this example I called the CraftingHandler "CraftingHandler" :)

Now you have to make your Item and then add the following:

aloeVeraMilk = (new ItemXXX(975)).setIconIndex(75).setItemName("Test Item").setMaxDamage(10); // Add your Max. Damge here!!!

Now we want, that you won't loose your Item after crafting. Go the crafting handler and add:

public class CraftingHandler implements ICraftingHandler {

@Override
public void onCrafting(EntityPlayer player, ItemStack item,
		IInventory craftMatrix) {

	for(int i=0; i < craftMatrix.getSizeInventory(); i++)
ย  ย  {
ย  ย  ย  ย  if(craftMatrix.getStackInSlot(i) != null)
ย  ย  ย  ย  {
ย  ย  ย  ย  ย  ย  ItemStack j = craftMatrix.getStackInSlot(i);
ย  ย  ย  ย  ย  ย  if(j.getItem() != null && j.getItem() == mod_eltrixscience.vaporizerItem)
ย  ย  ย  ย  ย  ย  {
ย  ย  ย  ย  ย  ย  ย  ย  ItemStack k = new ItemStack(mod_xxx.xxxItem, 2, (j.getItemDamage() - 1)); // <-- Set the Damage after crafting...
ย  ย  ย  ย  ย  ย  ย  ย  craftMatrix.setInventorySlotContents(i, k); //<-- Put the item back into the crafting gui!
ย  ย  ย  ย  ย  ย  }
ย  ย  ย  ย  ย  ย  
ย  ย  ย  ย  }
ย  ย  }

}

}

ย 

Hope I helped you!

Greetings from germany!

  • Author

Thanks a lot I've been looking for this for a while, I found the code that you put in the CraftingHandler class before but I didn't say that I had to put it in its own class so when I tried it in the base class it didn't work.

  • Author

Oh by the way this line of code:

ItemStack k = new ItemStack(mod_xxx.xxxItem, 2, (j.getItemDamage() - 1));

ย 

Should be changed to:

ItemStack k = new ItemStack(mod_xxx.xxxItem, 2, (j.getItemDamage() + 1));

ย 

Because otherwise you are taking away from the damage value which adds to the durability so it will go from 123 to 124 instead of 123 to 122.

  • Author

Also you will want to remove this piece of code at the bottom of the code:

craftMatrix.setInventorySlotContents(i, k);

ย 

And put in this if else statement so if the item has no durability left it gets destroyed:

if(k.getItemDamage() < k.getMaxDamage()){
	craftMatrix.setInventorySlotContents(i, k);
ย  }else{
	ItemStack l = new ItemStack(Block.blockClay, 0);
	craftMatrix.setInventorySlotContents(i, j);
ย   }

ย 

The Block.blockClay can be replaced with anything because the 0 after it means that 0 of whatever item is stated will be put in your inventory.

ย 

So the final code should look like this:

@Override
public void onCrafting(EntityPlayer player, ItemStack item,
		IInventory craftMatrix) {
	for(int i = 0; i < craftMatrix.getSizeInventory(); i++ ){
		if(craftMatrix.getStackInSlot(i) != null){
			ItemStack j = craftMatrix.getStackInSlot(i);
			if(j.getItem() != null && j.getItem() == YourMod.yourItem){
				ItemStack k = new ItemStack(YourMod.yourItem, 2, (j.getItemDamage() + 1));
				if(k.getItemDamage() < k.getMaxDamage()){
					craftMatrix.setInventorySlotContents(i, k);
				}else{
					ItemStack l = new ItemStack(Block.blockClay, 0);
					craftMatrix.setInventorySlotContents(i, j);
				}	
			}
		}
	}

}

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.