The bug
See title, the tool is not getting a Damage value when it is also setting Unbreakable.
Loot table used to test:
{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:fishing_rod",
"functions": [
{
"function": "set_nbt",
"tag": "{Unbreakable:1b}"
},
{
"function": "set_damage",
"damage": 0.5
}
]
}
]
}
]
}{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:fishing_rod",
"functions": [
{
"function": "set_nbt",
"tag": "{Unbreakable:1b}"
},
{
"function": "set_damage",
"damage": 0.5
}
]
}
]
}
]
}The log file returns the following:
[20:27:25] [Server thread/WARN]: Couldn't set damage of loot item 1xitem.minecraft.fishing_rod[20:27:25] [Server thread/WARN]: Couldn't set damage of loot item 1xitem.minecraft.fishing_rodCode analysis
Using MCP1.12 names, in method net.minecraft.world.storage.loot.functions.apply(), it checks if the item can be damaged using isItemStackDamageable(), which returns false if the item does have a damage value but is set to Unbreakable. It could check instead if getMaxDamage() isn't 0.
Comments 12
Even with damage set to 0.5 it doesn't give the item any damage for me...
I used the exact loot table as above, but with 0.5 rather than 0.985, yet it gives Damage 0, so I'm going to reopen this.
Relates to MC-264285
Tested in both 1.12.2 and 1.13-pre3.
This loot table doesn't work in either. However, changing the damage to 0.5 works in both. 0.98 also works fine.
After looking at the code, 0.985 gets rounded to 0.99, a float "f" is set as 1.0 - 0.99 = 0.01, 0.01 is multiplied by the max stack damage 64 which equals 0.64, and is floored to 0, resulting in no change.