I want to use the fish caught statistic in text. For that, I'm just writing %player:statistic fish_caught%.
However, that returns "Invalid statistic", despite it being valid. I also tried minecraft:fish_caught, but it was the same.
I looked in the code, and noticed the following:
ctx.player().getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(Identifier.tryParse("minecraft:fish_caught"))) this doesn't work, but it's basically what placeholder api does.
ctx.player().getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(Stats.FISH_CAUGHT)) this DOES work, despite it being an identifier, containing "minecraft:fish_caught"...
This is because stats are stored in an IdentityHashMap, which use reference equality. You can't make a new identifier and pass it in.
A fix would be, instead of doing getOrCreateStat(identifier), do getOrCreateStat(Registry.CUSTOM_STAT.get(identifier)). I haven't tested, but this seems to fix the issue.
I want to use the fish caught statistic in text. For that, I'm just writing
%player:statistic fish_caught%
. However, that returns "Invalid statistic", despite it being valid. I also triedminecraft:fish_caught
, but it was the same.I looked in the code, and noticed the following:
ctx.player().getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(Identifier.tryParse("minecraft:fish_caught")))
this doesn't work, but it's basically what placeholder api does.ctx.player().getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(Stats.FISH_CAUGHT))
this DOES work, despite it being an identifier, containing "minecraft:fish_caught"...This is because stats are stored in an IdentityHashMap, which use reference equality. You can't make a new identifier and pass it in.
A fix would be, instead of doing
getOrCreateStat(identifier)
, dogetOrCreateStat(Registry.CUSTOM_STAT.get(identifier))
. I haven't tested, but this seems to fix the issue.