mojira.dev
MC-269639

Incorrect Durability Application to Stacked Items with Custom Max Stack Size and Max Damage

Description:
In the current version of the game, when max_stack_size and max_damage, are combined for an item (e.g., a diamond sword), using the item affects the durability of the entire stack. When the items in the stack are then distributed across different inventory slots or dropped, all items reflect the durability loss.

Expected Behavior:
An exception must be made.
-Only one item should exhibit a loss in durability.
For example, if a player has a stack of 10 diamond swords with a custom max_stack_size and max_damage, uses the sword, and then distributes the swords across their inventory, only the used sword should show any sign of durability loss. The remaining 9 swords should remain intact, with full durability.-

Steps to Reproduce:

  1. Use the command to give a player an item with both custom components, for example:

    give @s minecraft:diamond_sword[minecraft:max_stack_size=64,minecraft:max_damage=10]
  1. Use the item to strike an entity or mine a block, to reduce durability.

  2. In the inventory, split the stack of items across different slots.

  3. Observe that all items in the newly distributed stack show the same amount of durability loss.

Proposal for a fix :

In the "Item" class in the Components verification method, There's already an Exeption for that, but it's incomplete. To fix the bug, I guess you just need to add MAX_DAMAGE.

Current code :

DataComponentMap buildAndValidateComponents() {
    DataComponentMap dataComponentMap = this.buildComponents();
    if (dataComponentMap.has(DataComponents.DAMAGE) && dataComponentMap.getOrDefault(DataComponents.MAX_STACK_SIZE, 1) > 1) {
        throw new IllegalStateException("Item cannot have both durability and be stackable");
    } else {
        return dataComponentMap;
    }
}

Fix :

if ((dataComponentMap.has(DataComponents.DAMAGE) || dataComponentMap.has(DataComponents.MAX_DAMAGE)) && dataComponentMap.getOrDefault(DataComponents.MAX_STACK_SIZE, 1) > 1)

.

Linked issues

Comments 4

The durability could be split only when splitting the stacks rather than when the item is first damaged as well.

While analyzing the items class code, I came across this.

DataComponentMap buildAndValidateComponents() {
			DataComponentMap dataComponentMap = this.buildComponents();
			if (dataComponentMap.has(DataComponents.DAMAGE) && dataComponentMap.getOrDefault(DataComponents.MAX_STACK_SIZE, 1) > 1) {
				throw new IllegalStateException("Item cannot have both durability and be stackable");
			} else {
				return dataComponentMap;
			}
		}

To fix the bug, I guess you just need to add max_damage like tihs :

if ((dataComponentMap.has(DataComponents.DAMAGE) || dataComponentMap.has(DataComponents.MAX_DAMAGE)) && dataComponentMap.getOrDefault(DataComponents.MAX_STACK_SIZE, 1) > 1) {

Can confirm. Related closely to MC-269789.

Thank you for your report!
After consideration, the issue is being closed as Won't Fix.

Please note that this is not the same as Working as Intended, as this bug report correctly describes behavior in the game that might not be the intended or desirable behavior, but it will not be fixed right now. Sometimes, this is because the issue reported is minor and/or impossible to change without large architectural changes to the code base.

Quick Links:
📓 Bug Tracker Guidelines – 💬 Community Support – 📧 Mojang Support (Technical Issues) – 📧 Microsoft Support (Account Issues)
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 Game Wiki

Hardel

(Unassigned)

Community Consensus

(Unassigned)

24w12a

Retrieved