Skip to content

Commit

Permalink
Unify Iris integrations
Browse files Browse the repository at this point in the history
Iris now has built-in support for NeoForge, so we can use the same
integration on both.

We also re-enable Forge's client tests, and test Iris there too.

Fixes #1967
  • Loading branch information
SquidDev committed Sep 11, 2024
1 parent 4f3247a commit 63181e7
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 95 deletions.
18 changes: 18 additions & 0 deletions buildSrc/src/main/kotlin/cc/tweaked/gradle/MinecraftExec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import java.nio.file.Files
import java.util.concurrent.TimeUnit
import java.util.function.Supplier
import javax.inject.Inject
import kotlin.collections.set
import kotlin.random.Random

/**
Expand Down Expand Up @@ -108,6 +109,23 @@ abstract class ClientJavaExec : JavaExec() {
}
}

/**
* Configure Iris to use Complementary Shaders.
*/
fun withComplementaryShaders() {
val cct = project.extensions.getByType(CCTweakedExtension::class.java)

withFileFrom(workingDir.resolve("shaderpacks/ComplementaryShaders_v4.6.zip")) {
cct.downloadFile("Complementary Shaders", "https://edge.forgecdn.net/files/3951/170/ComplementaryShaders_v4.6.zip")
}
withFileContents(workingDir.resolve("config/iris.properties")) {
"""
enableShaders=true
shaderPack=ComplementaryShaders_v4.6.zip
""".trimIndent()
}
}

@TaskAction
override fun exec() {
Files.createDirectories(workingDir.toPath())
Expand Down
22 changes: 11 additions & 11 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ nightConfig = "3.6.7"
# Minecraft mods
emi = "1.1.7+1.21"
fabricPermissions = "0.3.1"
iris = "1.6.14+1.20.4"
iris-fabric = "1.8.0-beta.3+1.21-fabric"
iris-forge = "1.8.0-beta.3+1.21-neoforge"
jei = "19.8.2.99"
modmenu = "11.0.0-rc.4"
moreRed = "4.0.0.4"
oculus = "1.2.5"
rei = "16.0.729"
rubidium = "0.6.1"
sodium = "mc1.20-0.4.10"
sodium-fabric = "mc1.21-0.6.0-beta.1-fabric"
sodium-forge = "mc1.21-0.6.0-beta.1-neoforge"
mixinExtra = "0.3.5"
create-forge = "0.5.1.f-33"
create-fabric = "0.5.1-f-build.1467+mc1.20.1"
Expand Down Expand Up @@ -111,20 +111,20 @@ fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fab
fabric-junit = { module = "net.fabricmc:fabric-loader-junit", version.ref = "fabric-loader" }
fabric-loader = { module = "net.fabricmc:fabric-loader", version.ref = "fabric-loader" }
fabricPermissions = { module = "me.lucko:fabric-permissions-api", version.ref = "fabricPermissions" }
iris = { module = "maven.modrinth:iris", version.ref = "iris" }
iris-fabric = { module = "maven.modrinth:iris", version.ref = "iris-fabric" }
iris-forge = { module = "maven.modrinth:iris", version.ref = "iris-forge" }
jei-api = { module = "mezz.jei:jei-1.21-common-api", version.ref = "jei" }
jei-fabric = { module = "mezz.jei:jei-1.21-fabric", version.ref = "jei" }
jei-forge = { module = "mezz.jei:jei-1.21-neoforge", version.ref = "jei" }
mixin = { module = "org.spongepowered:mixin", version.ref = "mixin" }
mixinExtra = { module = "io.github.llamalad7:mixinextras-common", version.ref = "mixinExtra" }
modmenu = { module = "com.terraformersmc:modmenu", version.ref = "modmenu" }
moreRed = { module = "commoble.morered:morered-1.20.1", version.ref = "moreRed" }
oculus = { module = "maven.modrinth:oculus", version.ref = "oculus" }
rei-api = { module = "me.shedaniel:RoughlyEnoughItems-api", version.ref = "rei" }
rei-builtin = { module = "me.shedaniel:RoughlyEnoughItems-default-plugin", version.ref = "rei" }
rei-fabric = { module = "me.shedaniel:RoughlyEnoughItems-fabric", version.ref = "rei" }
rubidium = { module = "maven.modrinth:rubidium", version.ref = "rubidium" }
sodium = { module = "maven.modrinth:sodium", version.ref = "sodium" }
sodium-fabric = { module = "maven.modrinth:sodium", version.ref = "sodium.fabric" }
sodium-forge = { module = "maven.modrinth:sodium", version.ref = "sodium.forge" }

# Testing
hamcrest = { module = "org.hamcrest:hamcrest", version.ref = "hamcrest" }
Expand Down Expand Up @@ -184,10 +184,10 @@ annotations = ["jsr305", "checkerFramework", "jetbrainsAnnotations"]
kotlin = ["kotlin-stdlib", "kotlin-coroutines"]

# Minecraft
externalMods-common = ["jei-api", "nightConfig-core", "nightConfig-toml"]
externalMods-forge-compile = ["moreRed", "oculus", "jei-api"]
externalMods-common = ["iris-forge", "jei-api", "nightConfig-core", "nightConfig-toml"]
externalMods-forge-compile = ["moreRed", "iris-forge", "jei-api"]
externalMods-forge-runtime = ["jei-forge"]
externalMods-fabric-compile = ["fabricPermissions", "iris", "jei-api", "rei-api", "rei-builtin"]
externalMods-fabric-compile = ["fabricPermissions", "iris-fabric", "jei-api", "rei-api", "rei-builtin"]
externalMods-fabric-runtime = ["jei-fabric", "modmenu"]

# Testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.mojang.blaze3d.vertex.VertexFormat;
import dan200.computercraft.client.render.RenderTypes;
import dan200.computercraft.client.render.text.DirectFixedWidthFontRenderer;
import net.fabricmc.loader.api.FabricLoader;
import dan200.computercraft.shared.platform.PlatformHelper;
import net.irisshaders.iris.api.v0.IrisApi;
import net.irisshaders.iris.api.v0.IrisTextVertexSink;
import net.minecraft.util.FastColor;
Expand All @@ -21,7 +21,7 @@
public class IrisShaderMod implements ShaderMod.Provider {
@Override
public Optional<ShaderMod> get() {
return FabricLoader.getInstance().isModLoaded("iris") ? Optional.of(new Impl()) : Optional.empty();
return PlatformHelper.get().isModLoaded("iris") ? Optional.of(new Impl()) : Optional.empty();
}

private static final class Impl extends ShaderMod {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ static PlatformHelper get() {
return instance == null ? Services.raise(PlatformHelper.class, Instance.ERROR) : instance;
}

/**
* Determine if the specified mod is loaded.
*
* @param id The id of the mod to check.
* @return Whether this mod is loaded.
*/
boolean isModLoaded(String id);

/**
* Create a new config builder.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@

@AutoService({ PlatformHelper.class, ComputerCraftAPIService.class })
public class TestPlatformHelper extends AbstractComputerCraftAPI implements PlatformHelper {
@Override
public boolean isModLoaded(String id) {
return false;
}

@Override
public ConfigFile.Builder createConfigBuilder() {
throw new UnsupportedOperationException("Cannot create config file inside tests");
Expand Down
16 changes: 4 additions & 12 deletions projects/fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ dependencies {
exclude("net.fabricmc.fabric-api")
}

"modTestWithSodium"(libs.sodium)
"modTestWithIris"(libs.iris)
"modTestWithIris"(libs.sodium)
"modTestWithSodium"(libs.sodium.fabric)
"modTestWithIris"(libs.iris.fabric)
"modTestWithIris"(libs.sodium.fabric)

"includeRuntimeOnly"(libs.cobalt)
"includeRuntimeOnly"(libs.jzlib)
Expand Down Expand Up @@ -247,15 +247,7 @@ val runGametestClientWithIris by tasks.registering(ClientJavaExec::class) {
tags("iris")
classpath += configurations["testWithIris"]

withFileFrom(workingDir.resolve("shaderpacks/ComplementaryShaders_v4.6.zip")) {
cct.downloadFile("Complementary Shaders", "https://edge.forgecdn.net/files/3951/170/ComplementaryShaders_v4.6.zip")
}
withFileContents(workingDir.resolve("config/iris.properties")) {
"""
enableShaders=true
shaderPack=ComplementaryShaders_v4.6.zip
""".trimIndent()
}
withComplementaryShaders()
}
cct.jacoco(runGametestClientWithIris)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags;
import net.fabricmc.fabric.api.transfer.v1.item.InventoryStorage;
import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -74,6 +75,11 @@

@AutoService(PlatformHelper.class)
public class PlatformHelperImpl implements PlatformHelper {
@Override
public boolean isModLoaded(String id) {
return FabricLoader.getInstance().isModLoaded(id);
}

@Override
public ConfigFile.Builder createConfigBuilder() {
return new FabricConfigFile.Builder();
Expand Down
27 changes: 23 additions & 4 deletions projects/forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ configurations {
// Prevent ending up with multiple versions of libraries on the classpath.
shouldResolveConsistentlyWith(minecraftLibrary.get())
}

register("testWithIris") {
isCanBeConsumed = false
isCanBeResolved = true
}
}

dependencies {
Expand Down Expand Up @@ -160,6 +165,9 @@ dependencies {
"testMinecraftLibrary"(libs.bundles.test)

testFixturesImplementation(testFixtures(project(":core")))

"testWithIris"(libs.iris.forge)
"testWithIris"(libs.sodium.forge)
}

// Compile tasks
Expand Down Expand Up @@ -219,18 +227,29 @@ val runGametest by tasks.registering(JavaExec::class) {
cct.jacoco(runGametest)
tasks.check { dependsOn(runGametest) }

/*val runGametestClient by tasks.registering(ClientJavaExec::class) {
val runGametestClient by tasks.registering(ClientJavaExec::class) {
description = "Runs client-side gametests with no mods"
setRunConfig(runs["testClient"])
copyFrom("runGameTestClient")
tags("client")
}
cct.jacoco(runGametestClient)

val runGametestClientWithIris by tasks.registering(ClientJavaExec::class) {
description = "Runs client-side gametests with Iris"
copyFrom("runGameTestClient")

tags("iris")
classpath += configurations["testWithIris"]

withComplementaryShaders()
}
cct.jacoco(runGametestClientWithIris)

tasks.register("checkClient") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Runs all client-only checks."
dependsOn(runGametestClient)
}*/
dependsOn(runGametestClient, runGametestClientWithIris)
}

// Upload tasks

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.neoforged.fml.ModList;
import net.neoforged.neoforge.capabilities.BlockCapability;
import net.neoforged.neoforge.capabilities.BlockCapabilityCache;
import net.neoforged.neoforge.capabilities.Capabilities;
Expand All @@ -72,6 +73,11 @@

@AutoService(PlatformHelper.class)
public class PlatformHelperImpl implements PlatformHelper {
@Override
public boolean isModLoaded(String id) {
return ModList.get().isLoaded(id);
}

@Override
public ConfigFile.Builder createConfigBuilder() {
return new ForgeConfigFile.Builder();
Expand Down
1 change: 1 addition & 0 deletions tools/screenshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def main():
images: list[Image] = []
for project, dir in {
"Forge": "projects/forge/build/gametest/runGametestClient",
"Forge (+Iris)": "projects/forge/build/gametest/runGametestClientWithIris",
"Fabric": "projects/fabric/build/gametest/runGametestClient",
"Fabric (+Sodium)": "projects/fabric/build/gametest/runGametestClientWithSodium",
"Fabric (+Iris)": "projects/fabric/build/gametest/runGametestClientWithIris",
Expand Down

0 comments on commit 63181e7

Please sign in to comment.