Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-6069

ItemStack.getData() and ItemStack.setData(...) cause legacy material init

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Minor Minor
    • None
    • None
    • Affects Minecraft versions 1.13+

    • git-Paper-135 (MC: 1.16.1)
    • Yes

      Calling ItemStack.getData() or ItemStack.setData(...) causes legacy material support initialization{{}}:

      Initializing Legacy Material Support. Unless you have legacy plugins and/or data this is a bug!

      The server freezes for a second while it does some legacy material magic before returning a legacy material (e.g. LEGACY_DIRT, instead of{{ DIRT}}).

      The documentation does not mention this behavior.

      As I feel we all would prefer to work with new, better DIRT over old, horrible LEGACY_DIRT, I think the method should be annotated as deprecated and/or the documentation should be updated to make users aware of this (misleading) behavior.

      One of the methods in question looks like so:

      /**
      {{ * Gets the MaterialData for this stack of items}}
      {{ *}}
      {{ * @return MaterialData for this item}}
      {{ */}}
      @Nullable
      public MaterialData getData() {
          Material mat = Bukkit.getUnsafe().toLegacy(getType());
          if (data == null && mat != null && mat.getData() != null) {
              data = mat.getNewData((byte) this.getDurability());
      {{    }}}

          return data;
      }

       

            Unassigned Unassigned
            otoomey Oscar
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: