mojira.dev
MC-266762

ItemStack.class work incorrectly

public static final ItemStack EMPTY = new ItemStack((Void)null);

This EMPTY cause some problem. First - programmer or modder dont know that instance is "EMPTY", if no check. Than he can set nbt to EMPTY item.

And it cause some bug:
Select item with nbt. Drop item. run in java System.out.println(Minecraft.getInstance().player.getMainHandItem().save(new CompoundTag()));
Expect - {id:"minecraft:air",Count:1b}
Got - {id:"minecraft:air",Count:1b,tag:{...}}

How to fix it?
replace EMPTY = new ItemStack((Void)null); to
new ItemStack((Void)null) {
public void setTag(@Nullable CompoundTag compoundTag) {}
public CompoundTag getOrCreateTag() {return new CompoundTag();}
public CompoundTag save(CompoundTag compoundTag) {compoundTag.putString("id","minecraft:air");compoundTag.putByte("Count",(byte)1)}
}

It will help modding and Mojang.

Comments 4

What's the gameplay impact of this? How can one experience this in-game without mods?

Nothing, but while i creating mod, i check item nbt and ignore count of item and id of item. Than got error - after drop item check empty slot, see nbt, run some functions. And it will optimize minecraft.

Sorry, but only issues that affect vanilla gameplay or data/resource pack development are accepted.

If you can figure out how this bug would affect normal vanilla gameplay, please create a new ticket.

Hunter

(Unassigned)

Unconfirmed

(Unassigned)

1.20.2, 23w46a

Retrieved