Jump to content

Recommended Posts

Posted

Hi there! I know it's possible to add tools and armors to the anvil repair system by doing this:

 

public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) {

return ingotSomething == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);

}

 

But I made it so that all my swords are put into one class like so:

 

public static Item copperSword = new ItemModSword...

public static Item steelSword = new ItemModSword...

 

Which means the getIsRepairable will only allow one item to use for repairing. My question is, is there a way to use more than one item for repairing depending on what tool I put in the anvil, without making new classes?

Posted

You mean you don't know how to use conditions statement like so ?

 

public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) {
return firstitem == par2ItemStack.itemID ||  seconditem == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);
}

 

 

Posted

Hi

 

I'm not sure I understand your question correctly, but it sounds to me like you have many swords made of different materials all within the one class, and each sword should only be repaired by its corresponding material eg

 

copper ingot for copper sword

iron ingot for iron sword

lead ingot for lead sword

 

Very much like the vanilla ItemSword with wood, stone, diamond, etc

 

If so, your isRepairable might look something like ItemSword.getIsRepairable, except that you have to add your own ingots

 

public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) {
   switch (materialIamMadeOf) {
      case iron: {
          return ingotIron == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);
      }
      case copper: {
          return ingotCopper == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);
      }
etc

-TGG

Posted

Hi

 

I'm not sure I understand your question correctly, but it sounds to me like you have many swords made of different materials all within the one class, and each sword should only be repaired by its corresponding material eg

 

copper ingot for copper sword

iron ingot for iron sword

lead ingot for lead sword

 

Very much like the vanilla ItemSword with wood, stone, diamond, etc

 

If so, your isRepairable might look something like ItemSword.getIsRepairable, except that you have to add your own ingots

 

public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) {
   switch (materialIamMadeOf) {
      case iron: {
          return ingotIron == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);
      }
      case copper: {
          return ingotCopper == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);
      }
etc

-TGG

 

Yup, that's what I meant! What should I put in the switch()?

Posted

Hi

 

You need to keep track of what each sword is made of - eg copper, iron, lead, or whatever.

 

The vanilla code does it like this

 

public class ItemSword extends Item
{
    private final EnumToolMaterial toolMaterial;

    public ItemSword(int par1, EnumToolMaterial par2EnumToolMaterial)
    {
        super(par1);
        this.toolMaterial = par2EnumToolMaterial;

 

and creates it using (for example)

    public static Item swordIron = new ItemSword(11, EnumToolMaterial.IRON);
    public static Item swordWood = new ItemSword(12, EnumToolMaterial.WOOD);
    public static Item swordStone = new ItemSword(16, EnumToolMaterial.STONE);

You can't add to the EnumToolMaterial, but you can create a field of your own (can be an int, doesn't have to be an enum) and make the materials whatever you like.

 

-TGG

 

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.