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

Casting data with /data get ... [scale]

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • None
    • 1.17.1
    • None
    • Unconfirmed
    • (Unassigned)

      If you get a value from the NBT storage with /data get storage ...and scale it (using the scale parameter), that same value is only casted and stored as an integer value.

      This has the implication that operations with values between 0 and 1 are impossible and all operations have rounding errors because they are truncated incorrectly. Even if said value is written back to a double NBT storage, it is of no use, because /data get ... [scale] returns only INT values anyway. So it would be advantageous to:

      a) Include a round() before the cast to Int to fix the rounding error.
      b) If a /data get ... [scale] function is used, that its return type is changed to Double. [PREFERRED]

      ----------------------------------------------------------------------------------------------------

      Example:
      /data merge storage minecraft:villaton {test_1:48}  -----> Store Value 48
      /execute store result storage minecraft:villaton test_2 double 1 run data get storage minecraft:villaton test_1 0.1 -------> Divide Value 48 by 0.1 and save it. Returns 4 instead of 4.8 or 5.

      /execute store result storage minecraft:villaton test_2 double 1 run data get storage minecraft:villaton test_1 0.01 ----------> Dividing the value by 0.01 returns 0 instead of 0.48. Theoreticly this is rounded correctly. But if it would be 98 divided by 0.01 it would still be 0. Also it is not possible to use ist as decimal at all, because it always is returned as INT by the scale operation.

      --------------------------------------------------------------------------------------------------------

       

            Unassigned Unassigned
            Villaton William Villaton
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: