[1.15.2] Some Withered items are unbreakable, and others are not
CplPibald opened this issue · 4 comments
Describe the bug
Testing with the withered tier of items; some are unbreakable, and some take durability damage.
Unbreakable: Excavator, axe, hammer, shovel, pickaxe, paxel
Breakable: Lumberaxe, sword, battleaxe, hoe
To Reproduce
Acquire withered tool and use it to break blocks, hit enemies, etc.
- Battleaxe and sword take damage when hitting enemies
- Battleaxe, sword, and lumberaxe take damage when breaking blocks. (withered lumberaxe only takes 1 damage when felling a tree, compared to 7 damage for other lumberaxes)
- Hoe takes damage when used to till farmland, but not break blocks or hitting mobs
Expected behavior
All tools with the withered material behave the same. It's not clear whether this is intended to be unbreakable or not.
Versions
RaysDongles-4.2.2b
Minecraft 1.15.2
Forge-31.2.37
Other mods
JEI, Hwyla
Thanks for the report. Not sure when I can get around to fixing this, I haven’t even debated on starting porting my mod to later versions of MC, as I’m not sure if I would like to continue supporting the mod as its a lot to do with everything else. I will leave it open for now and see if perhaps Tuesday I can look into the issue.
I hope you don't mind, I dug into the source a little bit more on this. I had intended to send a pull request with these suggestions, but I had trouble building the mod from the 1.15.x branch, so was unable to test them.
For the sword and battleaxe, the call to damageItem() in hitEntity() and onBlockDestroyed() applies 1 damage to the item, making it take durability damage when hitting an entity or breaking a block respectively. Compare on most withered items, the damage applied is 0, which causes normal use to not damage the item. My recommendation is to remove the damageItem() call altogether on the sword and other withered items, as it has the same effect as calling with 0 as the damage number.
For the lumber axe, the call to damageItem() in onBlockDestroyed passes 0 like the others, but unlike all other withered items, the lumber axe calls into super(), which then applies damage to the item. Recommendation is to return true from this call instead of calling into super.
For the hoe, the damageItem call is in onItemUse() in the HoeItem base class. You can override this function, but it does nontrivial work that you might not want to duplicate.
All that said, while investigating the 1.15 code, I found three alternate ways to make an item unbreakable which may be more useful/elegant:
- Adding the NBT tag
"Unbreakable": trueto the NBT of makes the stack unbreakable. This would have to be added to each ItemStack when it is created; for example by a custom recipe. - Override
getMaxDamage()in each Item object to return 0, which causes Minecraft to treat the item as if it doesn't have durability - (recommended) Change the durability field to 0 for the
WITHERED,WITHERED_SWORD,WITHERED_BATTLEAXE, andWITHERED_PAXELmaterials in ToolMaterials.java, which will cause any item that uses those materials to have no durability, and thus be unbreakable.
Appreciate it! I do not mind at all, this is what it is posted for. It may be a bit out dated or perhaps I accidentally uploaded a broken 1.15.x code to the GitHub instead of the completed version. As I said I will try to fix this Tuesday, but am not sure of my intentions with the mod anymore, I’d like to continue it, but as a self taught learner, It gets harder and harder each update and with everything else going on, it just really takes my time away. So again, I’ll try to fix it if I can, if not then I really don’t know yet if I will continue work on the mod, only time will tell.