mojira.dev
MCPE-180112

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

According to the official docs the "minecraft:durability" 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

Steps to reproduce:

  1. Download and import the attached pack(As of 27/08/2024, I have attached an updated version to keep the item format and min engine version to 1.21.30)

  2. Create/open a world with the add-on

  3. Run

    /give @s mojira:durability_32767
    /give @s mojira:durability_32768
    /give @s mojira:durability_32769
    /give @s mojira:durability_65535
    /give @s mojira:durability_65536
    /give @s mojira:durability_65537
  1. Run /scriptevent test:test test. For ease of use, in the video attached, I have a command block that runs execute as @a run scriptevent test: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

Linked issues

Attachments

Comments 1

[media][media][media][media]

SmokeyStack

(Unassigned)

1357406

Confirmed

Windows

1.20.80.24 Preview, 1.21.22 Hotfix

Retrieved