Uploaded image for project: 'Minecraft (Bedrock codebase)'
  1. Minecraft (Bedrock codebase)
  2. MCPE-180112

"minecraft:durability" component values above 32767 can result in negative values.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.20.80.24 Preview
    • None
    • Unconfirmed
    • Windows

      According to the [official docs|https://learn.microsoft.com/en-us/minecraft/creator/reference/content/itemreference/examples/itemcomponents/minecraft_durability?view=minecraft-bedrock-stable] the "minecraft:ddurability" component supports an integer type for its "max_durability". However, upon further testing, it seems to be using a signed 16-bit integer. This causes certain ranges of values to appear as negative which causes the Bedrock Engine to think the value is a negative number, even if the value is a positive number.

      This occurs due to the 2's complements for 16-bit integer. The negative ranges formula is, inclusive beginning and exclusive ending where x can be any arbitrary number.

      [256*(256x+128), 256*(256(x+1)))

      As an example, if x is 0, the range for negative values are [32768, 65536) which the below reproduction method below supports

      Reproduce:

      • Download the attached pack below
      • Import the pack into Preview 1.20.80.24
      • Enable the "Beta APIs" experimental toggle
      • Give yourself the following items:
        • mojira:durability_32767
        • mojira:durability_32768
        • mojira:durability_32769
        • mojira:durability_65535
        • mojira:durability_65536
        • mojira:durability_65537
      • Run the command "scriptevent test:test". For ease of use, in the video attached, I have a command block that runs "execute as @a run scriptevent test:test" which achieves the same result. 

      Expected Result:

      • mojira:durability_32767 should have "32767" max durability
      • mojira:durability_32768 should have "32768" max durability
      • mojira:durability_32769 should have "32769" max durability
      • mojira:durability_65535 should have "65535" max durability
      • mojira:durability_65536 should have "65536" max durability
      • mojira:durability_65537 should have "65537" max durability

      Actual Result:

      • mojira:durability_32767 has "32767" max durability
      • mojira:durability_32768 has "-32768" max durability
      • mojira:durability_32769 has "-32767" max durability
      • mojira:durability_65535 has "-1" max durability
      • mojira:durability_65536 has "0" max durability
      • mojira:durability_65537 has "1" max durability

            SmokeyStack SmokeyStack
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: