Open Jannyboy11 opened 2 hours ago
Material isn't backed by an registry, so, I'm not really sure what the expected behavior would be otherwise?
Material isn't backed by an registry, so, I'm not really sure what the expected behavior would be otherwise?
To not have an exception thrown.
The method should still yield null if that is the method contract instead of throwing an exception yea. The entire "registry lookup by class type" is deprecated af on paper anyway, fixing this won't have a negative impact on the paper registry API alterantives.
So what is the correct way to obtain all available Materials on Paper? Continue to use Material.values()
?
Yes, as Materials are not a registry concept, that's a bukkit/spigot concept, mojang doesn't have a registry of all Materials
BukkitägetRegistry(Material.class) will always return null, so yea. Will still fix that it is throwing instead of yielding null, so, pls keep the issue open.
Yes, as Materials are not a registry concept, that's a bukkit/spigot concept, mojang doesn't have a registry of all Materials
So this announcement on the PaperMC Discord is fake news then? I quote:
Going beyond this, please especially make sure you move away from Material.values() calls and instead get them [via the Registry API](https://jd.papermc.io/paper/1.21/io/papermc/paper/registry/RegistryAccess.html#getRegistry(io.papermc.paper.registry.RegistryKey)) (or the [upstream compatible one](https://jd.papermc.io/paper/1.21/org/bukkit/Server.html#getRegistry(java.lang.Class)))
We'll fix it, but that would be
Registry.MATERIAL
or if you already want to use the future/wip api
for (final ItemType itemType : Registry.ITEM) {
...
}
// or getting it via the key, which is slightly more future-proof
RegistryAccess.registryAccess().getRegistry(RegistryKey.BLOCK)...
I also edited the Discord announcement to clarify these
Expected behavior
Per Bukkit Javadocs, the Server#getRegistry(Class) method returns null when a registry is not available for the given Keyed class.
Observed/Actual behavior
Paper asserts that a registry must exists and throws a NullPointerException:
Steps/models to reproduce
/invgive Notch
and then press tab to tabcomplete materials.Plugin and Datapack List
Plugins: InvSeePlusPlus, InvSeePlusPlus_Give
No datapacks were used.
Paper version
This server is running Paper version 1.21.1-DEV-master@925c3b9 (2024-09-08T17:37:37Z) (Implementing API version 1.21.1-R0.1-SNAPSHOT)
I know this is running 16 versions behind, but the bug seems to be present still, per this patch: https://github.com/PaperMC/Paper/blob/master/patches/server/0471-Add-RegistryAccess-for-managing-Registries.patch#L878
Other
Per this message on the PaperMC discord, I implemented this new method to obtain the set of available materials on the server, as can be seen in the source code of my plugin here (using the 'upstream compatible' api): https://github.com/Jannyboy11/InvSee-plus-plus/blob/5c09d698fa74d302ae88d50dcdc02a79036b0735/InvSee%2B%2B_Platforms/Impl_1_21_1_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_21_1_R1/InvseeImpl.java#L344
If this is the incorrect way to do it, then I'd like to know.