mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-30 21:23:00 +00:00 
			
		
		
		
	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
This commit is contained in:
		| @@ -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()) | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -8,7 +8,7 @@ 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.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 @@ import java.util.function.IntFunction; | ||||
| 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 { | ||||
| @@ -60,6 +60,14 @@ public interface PlatformHelper { | ||||
|         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. | ||||
|      * | ||||
|   | ||||
| @@ -49,6 +49,11 @@ import java.util.function.Predicate; | ||||
| 
 | ||||
| @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"); | ||||
|   | ||||
| @@ -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) | ||||
| 
 | ||||
|   | ||||
| @@ -29,6 +29,7 @@ import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerType; | ||||
| 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 @@ import java.util.function.Supplier; | ||||
| 
 | ||||
| @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(); | ||||
|   | ||||
| @@ -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 | ||||
| 
 | ||||
|   | ||||
| @@ -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<ShaderMod> 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<ByteBuffer> 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<ByteBuffer> 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); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -50,6 +50,7 @@ import net.minecraft.world.level.block.entity.BlockEntity; | ||||
| 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 @@ import java.util.function.Supplier; | ||||
| 
 | ||||
| @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(); | ||||
|   | ||||
| @@ -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", | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jonathan Coates
					Jonathan Coates