Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-269639

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • None
    • 24w12a
    • None
    • Community Consensus
    • (Unassigned)

      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)
      

      .

            Unassigned Unassigned
            Hardel Hardel
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: