Jump to content

Remove tool repair


uni52724

Recommended Posts

2 minutes ago, That_Martin_Guy said:

Call setNoRepair in the items constructor or whenever you're creating the object.

Like this?

 

public void whenCrafted(ItemCraftedEvent event)
{
    if (event.crafting.getItem() instanceof ItemTool)
    {
        event.crafting.getItem().setNoRepair();
    }
}

 

Because that didn't seem to work for me :L

Link to comment
Share on other sites

Just now, That_Martin_Guy said:

No, definitely not. I and many other people on this forum recommend learning java before you try and mod. Trust me, I know from experience that it helps out immensly.

What are you talking about?! What did I do wrong? Many other mods of mine worked perfectly fine >.>

Link to comment
Share on other sites

And actually I don't think it needs to be strictly called in the constructor or when creating the object. It should be able to be set at any time (of course prior to trying to repair it). I would probably do it to vanilla items either during item registration or even recipe registration and even init or post init should work. Basically just sometime during loading after vanilla instances exist.

 

@uni52724sorry we're being a bit rude about the Java, but the use would be obvious if you were strong in programming. Let me teach you on how I take a suggestion and figure out the rest of the situation.

 

First of all you should have found the implementation of the method in Item class and you'd see that it is a simple setter method (with chaining as it returns the item instance).

 

Next I would use the call hierarchy to see how it is used. However, interestingly that method is never used in vanilla! But that is okay, that happens sometimes as there are some methods abandoned and some added by Forge. But it means we need to do more investigation to understand how it works.

 

So, then I look at the actual field that the setter sets called canRepair. It is protected in scope so can't be accessed directly, but can by extended classes. I look at it's call hierarchy to see if it is accessed directly by vanilla, but it is not. So basically it means that all Items default to canRepair = true since that is the default value.

 

Now you still need to know how recipes use this. It might be possible that it gets used during recipe registration or something, so you want to understand if the timing of the setNoRepair() matters much. In the call hierarchy for canRepair you can see that in addition to the setNoRepair() method there is a isRepairable() method -- this is the getter function. By following the call hierarchy for that method you can see that it is used by the RecipeRepairItem. Perfect -- so we know that we're on the right track.

 

However, it is a good idea to confirm the implementation of the isRepairable() so I look at its declaration. It does check canRepair field but also need isDamageable() to be true. So checking the declaration of that method shows it just checks that the item isn't using damage for sub-types and also that there is a maxDamage field that > 0. 

 

Now this is in fact quite interesting because it means that another way to prevent repair is to set the maxDamage value to 0 (or less). If you follow the call hierarchy for maxDamage, there is a setter called setMaxDamage() and it is actually called on a lot of vanilla items. If you look at something you know is not damageable like ItemBed you see that it calls setMaxDamage(0) in the constructor.

 

Therefore, all this means that vanilla items actually make things no repair by setMaxDamage(0) and do not actually use the setNoRepair() method. However, the setNoRepair() is equally valid. This is often the case in Minecraft because frankly the coding interface wasn't well managed over time and so there are often duplicate methods that achieve similar (but not always exactly) the same effect.

 

So that is the type of investigation someone strong in Java does when given a hint like "use setNoRepair()". I just did all this investigation myself. It is important because you really need to trace the implementations and uses otherwise you can get fooled as the name of the function may not match what you think it does, and you might find other implementation details like I did.

 

So hopefully that teaches you some techniques to help you solidify your own investigations into hints you get here.

  • Like 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

1 minute ago, diesieben07 said:

Nobody was rude.

True, no one was trying to be rude, but he seemed to take it as insulting and acted defensive so was just smoothing things over. I'm Canadian so I tend to err on side of over-polite. (Pro tip, when Canadians are saying "sorry" they might still be thinking you're an idiot.) ;-)

 

I also think the trick is there are lots of levels to "learning Java". Some people are still beginners but just need a nudge to get them to the next level. I also see a lot of people who seem to actually know Java enough but are somehow not effectively using their tools to investigate and debug. It is really hard to judge on this forum. This guy obviously didn't know enough to understand the instruction, but he also didn't seem to properly investigate. I'm hoping that giving him some guidance on the investigation will help him shore up his Java.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

On 3/4/2018 at 8:28 PM, That_Martin_Guy said:

No, definitely not. I and many other people on this forum recommend learning java before you try and mod. Trust me, I know from experience that it helps out immensly.

yeah i remembered, we both posted some bad threads. the reason why it is hard to learn java because the tutorials use deep hard words, these words means a lot in every sentence so it would be recommended to google each hard deep word. I once got confused when @Choonster used the word "obsfucate" until I googled it, its that easy!

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.