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

ItemStack.class work incorrectly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • None
    • 1.20.2, 23w46a
    • None
    • Unconfirmed
    • (Unassigned)

      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.

            Unassigned Unassigned
            dimburov Hunter
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: