Skip to content

Commit

Permalink
actually let quartz be loaded without forge
Browse files Browse the repository at this point in the history
  • Loading branch information
RogueLogix committed Oct 22, 2023
1 parent 4c98c0d commit 077a68f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
9 changes: 7 additions & 2 deletions src/main/java/net/roguelogix/quartz/QuartzConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.roguelogix.phosphophyllite.config.ConfigValue;
import net.roguelogix.phosphophyllite.registry.IgnoreRegistration;
import net.roguelogix.phosphophyllite.registry.RegisterConfig;
import net.roguelogix.quartz.internal.QuartzDebug;
import net.roguelogix.quartz.internal.gl46.GL46Config;
import net.roguelogix.quartz.internal.vk.VKConfig;

Expand Down Expand Up @@ -34,14 +35,18 @@ private static boolean isValidPhosLoaading() {
final var phosVersion = phosContainer.getVersion();
final var quartzPhosDep = quartzContainer.getDependencies().stream().filter(dep -> dep.getModId().equals(Phosphophyllite.modid)).findAny().orElse(null);

if(quartzPhosDep == null){
if (quartzPhosDep == null) {
return false;
}
return quartzPhosDep.getVersionRange().containsVersion(phosVersion);
}

private static boolean setup() {
if(!isValidPhosLoaading()){
if (!QuartzDebug.doesForgeExist()) {
// loading without forge present
return false;
}
if (!isValidPhosLoaading()) {
// in the event we have an invalid phos loading, we dont really care anymore
return false;
}
Expand Down
18 changes: 4 additions & 14 deletions src/main/java/net/roguelogix/quartz/internal/QuartzCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
import java.lang.ref.Cleaner;
import java.util.List;

import static net.roguelogix.quartz.internal.QuartzDebug.doesForgeExist;

@NonnullDefault
public abstract class QuartzCore {

public static final Logger LOGGER = LogManager.getLogger("Quartz");
public static final boolean DEBUG;

@Nonnull
public static final QuartzCore INSTANCE;
Expand All @@ -50,25 +51,14 @@ public static void mainThreadClean(Object referent, Runnable cleanFunc) {
CLEANER.register(referent, () -> deletionQueue.enqueueUntracked(cleanFunc));
}

public static boolean doesForgeExist(){
try{
return FMLLoader.getLoadingModList() != null;
} catch (Throwable e){
return true;
}
}

static {
QuartzCore instance = null;
if (DatagenModLoader.isRunningDataGen() || !doesForgeExist()) {
DEBUG = false;
} else {
if (!DatagenModLoader.isRunningDataGen() && doesForgeExist()) {
if (!Thread.currentThread().getStackTrace()[2].getClassName().equals(EventListener.class.getName())) {
throw new IllegalStateException("Attempt to init quartz before it is ready");
}
LOGGER.info("Quartz Init");
DEBUG = QuartzConfig.INSTANCE.debug;
if (DEBUG) {
if (QuartzDebug.DEBUG) {
LOGGER.warn("Debug mode enabled, performance may suffer");
}

Expand Down
33 changes: 33 additions & 0 deletions src/main/java/net/roguelogix/quartz/internal/QuartzDebug.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.roguelogix.quartz.internal;

import net.minecraftforge.data.loading.DatagenModLoader;
import net.minecraftforge.fml.loading.FMLLoader;
import net.roguelogix.quartz.QuartzConfig;

public class QuartzDebug {
public static final boolean DEBUG;

static {
if (!doesForgeExist() || runningDatagen()) {
DEBUG = false;
} else {
DEBUG = QuartzConfig.INSTANCE.debug;
}
}

public static boolean runningDatagen(){
try{
return DatagenModLoader.isRunningDataGen();
} catch (Throwable e){
return false;
}
}

public static boolean doesForgeExist(){
try{
return FMLLoader.getLoadingModList() != null;
} catch (Throwable e){
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import javax.annotation.Nonnull;
import java.lang.Math;

import static net.roguelogix.quartz.internal.QuartzCore.DEBUG;
import static net.roguelogix.quartz.internal.QuartzDebug.DEBUG;

@SuppressWarnings("DuplicatedCode")
public record PointerWrapper(long pointer, long size) implements Comparable<PointerWrapper> {
Expand Down

0 comments on commit 077a68f

Please sign in to comment.