transformDamage doesn't respect Unbreaking enchantment
DoomRater opened this issue ยท 2 comments
Issue Description:
The Unbreaking enchantment reduces the chance of an item taking durability damage upon use to 1/(1+n), where n is the level of Unbreaking. So Unbreaking 1 means the item has a 50% chance of receiving damage.
What happens:
When I craft MrCrayFish logs using CraftTweaker, the axe always receives one point of damage each crafting attempt regardless of what Unbreaking value is upon a tool. I placed Unbreaking III on the tool and it always lost a point of durability each craft attempt.
What you expected to happen:
transformDamage() should apply the chance to apply damage according to the tool's Unbreaking level. At Unbreaking III, the odds are 1 in 4, or 25% to apply one point of damage each craft attempt.
Script used (Please Pastebin or gist your script, posting an unpasted or ungist'd script will automatically close this issue):
Affected Versions (Do not use "latest"):
- Minecraft: 1.12.2
- Forge: 14.23.5.2838
- Crafttweaker: 1.12-4.1.19
- Using a server: not in this example
I honest;y don't believe that the enchantment should have an effect on this, what you're asking for is really niche and not what people have grown to expect (having items not take 1 damage all the time)
Hi @DoomRater,
This might be how it's supposed to work, otherwise I think you have no way to reliably damage an item with Unbreaking.
If you want to account for Unbreaking, maybe you can use a custom itemTransformer, as documented there.
Something of the sort should work (untested; I use ContentTweaker to get a random generator):
import crafttweaker.item.IItemStack;
import crafttweaker.world.IWorld;
import mods.contenttweaker.World;
import mods.contenttweaker.Random;
transformedItem = item.transformNew(function(item as IItemStack){
var unbreaking_lvl = 0 as int;
for ench in item.enchantments {
if (ench.definition == <enchantment:minecraft:unbreaking>)
unbreaking_lvl += ench.level;
}
var rand = IWorld.toContentTweakerWorld(IWorld.getFromID(0)).getRandom() as Random;
if (rand.nextInt(unbreaking_lvl + 1) == 0) {
return item.transformDamage();
} else {
return item;
}
});