From 63181e73a14f840a360125e1e6b2be8907d551f3 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Wed, 11 Sep 2024 20:07:12 +0100 Subject: [PATCH] Unify Iris integrations 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 --- .../kotlin/cc/tweaked/gradle/MinecraftExec.kt | 18 +++++ gradle/libs.versions.toml | 22 +++---- .../client/integration/IrisShaderMod.java | 4 +- .../shared/platform/PlatformHelper.java | 8 +++ .../computercraft/TestPlatformHelper.java | 5 ++ projects/fabric/build.gradle.kts | 16 ++--- .../shared/platform/PlatformHelperImpl.java | 6 ++ projects/forge/build.gradle.kts | 27 ++++++-- .../client/integration/IrisShaderMod.java | 66 ------------------- .../shared/platform/PlatformHelperImpl.java | 6 ++ tools/screenshots.py | 1 + 11 files changed, 84 insertions(+), 95 deletions(-) rename projects/{fabric => common}/src/client/java/dan200/computercraft/client/integration/IrisShaderMod.java (93%) delete mode 100644 projects/forge/src/client/java/dan200/computercraft/client/integration/IrisShaderMod.java diff --git a/buildSrc/src/main/kotlin/cc/tweaked/gradle/MinecraftExec.kt b/buildSrc/src/main/kotlin/cc/tweaked/gradle/MinecraftExec.kt index 1719d4e5a8..20baaccfc7 100644 --- a/buildSrc/src/main/kotlin/cc/tweaked/gradle/MinecraftExec.kt +++ b/buildSrc/src/main/kotlin/cc/tweaked/gradle/MinecraftExec.kt @@ -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 /** @@ -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()) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4b785bba8a..e5b6c2fd26 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" @@ -111,7 +111,8 @@ 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" } @@ -119,12 +120,11 @@ 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" } @@ -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 diff --git a/projects/fabric/src/client/java/dan200/computercraft/client/integration/IrisShaderMod.java b/projects/common/src/client/java/dan200/computercraft/client/integration/IrisShaderMod.java similarity index 93% rename from projects/fabric/src/client/java/dan200/computercraft/client/integration/IrisShaderMod.java rename to projects/common/src/client/java/dan200/computercraft/client/integration/IrisShaderMod.java index 9f52028b49..a8241d6437 100644 --- a/projects/fabric/src/client/java/dan200/computercraft/client/integration/IrisShaderMod.java +++ b/projects/common/src/client/java/dan200/computercraft/client/integration/IrisShaderMod.java @@ -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; @@ -21,7 +21,7 @@ public class IrisShaderMod implements ShaderMod.Provider { @Override public Optional 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 { diff --git a/projects/common/src/main/java/dan200/computercraft/shared/platform/PlatformHelper.java b/projects/common/src/main/java/dan200/computercraft/shared/platform/PlatformHelper.java index 9f1e821b13..2892a8c8e2 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/platform/PlatformHelper.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/platform/PlatformHelper.java @@ -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. * diff --git a/projects/common/src/test/java/dan200/computercraft/TestPlatformHelper.java b/projects/common/src/test/java/dan200/computercraft/TestPlatformHelper.java index ab7cb71d09..fae335b787 100644 --- a/projects/common/src/test/java/dan200/computercraft/TestPlatformHelper.java +++ b/projects/common/src/test/java/dan200/computercraft/TestPlatformHelper.java @@ -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"); diff --git a/projects/fabric/build.gradle.kts b/projects/fabric/build.gradle.kts index 6f306f0910..21ce836b3b 100644 --- a/projects/fabric/build.gradle.kts +++ b/projects/fabric/build.gradle.kts @@ -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) @@ -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) diff --git a/projects/fabric/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java b/projects/fabric/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java index a1ab7b7425..35568523dc 100644 --- a/projects/fabric/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java +++ b/projects/fabric/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java @@ -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; @@ -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(); diff --git a/projects/forge/build.gradle.kts b/projects/forge/build.gradle.kts index 8b30cc5cc0..2b8f2feda0 100644 --- a/projects/forge/build.gradle.kts +++ b/projects/forge/build.gradle.kts @@ -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 { @@ -160,6 +165,9 @@ dependencies { "testMinecraftLibrary"(libs.bundles.test) testFixturesImplementation(testFixtures(project(":core"))) + + "testWithIris"(libs.iris.forge) + "testWithIris"(libs.sodium.forge) } // Compile tasks @@ -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 diff --git a/projects/forge/src/client/java/dan200/computercraft/client/integration/IrisShaderMod.java b/projects/forge/src/client/java/dan200/computercraft/client/integration/IrisShaderMod.java deleted file mode 100644 index 84e90844d7..0000000000 --- a/projects/forge/src/client/java/dan200/computercraft/client/integration/IrisShaderMod.java +++ /dev/null @@ -1,66 +0,0 @@ -// SPDX-FileCopyrightText: 2022 The CC: Tweaked Developers -// -// SPDX-License-Identifier: MPL-2.0 - -package dan200.computercraft.client.integration; - -import com.google.auto.service.AutoService; -import com.mojang.blaze3d.vertex.VertexFormat; -import dan200.computercraft.client.render.RenderTypes; -import dan200.computercraft.client.render.text.DirectFixedWidthFontRenderer; -import net.irisshaders.iris.api.v0.IrisApi; -import net.irisshaders.iris.api.v0.IrisTextVertexSink; -import net.minecraft.util.FastColor; -import net.neoforged.fml.ModList; - -import java.nio.ByteBuffer; -import java.util.Optional; -import java.util.function.IntFunction; - -/** - * A {@link ShaderMod} for Oculus (the Forge Iris port). - */ -@AutoService(ShaderMod.Provider.class) -public class IrisShaderMod implements ShaderMod.Provider { - @Override - public Optional get() { - return ModList.get().isLoaded("oculus") ? Optional.of(new Impl()) : Optional.empty(); - } - - private static final class Impl extends ShaderMod { - @Override - public boolean isRenderingShadowPass() { - return IrisApi.getInstance().isRenderingShadowPass(); - } - - @Override - public DirectFixedWidthFontRenderer.QuadEmitter getQuadEmitter(int vertexCount, IntFunction makeBuffer) { - return IrisApi.getInstance().getMinorApiRevision() >= 1 - ? new IrisQuadEmitter(vertexCount, makeBuffer) - : super.getQuadEmitter(vertexCount, makeBuffer); - } - - private static final class IrisQuadEmitter implements DirectFixedWidthFontRenderer.QuadEmitter { - private final IrisTextVertexSink sink; - - private IrisQuadEmitter(int vertexCount, IntFunction makeBuffer) { - sink = IrisApi.getInstance().createTextVertexSink(vertexCount, makeBuffer); - } - - @Override - public VertexFormat format() { - return sink.getUnderlyingVertexFormat(); - } - - @Override - public ByteBuffer buffer() { - return sink.getUnderlyingByteBuffer(); - } - - @Override - public void quad(float x1, float y1, float x2, float y2, float z, int colour, float u1, float v1, float u2, float v2) { - sink.quad(x1, y1, x2, y2, z, FastColor.ABGR32.fromArgb32(colour), u1, v1, u2, v2, RenderTypes.FULL_BRIGHT_LIGHTMAP); - } - } - } -} diff --git a/projects/forge/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java b/projects/forge/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java index 3511c830b8..d0698b5769 100644 --- a/projects/forge/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java +++ b/projects/forge/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java @@ -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; @@ -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(); diff --git a/tools/screenshots.py b/tools/screenshots.py index 4a497306d3..59b033b9b3 100755 --- a/tools/screenshots.py +++ b/tools/screenshots.py @@ -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",