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.

[1.6.4] [NEW PROBLEM] Problem with damaging an item after crafted with.

Featured Replies

Posted

NEW PROBLEM:

 

Now the item wont break even thou the durability is below 0.

 

 

CODE:

Main Class (Recipe & Registration of handler) :

 

  
GameRegistry.registerCraftingHandler(new CraftingHandler());
    	   
    	   GameRegistry.addShapelessRecipe(new ItemStack(SiliconMixture), new Object[]{
    		   new ItemStack(CopperIngot), new ItemStack(Item.ingotIron), new ItemStack(ShapingHammer, 0, -1)
               }); 

 

 

Crafting Handler:

 

 
public class CraftingHandler implements ICraftingHandler{

@Override
public void onCrafting(EntityPlayer player, ItemStack item, IInventory inv) 
{
  	for(int i=0; i < inv.getSizeInventory(); i++)
	{        	
    	if(inv.getStackInSlot(i) != null)
    	{
    		ItemStack j = inv.getStackInSlot(i);
    		if(j.getItem() != null && j.getItem() == main_ProcessCraft.ShapingHammer)
    		{
    			ItemStack k = new ItemStack(main_ProcessCraft.ShapingHammer, 2, (j.getItemDamage() + 1));
    			inv.setInventorySlotContents(i, k);
    		}
    	}  
	}
}


@Override
public void onSmelting(EntityPlayer player, ItemStack item) {
	// TODO Auto-generated method stub

}


}

 

 

Item File:

 

 
package gmod.mods.ProcessingCraft.main.item;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;

public class ItemShapingHammer extends Item {

public ItemShapingHammer(int par1) {
	super(par1);
	this.setCreativeTab(CreativeTabs.tabBlock);
	this.bFull3D = true;
	this.maxStackSize = 1;
	this.canRepair = true;
	this.setMaxDamage(128);

}

  

}

 

 

Any Help to my problem will be appreciated!

 

 

 

Not new to java >> New to modding.

Are you trying to get it to take 1 damage when used in crafting each time and once the durability hits 0, you can't use it for crafting anymore until repaired?

If I helped then you help, hit that Thank You button or Applaud.

  • Author

well I tried adding this, but it did not help :(

 

int d = j.getItemDamage();

    if(d > 128)

    {

    inv.setInventorySlotContents(i, null);

    }

Not new to java >> New to modding.

Is it supposed to just disappear like a sword when it brakes?

If I helped then you help, hit that Thank You button or Applaud.

I taught I knew it but then I tried it myself so I don't give false info and it didn't work.... Too much for my brain to handle sorry. xD

If I helped then you help, hit that Thank You button or Applaud.

I hope you know what this is doing.

int d = j.getItemDamage();
if(d > 128)
{
     inv.setInventorySlotContents(i, null);
}

This is checking when - your item is above the max damage (greater than 128).

 

You can check if it is at 0, then remove the item, but the problem is that you probably don't even know what (d>128) really means - d (greater than) 128.

You should use (checks if it is equal to 0 or below 0. [0,-1,-2,-3,etc.])

int d = j.getItemDamage();
if(d <= 0)
{
    //break / delete item
}

  • Author

I was told that damage is inverted... 128 Damage taken to the item.

Not new to java >> New to modding.

I hope you know what this is doing.

int d = j.getItemDamage();
if(d > 128)
{
     inv.setInventorySlotContents(i, null);
}

This is checking when - your item is above the max damage (greater than 128).

 

You can check if it is at 0, then remove the item, but the problem is that you probably don't even know what (d>128) really means - d (greater than) 128.

You should use (checks if it is equal to 0 or below 0. [0,-1,-2,-3,etc.])

int d = j.getItemDamage();
if(d <= 0)
{
    //break / delete item
}

 

you really should get your facts straight before you go around insulting people..

 

@gmod622

an easier way to do what you want is this

 

if(j.getItem() != null && j.getItem() == main_ProcessCraft.ShapingHammer)
{
    if (!j.attemptDamageItem(1, player.getRNG()))
    {
        j.stackSize++;
    }
}

 

although, this should already work fine assuming you added it to the rest of your code correctly

 

int d = j.getItemDamage();
if(d > 128)
{
     inv.setInventorySlotContents(i, null);
}

 

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.