KubeJS

KubeJS

69M Downloads

`PlayerStatsJS#get` does not work

ChiefArug opened this issue ยท 0 comments

commented

Minecraft Version

1.19.2

KubeJS Version

6bfa1f

Rhino Version

1802.2.2-build.229

Architectury Version

5.2.72

Forge/Fabric Version

43.1.3

Describe your issue

PlayerStatsJS accepts a resource location, then uses Stats.CUSTOM#get to get the stat object. CUSTOM is a StatType, which uses an IndentityHashMap to store its values.
The IdentityHashMap has this in its JavaDoc:

if this map contains a mapping from a key k to a value v such that (key == k), then this method returns v; otherwise it returns null

This means that even though the ResourceLocation passed in and the ResourceLocation in the map as a key have identical paths and locations, they are not == and so the map returns null, which then ends up throwing an error Cannot invoke "net.minecraft.resources.ResourceLocation.toString()" because "p_12866_" is null when trying to convert it to a stat location.

The solution is probably to add a binding for Stats, and get players to use that to pass in a stat id (Stats has public static fields for each of the stats that stores the same ResourceLocation the IdentityHashMap has)

Crash report/logs

No response