mojira.dev
MC-217290

Advancement inventory_changed with item count of 0

Consider the following advancement:

{
  "criteria": {
    "test": {
      "trigger": "minecraft:inventory_changed",
      "conditions": {
        "items": [ {
          "item": "minecraft:stone",
          "count": 0
        } ]
      }
    }
  },
  "rewards": { "experience": 1 }
}

If we follow the logic, whenever a player's inventory is changed, if they don't have any stone in it, they should be granted 1 exp point.

But what is happening is that the advancement is never triggered. The behavior is the same if we put "max" to 0 for the count.

 

This is a bug, since this logic can be achieved with the following advancement, meaning that the "inventory_changed" trigger is properly triggered when you remove the last of a certain item from your inventory:

{
  "criteria": {
    "test": {
      "trigger": "minecraft:inventory_changed",
      "conditions": {
        "player": [ {
          "condition": "minecraft:inverted",
          "term": {
            "condition": "minecraft:entity_properties",
            "entity": "this",
            "predicate": { "nbt": "{ Inventory: [ { id: 'minecraft:stone' } ] }" }
          }
        } ]
      }
    }
  },
  "rewards": { "experience": 1 }
}

But this is not as flexible as the "items" condition approach (for example item tags are not available), it is heavier to process, and it is very ugly.

I included a small data pack to quickly test if the bug is fixed: when your inventory changes, if you have no stone in it, you get a message saying which method triggered the advancement (item or NBT).

Attachments

Comments 3

can confirm in 21w11a

⚠️ Please do not add Affected Versions to resolved reports.

Have a look at the Resolution and the comments to see why this ticket has been resolved. If you think this ticket has been resolved erroneously you can contact the Mojira staff on Discord or Reddit.

-- I am a bot. This action was performed automatically! If you think it was incorrect, please notify us on Discord or Reddit

How the hell is it "working as intended" ?

  1. It's totally legit to check if a player doesn't have an item anymore in their inventory: for example you can refill some blocks when they have used all.

  2. There is a workaround to achieve the same behavior but with a lot more complicated and resource consuming method, so why not let the possibility to do it with the simplier, more resource friendly one?

  3. This is not logic: 0 is a possible count for an item, for example by running « execute store result storage test count int 1 run clear @s minecraft:stone 0 » you may get a value of 0.

I understand that it may not be very urgent, but why just reject it?

 

By the way, I didn't receive an email saying that the ticket was closed while I'm surveying it.

AHL

(Unassigned)

Community Consensus

21w08b, 21w10a, 21w11a, 21w14a, 21w15a, 21w17a, 21w18a

Retrieved