Skip to content

Commit

Permalink
Rich Presence Helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Mar 30, 2024
1 parent 46147d7 commit 9c8b483
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 3 deletions.
7 changes: 7 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ dependencies {
// Effortless Building (from CurseForge)
compileOnly rfg.deobf("curse.maven:effortless-building-302113:2847346") // Version 2.16

// Better Questing Unofficial (from CurseForge)
compileOnly rfg.deobf("curse.maven:better-questing-unofficial-629629:5183601") // Version 4.2.2

/* -------------------------------- Soft Deps, Multiple Runtime Declaration -------------------------------- */
if (project.enable_draconic.toBoolean() || project.enable_thermal.toBoolean()) {
runtimeOnly "curse.maven:redstone-flux-270789:2920436" // Version 2.1.1.1
Expand Down Expand Up @@ -188,6 +191,10 @@ dependencies {
runtimeOnly "curse.maven:effortless-building-302113:2847346" // Version 2.16
}

if (project.enable_bqu.toBoolean()) {
runtimeOnly "curse.maven:better-questing-unofficial-629629:5183601" // Version 4.2.2
}

if (project.enable_ender_storage.toBoolean()) {
// Ender Storage, runtime only, integrated in remappers (from CurseForge)
runtimeOnly "curse.maven:ender-storage-245174:2755787" // Version 2.4.6.137
Expand Down
6 changes: 5 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ curseForgeRelations = requiredDependency:codechicken-lib-1-8;\
optionalDependency:libvulpes;\
optionalDependency:advanced-rocketry;\
optionalDependency:architecturecraft-tridev;\
optionalDependency:effortless-building;
optionalDependency:effortless-building;\
optionalDependency:better-questing-unofficial;

# This project's release type on CurseForge and/or Modrinth
# Alternatively this can be set with the 'RELEASE_TYPE' environment variable.
Expand Down Expand Up @@ -252,6 +253,9 @@ enable_architecture_craft = false
# If this is set to false, the mixin will not apply.
enable_effortless_building = false

# Whether to enable BQu in runtime. Enables Labs Tier Helper.
enable_bqu = false

# Whether to enable Ender Storage in runtime. Enables remappers to remap items in ender storage.
# If this is set to false, the remappers will not apply there.
enable_ender_storage = false
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/nomiceu/nomilabs/LabsValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ public class LabsValues {
public static final String ROCKETRY_MODID = "advancedrocketry";
public static final String ARCHITECTURE_MODID = "architecturecraft";
public static final String EFFORTLESS_MODID = "effortlessbuilding";
public static final String BQU_MODID = "betterquesting";
}
3 changes: 2 additions & 1 deletion src/main/java/com/nomiceu/nomilabs/NomiLabs.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
+ "after:crafttweaker@[4.1.20,);"
+ "after:appliedenergistics2;"
+ "after:architecturecraft;"
+ "after:effortlessbuilding;")
+ "after:effortlessbuilding;"
+ "after:betterquesting;")
@SuppressWarnings("unused")
public class NomiLabs {
public static final Logger LOGGER = LogManager.getLogger(LabsValues.LABS_MODID);
Expand Down
72 changes: 72 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ public static class Advanced {
@Config.Name("fluid registry")
public final FluidRegistry fluidRegistrySettings = new FluidRegistry();

@Config.Comment({"Tier Detectors, which get the Tier a Player is On based on Quest Completion.",
"Currently only used in Nomi-CEu for Rich Presence."})
@Config.LangKey("config.nomilabs.advanced.tiers")
@Config.Name("tier settings")
public final TierSettings tierSettings = new TierSettings();

@Config.Comment({"List of Regex Patterns to ignore if they are included in the ITEM missing registry list.",
"Do not change unless you know what you are doing!",
"This can be very inefficient with lots of patterns and lots of missing registries. Try to condense it into one pattern!",
Expand Down Expand Up @@ -403,5 +409,71 @@ public static class FluidRegistry {
@Config.RequiresMcRestart
public boolean logConflictingFluids = false;
}

public static class TierSettings {
@Config.Comment({"Better Questing QB IDs for Normal Mode Tiers.",
"These are checked in reverse, so later quests in the list, and in progression, have higher priority",
"[default: ]"})
@Config.LangKey("config.nomilabs.advanced.tiers.normal_qb_ids")
@Config.RequiresMcRestart
public int[] normalModeQuestIds = new int[0];

@Config.Comment({"Non-Formatted Names for Normal Mode Tiers.",
"Each Tier must have the same index as the corresponding Quest ID!",
"[default: ]"})
@Config.LangKey("config.nomilabs.advanced.tiers.normal_slugs")
@Config.RequiresMcRestart
public String[] normalModeSlugs = new String[0];

@Config.Comment({"Formatted Names for Normal Mode Tiers.",
"Each Tier must have the same index as the corresponding Quest ID!",
"[default: ]"})
@Config.LangKey("config.nomilabs.advanced.tiers.normal_formatted")
@Config.RequiresMcRestart
public String[] normalModeFormatted = new String[0];

@Config.Comment({"Better Questing QB IDs for Expert Mode Tiers.",
"[default: ]"})
@Config.LangKey("config.nomilabs.advanced.tiers.expert_qb_ids")
@Config.RequiresMcRestart
public int[] expertModeQuestIds = new int[0];

@Config.Comment({"Non-Formatted Names for Expert Mode Tiers.",
"Each Tier must have the same index as the corresponding Quest ID!",
"[default: ]"})
@Config.LangKey("config.nomilabs.advanced.tiers.expert_slugs")
@Config.RequiresMcRestart
public String[] expertModeSlugs = new String[0];

@Config.Comment({"Formatted Names for Expert Mode Tiers.",
"Each Tier must have the same index as the corresponding Quest ID!",
"[default: ]"})
@Config.LangKey("config.nomilabs.advanced.tiers.expert_formatted")
@Config.RequiresMcRestart
public String[] expertModeFormatted = new String[0];

@Config.Comment({"Non-Formatted Name for Default Tier (Before Any Quests are Completed).",
"[default: pre-lv ]"})
@Config.LangKey("config.nomilabs.advanced.tiers.expert_formatted")
@Config.RequiresMcRestart
public String defaultSlug = "pre-lv";

@Config.Comment({"Formatted Name for Default Tier (Before Any Quests are Completed).",
"[default: Before LV ]"})
@Config.LangKey("config.nomilabs.advanced.tiers.expert_formatted")
@Config.RequiresMcRestart
public String defaultFormatted = "Before LV";

@Config.Comment({"Which Lists to default to if the mode is not Normal or Expert.",
"[default: NORMAL]"})
@Config.LangKey("config.nomilabs.advanced.tiers.default")
@Config.RequiresMcRestart
public DefaultModeType defaultMode = DefaultModeType.NORMAL;

public enum DefaultModeType {
NORMAL,
EXPERT
}
}
}
}
6 changes: 5 additions & 1 deletion src/main/java/com/nomiceu/nomilabs/event/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
import com.nomiceu.nomilabs.creativetab.registry.LabsCreativeTabs;
import com.nomiceu.nomilabs.fluid.FluidRegistryMixinHelper;
import com.nomiceu.nomilabs.fluid.registry.LabsFluids;
import com.nomiceu.nomilabs.gregtech.recipe.LabsRecipeMaps;
import com.nomiceu.nomilabs.gregtech.LabsSounds;
import com.nomiceu.nomilabs.gregtech.block.registry.LabsMetaBlocks;
import com.nomiceu.nomilabs.gregtech.material.registry.LabsMaterials;
import com.nomiceu.nomilabs.gregtech.multiblock.registry.LabsMultiblocks;
import com.nomiceu.nomilabs.gregtech.prefix.LabsMaterialFlags;
import com.nomiceu.nomilabs.gregtech.prefix.LabsOrePrefix;
import com.nomiceu.nomilabs.gregtech.recipe.LabsRecipeMaps;
import com.nomiceu.nomilabs.gregtech.recipe.PerfectGemsCutterRecipes;
import com.nomiceu.nomilabs.groovy.GroovyScriptHandManager;
import com.nomiceu.nomilabs.integration.architecturecraft.LabsShapes;
import com.nomiceu.nomilabs.integration.betterquesting.LabsTierHelper;
import com.nomiceu.nomilabs.integration.top.TOPTooltipManager;
import com.nomiceu.nomilabs.item.ItemExcitationCoil;
import com.nomiceu.nomilabs.item.registry.LabsItems;
Expand Down Expand Up @@ -77,6 +78,9 @@ public static void preInit() {
if (LabsConfig.modIntegration.enableTOPIntegration && Loader.isModLoaded(LabsValues.TOP_MODID))
TOPTooltipManager.registerProviders();

if (Loader.isModLoaded(LabsValues.BQU_MODID))
LabsTierHelper.preInit();

DataFixerHandler.preInit();
FluidRegistryMixinHelper.preInit();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.nomiceu.nomilabs.integration.betterquesting;

import betterquesting.api.api.QuestingAPI;
import betterquesting.questing.QuestDatabase;
import com.nomiceu.nomilabs.LabsValues;
import com.nomiceu.nomilabs.config.LabsConfig;
import com.nomiceu.nomilabs.util.LabsModeHelper;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.common.Loader;

import java.util.*;

/**
* Used by Nomi-CEu for Rich Presence.
* <p>
* As Quest ID Lists are not long, checking it each time is not expensive.
* <p>
* Also, Mod Specific Event Bus Subscribers are annoying.
*/

public class LabsTierHelper {
private static int[] IDS;
private static String[] SLUGS;
private static String[] NAMES;

private static UUID uuid;
// Using Integer instead of int, so it can be null
private static Integer cacheID;

public static void preInit() {
boolean normal = LabsModeHelper.isNormal();
if (!normal && !LabsModeHelper.isExpert()) {
if (LabsConfig.advanced.tierSettings.defaultMode == LabsConfig.Advanced.TierSettings.DefaultModeType.NORMAL) {
normal = true;
}
}
if (normal) {
IDS = LabsConfig.advanced.tierSettings.normalModeQuestIds;
SLUGS = LabsConfig.advanced.tierSettings.normalModeSlugs;
NAMES = LabsConfig.advanced.tierSettings.normalModeFormatted;
} else {
IDS = LabsConfig.advanced.tierSettings.expertModeQuestIds;
SLUGS = LabsConfig.advanced.tierSettings.expertModeSlugs;
NAMES = LabsConfig.advanced.tierSettings.expertModeFormatted;
}
uuid = null;
cacheID = null;
}

public static void rebuildCacheTier() {
var inputUuid = QuestingAPI.getQuestingUUID(Minecraft.getMinecraft().player);
uuid = inputUuid;
if (inputUuid == null) {
cacheID = null;
return;
}
for (int i = IDS.length - 1; i >= 0; i--) {
var quest = QuestDatabase.INSTANCE.getValue(IDS[i]);
if (quest != null && quest.isComplete(uuid)) {
cacheID = i;
return;
}
}
cacheID = null;
}

public static void resetCacheTier() {
uuid = null;
cacheID = null;
}

@SuppressWarnings("unused")
public static String getTierSlug() {
return getOrDefault(LabsConfig.advanced.tierSettings.defaultSlug, SLUGS);
}

@SuppressWarnings("unused")
public static String getTierName() {
return getOrDefault(LabsConfig.advanced.tierSettings.defaultFormatted, NAMES);
}

public static String getOrDefault(String defaultValue, String[] list) {
if (!Loader.isModLoaded(LabsValues.BQU_MODID)) return Minecraft.getMinecraft().player == null ? "" : defaultValue;
if (Minecraft.getMinecraft().player != null) {
rebuildCacheTier();
} else
resetCacheTier();
if (cacheID == null) return uuid == null ? "" : defaultValue;
return list[cacheID];
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/util/LabsModeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.nomiceu.nomilabs.LabsValues;
import com.nomiceu.nomilabs.config.LabsConfig;
import io.sommers.packmode.PMConfig;
import org.apache.commons.lang3.StringUtils;

public class LabsModeHelper {
private static boolean checked = false;
Expand All @@ -19,6 +20,14 @@ public static boolean isExpert() {
return PMConfig.getPackMode().equals(LabsValues.EXPERT_MODE);
}

/**
* Used by Nomi-CEu Rich Presence.
*/
@SuppressWarnings("unused")
public static String getFormattedMode() {
return StringUtils.capitalize(PMConfig.getPackMode());
}

public static void check() {
checked = true;
if (LabsConfig.advanced.allowOtherPackModes) return;
Expand Down

0 comments on commit 9c8b483

Please sign in to comment.