11package dev .ftb .mods .ftbranks .impl .condition ;
22
33import dev .ftb .mods .ftblibrary .snbt .SNBTCompoundTag ;
4+ import dev .ftb .mods .ftbranks .FTBRanks ;
45import dev .ftb .mods .ftbranks .api .RankCondition ;
6+ import dev .ftb .mods .ftbranks .api .RankException ;
7+ import net .minecraft .core .registries .BuiltInRegistries ;
58import net .minecraft .resources .ResourceLocation ;
69import net .minecraft .server .level .ServerPlayer ;
710import net .minecraft .stats .Stat ;
@@ -25,7 +28,23 @@ public class StatCondition implements RankCondition {
2528
2629 public StatCondition (SNBTCompoundTag tag ) {
2730 statId = new ResourceLocation (tag .getString ("stat" ));
28- stat = Stats .CUSTOM .get (statId );
31+
32+ ResourceLocation actualId = BuiltInRegistries .CUSTOM_STAT .get (statId );
33+ if (actualId == null ) {
34+ // workaround for a bug where mods might register a modded stat in the vanilla namespace
35+ // https://github.com/FTBTeam/FTB-Mods-Issues/issues/724
36+ actualId = BuiltInRegistries .CUSTOM_STAT .get (new ResourceLocation (statId .getPath ()));
37+ }
38+ if (actualId == null ) {
39+ // shouldn't happen, but in case the stat is missing...
40+ stat = null ;
41+ value = 0 ;
42+ valueCheck = EQUALS ;
43+ FTBRanks .LOGGER .warn ("could not get stat for {} / {} - condition will not function" , getType (), statId );
44+ throw new RankException ("Invalid stat ID: " + statId );
45+ }
46+
47+ stat = Stats .CUSTOM .get (actualId );
2948 value = tag .getInt ("value" );
3049
3150 switch (tag .getString ("value_check" )) {
@@ -45,6 +64,8 @@ public String getType() {
4564
4665 @ Override
4766 public boolean isRankActive (ServerPlayer player ) {
67+ if (stat == null ) return false ;
68+
4869 int v = player .getStats ().getValue (stat );
4970
5071 return switch (valueCheck ) {
0 commit comments