Skip to content

Commit 76e7350

Browse files
committed
Add a method to detect gametest enabled environments.
1 parent 2d675cf commit 76e7350

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

Common/src/main/java/net/darkhax/bookshelf/api/util/IPlatformHelper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,11 @@ default MutableComponent getModNameComponent(String modId) {
104104
final String modName = getModName(modId);
105105
return modName != null ? new TextComponent(modName) : null;
106106
}
107+
108+
/**
109+
* Checks if the mod is currently running in an environment with game tests enabled.
110+
*
111+
* @return Are game tests currently enabled?
112+
*/
113+
boolean isTestingEnvironment();
107114
}

Fabric/src/main/java/net/darkhax/bookshelf/impl/util/PlatformHelperFabric.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.darkhax.bookshelf.api.PhysicalSide;
44
import net.darkhax.bookshelf.api.util.IPlatformHelper;
55
import net.fabricmc.api.EnvType;
6+
import net.fabricmc.fabric.impl.gametest.FabricGameTestHelper;
67
import net.fabricmc.loader.api.FabricLoader;
78
import org.jetbrains.annotations.Nullable;
89

@@ -46,4 +47,10 @@ public String getModName(String modId) {
4647

4748
return FabricLoader.getInstance().getModContainer(modId).map(mod -> mod.getMetadata().getName()).orElse(modId);
4849
}
50+
51+
@Override
52+
public boolean isTestingEnvironment() {
53+
54+
return FabricGameTestHelper.ENABLED;
55+
}
4956
}

Forge/src/main/java/net/darkhax/bookshelf/impl/util/PlatformHelperForge.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraftforge.fml.loading.FMLEnvironment;
77
import net.minecraftforge.fml.loading.FMLLoader;
88
import net.minecraftforge.fml.loading.FMLPaths;
9+
import net.minecraftforge.gametest.ForgeGameTestHooks;
910
import org.jetbrains.annotations.Nullable;
1011

1112
import java.nio.file.Path;
@@ -48,4 +49,10 @@ public String getModName(String modId) {
4849

4950
return ModList.get().getModContainerById(modId).map(mod -> mod.getModInfo().getDisplayName()).orElse(modId);
5051
}
52+
53+
@Override
54+
public boolean isTestingEnvironment() {
55+
56+
return ForgeGameTestHooks.isGametestEnabled();
57+
}
5158
}

0 commit comments

Comments
 (0)