Jump to content

[1.8] Armor won't repair


Hamster_Furtif

Recommended Posts

Hey !

I have created a custom armor (actually, it's only a helmet), but it doesn't repairs.

Here is the code:

public class ItemMask extends ItemArmor{

public ItemMask(String nom) {
	super(Masks.armorMask, 1, 0);
	this.setMaxDamage(2);
	this.setUnlocalizedName("mask_"+nom);
	this.canRepair = true;
	this.setCreativeTab(Masks.tabMasks);


}

@Override
public boolean getIsRepairable(ItemStack input, ItemStack repair)
{
	return repair.getItem() == Items.clay_ball ? true : false;
}
}

 

Here is the ArmorMaterial:

	static int[] a = {1,1,1,1};
public static ArmorMaterial armorMask = EnumHelper.addArmorMaterial("armorMask", "mask", 2, a, 0);

 

And even this doesn't work:

 

@Override
public boolean getIsRepairable(ItemStack input, ItemStack repair)
{
	return true;
}

And there is something else: the armor doesn't break when it has 0HP, it takes one more hit to break it.

 

Thank you for your help !

 

Link to comment
Share on other sites

I think it is normal that the armor breaks when it has -1HP.

 

Try instead of

return repair.getItem() == Items.clay_ball ? true : false;[/Code]

 
[code]    @Override
public boolean getIsRepairable(ItemStack input, ItemStack repair)
{
                //input is the itemStack to be repaired, repair is the itemStack that should repair this item.
                //Change the bronze items to your own.
	return input.getItem() == MyItems.bronze_helmet && repair.getItem() == MyItems.bronze_ingot;
}

 

Also, the

? true : false[/Code]

is not necessary, "input.getItem() instanceof ItemBronzeArmor && repair.getItem() == MyItems.bronze_ingo" already returns false or true.

 

Hope this helps.

Creator of the Master Chef Mod and many more to come.

 

If I helped you, please click the 'thank you' button.

Link to comment
Share on other sites

 @Override
public boolean getIsRepairable(ItemStack input, ItemStack repair)
{
                //input is the itemStack to be repaired, repair is the itemStack that should repair this item.
                //Change the bronze items to your own.
	return input.getItem() == MyItems.bronze_helmet && repair.getItem() == MyItems.bronze_ingot;
}

This is not working. The weird thing is that it didn't work with:

@Override
public boolean getIsRepairable(ItemStack input, ItemStack repair)
{
	return true;
}

 

And I know adding

? true : false

is useless, but I tried everything I could.  :(

 

 

Link to comment
Share on other sites

System.out.println("Trying to repair: " + input.getItem() == MyItems.bronze_helmet + " && " + repair.getItem() == MyItems.bronze_ingot);

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

What you sent me caused an error, so I used this:

		System.out.println("Trying to repair: ");
	System.out.println(input.getItem() == Masks.mask_cow);
	System.out.println("&&");
	System.out.println(repair.getItem() == Items.clay_ball);
	return input.getItem() == Masks.mask_cow && repair.getItem() == Items.clay_ball;

 

And it printed:

Trying to repair
true
&&
true

Link to comment
Share on other sites

The latest version is:

package com.hamsterfurtif.masks.masques;

import net.minecraft.init.Items;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;

import com.hamsterfurtif.masks.Masks;

public class ItemMask extends ItemArmor{

public ItemMask(String nom) {
	super(Masks.armorMask, 1, 0);
	this.setMaxDamage(2);
	this.setUnlocalizedName("mask_"+nom);
	this.canRepair = true;
	this.setCreativeTab(Masks.tabMasks);


}

@Override
public boolean getIsRepairable(ItemStack input, ItemStack repair)
{
	boolean compatible = false;
	for (int i=0; i < Masks.masques.length; i++)
	{
		System.out.println("Trying to repair: ");
		System.out.println(input.getItem() == Masks.masques[i]);
		System.out.println("&&");
		System.out.println(repair.getItem() == Items.clay_ball);


			if (input.getItem() == Masks.masques[i] && repair.getItem() == Items.clay_ball)
				compatible = true;

	}

	return compatible;
}
}

 

With this in the main class:

public static Item mask_clay = new ItemMask("clay");
public static Item mask_spider = new ItemMaskSpider();
public static Item mask_cow = new ItemMaskCow();
public static Item mask_mouton = new ItemMaskMouton();
public static Item mask_gardien = new ItemMaskGardien();
public static Item mask_squelette = new ItemMaskSquelette();
    
public static Item[] masques= {mask_clay, mask_spider, mask_cow, mask_mouton, mask_gardien, mask_squelette};

 

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...

I'm not sure if its true for 1.8 but after some lengthy research I came across the solution for 1.7.10.

 

Remove that getIsRepairable from your itemarmor class and put this in your main registry class/method put the following.

 

//your enum name fallowed by the .customCraftingMaterial, than just set it to your item you want it to repair.
ARMORCOPPER.customCraftingMaterial = ingotCopper;

 

I use a register method, and I put this after everything was set in that method.

 

So [Made in short hand]:

 

Main class

@mod()
public void preInit()
MyModsItemClass.registerItems();

 

MyModsItemClass class

public static final ItemArmor.ArmorMaterial ARMORCOPPER = EnumHelper.addArmorMaterial("COPPER", 10, new int[]{2,3,2,2}, 12);

public static Item myArmor;
public static Item ingotCopper

public static void registerItems(){

  myArmor = new MyArmor(ARMORCOPPER, 0, 0, "", "");

  ingotCopper = new MyItems();

  ARMORCOPPER.customCraftingMaterial = ingotCopper;

}

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.