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

"minecraft:damage" component value has unexpected integer behaviour

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.20.80.23 Preview
    • None
    • Confirmed
    • Windows
    • 1235577

      Update: A Mojira moderator has told me to merge MCPE-180074 into this report. I have updated the description, attachements, and title to reflect this merge

      According to the [official docs|https://learn.microsoft.com/en-us/minecraft/creator/reference/content/itemreference/examples/itemcomponents/minecraft_damage?view=minecraft-bedrock-stable] the "minecraft:damage" component supports an integer type. However, upon further testing, it seems that it uses the following formula:

      value = value % 256

      rather than using the actual value.

      More so, the component seems to be using a signed 16-bit integer which causes unexpected/unwanted behaviour. 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.23
      • Give yourself the following items:
        • mojira:damage_255
        • mojira:damage_256
        • mojira:damage_257
        • mojira:damage_32767
        • mojira:damage_32768
        • mojira:damage_32769
        • mojira:damage_65536
      • Open your inventory and hover over the items

      Expected Result:

      • mojira:damage_255 should have a "+255 attack damage" tooltip
      • mojira:damage_256 should have a "+256 attack damage" tooltip
      • mojira:damage_257 should have a "+257 attack damage" tooltip
      • mojira:damage_32767 should have a "+255 attack damage" tooltip
      • mojira:damage_32768 should have no "attack damage" tooltip
      • mojira:damage_32769 should have a "+1 attack damage" tooltip
      • mojira:damage_65536 should have no "attack damage" tooltip

      Actual Result:

      • mojira:damage_255 has a "+255 attack damage" tooltip
      • mojira:damage_256 has no "attack damage" tooltip
      • mojira:damage_257 has a "+1 attack damage" tooltip
      • mojira:damage_32767 has a "+255 attack damage" tooltip. The item does parse correctly.
      • mojira:damage_32768 throws a content log error. The item does not parse correctly thus rendering the item broken.
      • mojira:damage_32769 throws a content log error. The item does not parse correctly thus rendering the item broken.
      • mojira:damage_65536 has no "attack damage" tooltip. The item does parse correctly.

        1. mojira.mcpack
          3 kB
          SmokeyStack
        2. Screenshot 2024-03-26 172706.png
          385 kB
          SmokeyStack
        3. 2024-03-26 17-11-35.mp4
          727 kB
          SmokeyStack

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

              Created:
              Updated:
              CHK: