mojira.dev

Oligo

Assigned

No issues.

Reported

MC-277015 Functions containing uninstantiated macro commands terminate function tag completion Works As Intended MC-252228 Inventory_changed advancement trigger captures intermediate inventory states Won't Fix

Comments

I've been testing this in 1.18.2 and I was not able to replicate this behavior. The vine disappears and there is no ghost item.

HOWEVER, I have still noticed some interesting behavior when using rewarded functions and moving items within the inventory.

My testing setup:

1. Place a shulker box in a the world at 0 -61 0 and replace the player's first inventory slot with an item (in my example it's a diamond).

2. Create an inventory_changed advancement which rewards a function which copies the player's hotbar into a shulker box:

say inventory changed
data modify block 0 -61 0 Items set from entity @s Inventory

3. Now move the diamond in the first hotbar slot to the second hotbar slot (open inventory GUI, hover over second slot, and press 1 button).

This should cause the diamond to move to the second slot and the "inventory changed" message displays in chat.

However, when you open the shulker box there will be two diamonds in the inventory spots corresponding to where the item started and where it ended. This turns out to be an intermediate inventory state that is normally not visible to the player.

If we repeat the same steps previously but this time add a command to our function file which removes the inventory_change advancement:

advancement revoke @s only [advancement]

you will notice the "inventory changed" message prints twice and the shulker inventory should accurately reflect the player's inventory.

This demonstrates that minecraft handles inventory changes in two steps:

1. The game copies the item from the initial slot to the destination slot while holding any item in the destination slot in some storage space. This change is reflected in the first inventory_changed advancement granted.

2. The game then takes the item in storage space and places it into the initial slot. This change is reflected in the second inventory_changed advancement granted.

The inventory_changed advancement returns the function so fast it is able to resolve both of these steps in-game. I am unsure whether this behavior is intended by the devs or not, hence why I am leaving this as a comment.

If you wish to avoid this behavior, one can simply remove the function reward from the advancement and run a command as every player with the advancement in a tick function:

execute as @a[advancements={[advancement]=true}] run [function]