[SPIGOT-6069] ItemStack.getData() and ItemStack.setData(...) cause legacy material init Created: 13/Aug/20  Updated: 13/Aug/20  Resolved: 13/Aug/20

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Oscar Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: 1.13, bukkit
Environment:

Affects Minecraft versions 1.13+


Version: git-Paper-135 (MC: 1.16.1)
Guidelines Read: Yes

 Description   

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;
}

 



 Comments   
Comment by md_5 [ 13/Aug/20 ]

MaterialData itself is marked deprecated. It's a bit hard to manually deprecate every method referring to it

Generated at Fri Apr 11 15:30:24 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.