Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Consider retaining public visibility for CraftItemStack#asBukkitCopy(ItemStack)

Open FxRayHughes opened this issue 4 months ago • 8 comments

Is your feature request related to a problem?

In the combined 26.2 development changes (#14001), CraftItemStack#asBukkitCopy(net.minecraft.world.item.ItemStack) was changed from public to private, while a new public overload accepting ItemInstance was introduced.

Our project is a dependency library that provides a compatibility layer across multiple Minecraft server versions. Because of that, lower-level conversion methods such as this one are particularly important to us when the required functionality is not consistently available through the public API.

Existing library binaries compiled against previous Paper versions reference the original asBukkitCopy(ItemStack) method directly. Changing its visibility to private causes those binaries to fail on the new version, rather than allowing them to use the new ItemInstance overload.

This breaks the shared compatibility path used across all previously supported versions and requires a version-specific library update.

We understand that CraftBukkit and NMS internals do not provide backward-compatibility guarantees. We are not requesting such a guarantee generally; we are only asking whether this specific compatibility break could be avoided because the original method can remain available alongside the new overload.

Describe the solution you'd like.

Please consider keeping the existing overload public:

public static ItemStack asBukkitCopy(net.minecraft.world.item.ItemStack original) {
    return asCraftMirror(original.copy());
}

The new asBukkitCopy(ItemInstance) overload could remain unchanged. Since net.minecraft.world.item.ItemStack implements ItemInstance, retaining both overloads should preserve the current behavior while allowing existing binaries to continue resolving the original method.

This would avoid a significant compatibility disruption with what appears to be very little additional implementation or maintenance cost.

Describe alternatives you've considered.

We can add a version-specific implementation to our compatibility library, for example by copying the NMS stack and passing it to asCraftMirror, and then publish an updated library version.

We will take that approach if retaining the method is not considered appropriate. However, it would require downstream projects to update their dependency solely because of this visibility change, so we wanted to ask whether preserving the existing overload could be considered first.

Other

Thank you for considering this request. We appreciate that this concerns an internal API and understand if an exception cannot be made.

FxRayHughes avatar Jul 17 '26 03:07 FxRayHughes

Why are libraries poking server internals expecting to continue working on future versions?

mbax avatar Jul 17 '26 03:07 mbax

Why are libraries poking server internals expecting to continue working on future versions?

This is also a very common operation. A GitHub code search shows that many plugins and libraries call this method directly, so the impact is not limited to our project.

We understand that it is an internal API and that compatibility is not guaranteed. However, given its widespread usage and the relatively low cost of retaining the existing overload, we believe this specific case is worth reconsidering. If preserving it is not feasible, we will adapt our compatibility layer accordingly.

FxRayHughes avatar Jul 17 '26 03:07 FxRayHughes

Why are libraries poking server internals expecting to continue working on future versions?

Isn't this normal practice? Some operations are impossible with just the encapsulated bukkit methods. Using the internal implementation allows for more flexibility and more possibilities. We can't keep asking you to add new methods every time, and those requests might be rejected. Our use of the internal implementation doesn't affect your server's operation, but your modification makes it unusable for us, requiring us to spend time making compatibility adjustments and increasing the workload for others. If you think we shouldn't access the internal implementation, how can the encapsulated methods perform more operations?

Jie-150 avatar Jul 17 '26 04:07 Jie-150

If you think we shouldn't access the internal implementation, how can the encapsulated methods perform more operations?

The question was about asking to revert internal changes, not about the usage. Libraries that are poking around in internals should be preparing compatibility layers for different versions

masmc05 avatar Jul 17 '26 07:07 masmc05

While I agree that it wouldn't hurt anyone to make this method public again, you should keep in mind that internals are internals, they're not a part of the public stable API. You could for example use MethodHandles to access that method, they are much faster than reflection, almost as fast as direct call, and they would (for now) work for all versions.

GliczDev avatar Jul 17 '26 10:07 GliczDev

Lucky for you I found a reason to update the code there, so I also made that method public again. It's eventually going to break much more than that though, and this is ofc a rare nicety etc. etc.

kennytv avatar Jul 17 '26 11:07 kennytv

While I agree that it wouldn't hurt anyone to make this method public again, you should keep in mind that internals are internals, they're not a part of the public stable API. You could for example use MethodHandles to access that method, they are much faster than reflection, almost as fast as direct call, and they would (for now) work for all versions.

This raises a question: if it's almost as fast as a simple call, why go through a detour to execute it when you can call it directly? Secondly, it's encapsulated content; why make it private? I understand you say it's the core logic, but it only converts internal item objects into Bukkit items, which doesn't affect the server's correct operation. Why make it private? You said you created another class; you could keep this and let another class with the same name handle it, instead of removing or making it private. If you use my library, and I make this type of method private in the next update, what will you choose? Continue using my library or create your own? If it's unstable, you can add a tag instead of directly deleting or making it private.

Jie-150 avatar Jul 17 '26 11:07 Jie-150

This is internal code, not an exposed part of a library, nobody makes guarantees over the ABI of internals which exist solely for their own code, where practices like the least visibility requires for a method is usually the default.

ItemStacks in the API have been modified a lot over the past few years, methods like a bukkit copy make limited sense when bukkit stacks a wrapper over a mojang stack

electronicboy avatar Jul 17 '26 11:07 electronicboy