Skip to content

Commit

Permalink
Fix Cleanroom Compat
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Sep 14, 2024
1 parent 3218855 commit 8fd6acb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/nomiceu/nomilabs/NomiLabs.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void preInit(FMLPreInitializationEvent event) {

@EventHandler
public void postInit(FMLPostInitializationEvent event) {
CommonProxy.postInit();
if (LabsSide.isClient())
ClientProxy.postInit();
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/event/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public static void preInit() {
LabsDimensions.register();
}

public static void postInit() {
LabsModeHelper.onPostInit();
}

public static void loadComplete() {
FluidRegistryMixinHelper.loadComplete();

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/groovy/GroovyHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.Loader;

import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -422,7 +423,9 @@ public static ChancedFluidOutput chanced(FluidStack fluid, int chance, int chanc
return new ChancedFluidOutput(fluid, chance, chanceBoost);
}

@Contract("_ -> new")
public static GTRecipeInput toGtInput(IIngredient ingredient) {
// noinspection Contract
return RecipeBuilderAccessor.ofGroovyIngredient(ingredient);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public void changeInitDifficulty(CallbackInfoReturnable<EnumDifficulty> cir) {

NomiLabs.LOGGER.warn("-----------------------------------------------");
NomiLabs.LOGGER.warn("===============================================");

}
}

Expand Down
20 changes: 11 additions & 9 deletions src/main/java/com/nomiceu/nomilabs/util/LabsModeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,18 @@
public class LabsModeHelper {

private static boolean checked = false;
private static boolean postInitPassed = false;
@Nullable
private static String modePreCache = null;

public static boolean isNormal() {
if (!checked)
throw new IllegalStateException("Cannot access Pack Mode before Post Init or Labs Config Load!");
return getMode().equals(LabsValues.NORMAL_MODE);
}

public static boolean isExpert() {
if (!checked)
throw new IllegalStateException("Cannot access Pack Mode before Post Init or Labs Config Load!");
return getMode().equals(LabsValues.EXPERT_MODE);
}

/**
* Used by Nomi-CEu Rich Presence.
*/
@SuppressWarnings("unused")
public static String getFormattedMode() {
return StringUtils.capitalize(getMode());
}
Expand All @@ -43,8 +36,11 @@ public static String getFormattedMode() {
* Get the Mode (at all times)
*/
public static String getMode() {
if (!postInitPassed) return getModePre();

// Reflection:
// ClassNotFound Exception Thrown if PMConfig not loaded
// (Just in Case, Prevent Load in Pre)
try {
// Prevent loading Static Init, use MC Mod Loader
var pmCfgClass = Class.forName("io.sommers.packmode.PMConfig", false,
Expand All @@ -64,7 +60,9 @@ public static String getMode() {
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException |
InvocationTargetException e) {
// PackMode not loaded
return getModePre();
// Throw, causes problems with cleanroom if we did this
throw new RuntimeException(
"Tried to get mode when PMConfig class is not loaded! Fatal error, this should not happen! Report to Nomi-Labs devs!");
}
}

Expand Down Expand Up @@ -96,6 +94,10 @@ public static void check() {
if (!checked) getMode(); // Will check, whether it uses getModePre or PMConfig.getPackMode
}

public static void onPostInit() {
postInitPassed = true;
}

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

0 comments on commit 8fd6acb

Please sign in to comment.