mojira.dev
MCPE-180073

"minecraft:damage" component value has unexpected integer behaviour

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 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(As of 27/08/2024, I have attached an updated version to keep the item format and min engine version to 1.21.30)

  • Import the pack into Preview 1.21.30.24

  • 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.

Linked issues

Attachments

Comments 5

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

Seems to me that the content log error should say the value must be >= 0 and <= 255, and the game should fail to parse anything outside those bounds. I don't understand why you would expect 32767 damage to be functional and yet convert to 255.

@GoldenHelmet The issue is the content log does not say it expects a value from [0, 255], all it says it needs to be a value >= 0 per the content log. If that is the case, then the content log error should be updated, if not, then it needs to stop using the modulus formula. Other components such as "minecraft:use_modifiers -> "movement_modifier" have content log errors that specifically states it has to be within [0,1] and doesn't parse the item correctly. It does not just say, "Value must be >= 0" and use a modulus formula.

>I don't understand why you would expect 32767 damage to be functional and yet convert to 255.

I don't expect it to convert to 255, I expect it to have a damage of 32767 but due to this bug, it converts to 255

Can confirm, tested in 1.20,80.24.

Can confirm, tested in 1.21.44 on Xbox

SmokeyStack

(Unassigned)

1235577

Confirmed

Multiple

1.20.80.23 Preview, 1.21.60.24 Preview

Retrieved