Jump to content

[Solved] Making a RP2 Handsaw type item help.


Rowsell99

Recommended Posts

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
				}	
			}
		}
	}

}

Link to comment
Share on other sites

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.