Jump to content

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


Recommended Posts

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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
}

Posted

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

×   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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.