Skip to content

Commit 669a892

Browse files
committed
fix: stat lookup for StatCondition
FTBTeam/FTB-Mods-Issues#1610
1 parent 3fdd373 commit 669a892

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

common/src/main/java/dev/ftb/mods/ftbranks/impl/condition/StatCondition.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package dev.ftb.mods.ftbranks.impl.condition;
22

33
import dev.ftb.mods.ftblibrary.snbt.SNBTCompoundTag;
4+
import dev.ftb.mods.ftbranks.FTBRanks;
45
import dev.ftb.mods.ftbranks.api.RankCondition;
6+
import dev.ftb.mods.ftbranks.api.RankException;
7+
import net.minecraft.core.registries.BuiltInRegistries;
58
import net.minecraft.resources.ResourceLocation;
69
import net.minecraft.server.level.ServerPlayer;
710
import 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

Comments
 (0)