Mojira Archive
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.

Invalid

Hunter

2023-11-17, 11:46 AM

2023-11-17, 01:15 PM

2023-11-17, 01:15 PM

0

1

Unconfirmed

(Unassigned)

1.20.2, 23w46a

-