Skip to content

Commit

Permalink
Fixed issue with badges and overridden powers
Browse files Browse the repository at this point in the history
  • Loading branch information
eggohito committed May 30, 2024
1 parent 407250d commit 008df52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.*;
import io.github.apace100.apoli.integration.PostPowerLoadCallback;
import io.github.apace100.apoli.integration.PowerOverrideCallback;
import io.github.apace100.apoli.integration.PrePowerReloadCallback;
import io.github.apace100.apoli.power.*;
import io.github.apace100.calio.registry.DataObjectRegistry;
Expand Down Expand Up @@ -50,6 +51,7 @@ public static void init() {
//register callbacks
PrePowerReloadCallback.EVENT.register(BadgeManager::clear);
PowerTypes.registerAdditionalData("badges", BadgeManager::readCustomBadges);
PowerOverrideCallback.EVENT.register(BADGES::remove);
PostPowerLoadCallback.EVENT.register(BadgeManager::readAutoBadges);
AutoBadgeCallback.EVENT.register(BadgeManager::createAutoBadges);
ServerLifecycleEvents.SYNC_DATA_PACK_CONTENTS.addPhaseOrdering(PowerTypes.PHASE, PHASE);
Expand Down
36 changes: 12 additions & 24 deletions src/main/java/io/github/apace100/origins/util/PowerKeyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.minecraft.util.Identifier;

import java.util.HashMap;
import java.util.List;

public class PowerKeyManager {

Expand All @@ -15,32 +14,21 @@ public static void clearCache() {
}

public static String getKeyIdentifier(Identifier powerId) {
if(KEY_CACHE.containsKey(powerId)) {
return KEY_CACHE.get(powerId);
}
String key = getKeyFromPower(powerId);
KEY_CACHE.put(powerId, key);
return key;
return KEY_CACHE.computeIfAbsent(powerId, PowerKeyManager::getKeyFromPower);
}

private static String getKeyFromPower(Identifier powerId) {
if(PowerTypeRegistry.contains(powerId)) {
PowerType<?> powerType = PowerTypeRegistry.get(powerId);
Power power = powerType.create(null);
String key = "";
if (power instanceof Active) {
key = ((Active) power).getKey().key;
} else if (powerType instanceof MultiplePowerType<?>) {
List<Identifier> subs = ((MultiplePowerType<?>) powerType).getSubPowers();
for (Identifier sub : subs) {
String subKey = getKeyFromPower(sub);
if (!subKey.isEmpty()) {
return subKey;
}
}
}
return key.equals("none") ? "key.origins.primary_active" : key;

PowerType<?> power = PowerTypeRegistry.getNullable(powerId);
if (power == null || !(power.create(null) instanceof Active activePower)) {
return "";
}
return "";

String key = activePower.getKey().key;
return key.equals("none")
? "key.origins.primary_active"
: key;

}

}

0 comments on commit 008df52

Please sign in to comment.