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

Advancements: `components` does not work with floats

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • None
    • 1.20.6, 24w21b, 1.21 Pre-Release 2, 1.21 Release Candidate 1, 1.21
    • Windows 11
    • Community Consensus
    • Advancements, Data Packs

      the following advancement should trigger when a player picks up a bucket of tropical fish with the `BucketVariantTag` set to `67502593`:

       

      {
        "display": {
          "icon": {
            "id": "minecraft:warped_fungus",
            "count": 1
          },
          "title": {
            "text": "triggered"
          },
          "description": {
            "translate": "advancements.husbandry.tactical_fishing.description"
          }
        },
        "parent": "minecraft:husbandry/fishy_business",
        "criteria": {
          "tropical_fish_bucket": {
            "trigger": "minecraft:inventory_changed",
            "conditions": {
              "items": [
                {
                  "items": "minecraft:tropical_fish_bucket",
                  "components": {
                    "minecraft:bucket_entity_data": {
                      "BucketVariantTag":67502593
                    }
                  }
                }
              ]
            }
          }
        },
        "requirements": [
          [
            "tropical_fish_bucket"
          ]
        ],
        "sends_telemetry_event": false
      }

      However it doesn't work because the components needs an exact match as most naturally caught tropical fish would have a health tag, an exact match can be created with 

      /give @s minecraft:tropical_fish_bucket[minecraft:bucket_entity_data={BucketVariantTag:67502593}]
      

      So the modified version should work: 

      {
        "display": {
          "icon": {
            "id": "minecraft:warped_fungus",
            "count": 1
          },
          "title": {
            "text": "triggered"
          },
          "description": {
            "translate": "advancements.husbandry.tactical_fishing.description"
          }
        },
        "parent": "minecraft:husbandry/fishy_business",
        "criteria": {
          "tropical_fish_bucket": {
            "trigger": "minecraft:inventory_changed",
            "conditions": {
              "items": [
                {
                  "items": "minecraft:tropical_fish_bucket",
                  "components": {
                    "minecraft:bucket_entity_data": {
                      "Health": 3.0,
                      "BucketVariantTag":67502593
                    }
                  }
                }
              ]
            }
          }
        },
        "requirements": [
          [
            "tropical_fish_bucket"
          ]
        ],
        "sends_telemetry_event": false
      }
      

      But this too doesn't work as in json the 3.0 of the health tag will be implicitly casted to an int and result in health:3b where as the natural occuring ones will be floats so health:3.0f. In effect this renders them inaccessible for advancements with the recent changes, `minecraft:bucket_entity_data` should be able to check for the tags given not an exact match (which I presume was simpler to implement with "==").

      This can be further proven by using a health value that cannot be casted into an integer, such as 2.5, if you change the advancement to trigger on 2.5 health and then spawn a tropical fish with that BucketVarientTag it will work just fine. Unfortunately fish spawn with 3.0 health. Like with this command:

      /give @s minecraft:tropical_fish_bucket[minecraft:bucket_entity_data={BucketVariantTag:67502593,Health:2.5f}]
      

       

      Another way to check this is by giving yourself a fish with interger health with the command below, this will trigger the advancement as it matches the integer 3 for health

      /give @s minecraft:tropical_fish_bucket[minecraft:bucket_entity_data={BucketVariantTag:67502593,Health:3d}]
      

       

      How to reproduce:

      1. Add datapack-BucketVariantTag.tag to a world
      2. Spawn a tropical fish with the `BucketVariantTag` set to 67502593
      3. Catch the fish in a water bucket and that should trigger the advancement but it won't
      4. if you use the following command it will as it lacks the health tag "/give @s minecraft:tropical_fish_bucket[minecraft:bucket_entity_data=
        {BucketVariantTag:67502593}

        ]"

      5. The same can be done with datapack-BucketVariantTag&Health.tag and the command would be "/give @s minecraft:tropical_fish_bucket[minecraft:bucket_entity_data=
        {BucketVariantTag:67502593,Health:3b}

        ]" 

      Expected result:

      1. the advancement should trigger when a fish with the "BucketVariantTag" of 67502593 is caught and the health is 3.0

      Actual result:

      1. the advancements do not trigger be cause the 3.0 is converted into an interger and since "3d" != "3f"

      I've attached test datapacks to show these behaviours, one checking for the `BucketVariantTag` another checking for both the tags

            Unassigned Unassigned
            zer0p1us zer0p1us
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: