mojira.dev
MC-127748

The loot table function set_damage not applied if the item is unbreakable

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_rod

Code 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

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.

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.

Ok, what? now it works?

EDIT: oooh, found the cause now.

Present in 1.13-pre7

2 more comments

Please do not mark unreleased versions as affected.
You don't have access to them yet.

user-f2760

AlexMCool

(Unassigned)

Confirmed

Platform

Low

Loot tables

loot-table

Minecraft 1.12.2, Minecraft 18w11a, Minecraft 18w19b, Minecraft 1.13-pre5, Minecraft 1.13-pre6, ..., 20w30a, 1.16.2 Pre-release 1, 1.16.2 Pre-release 2, 1.16.2 Pre-release 3, 1.16.2 Release Candidate 1

Retrieved