Skip to content

Commit

Permalink
reworked iris api dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
andi-makes committed Nov 10, 2024
1 parent 64bc98b commit 7663a22
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 36 deletions.
1 change: 0 additions & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ minecraft {

dependencies {
compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5'
compileOnly(files(rootProject.getRootDir().path + "/iris_api.jar"))
}
2 changes: 2 additions & 0 deletions common/src/main/java/dev/schmarrn/lighty/UtilDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public interface UtilDefinition {

Path getConfigDir();

boolean shadersEnabled();

static UtilDefinition load() {
return ServiceLoader.load(UtilDefinition.class).findFirst().orElseThrow(() -> new IllegalStateException("No valid ServiceImpl found"));
}
Expand Down
24 changes: 4 additions & 20 deletions common/src/main/java/dev/schmarrn/lighty/compat/IrisCompat.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.schmarrn.lighty.compat;

import com.mojang.blaze3d.vertex.PoseStack;
import dev.schmarrn.lighty.UtilDefinition;
import dev.schmarrn.lighty.mixin.GameRendererAccessor;
import net.irisshaders.iris.api.v0.IrisApi;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
Expand All @@ -13,18 +13,6 @@
import org.joml.Vector3f;

public class IrisCompat {
private static final IrisApi INSTANCE;

static {
IrisApi i;
try {
i = (IrisApi)Class.forName("net.irisshaders.iris.apiimpl.IrisApiV0Impl").getField("INSTANCE").get((Object)null);
} catch (NoSuchFieldException | ClassNotFoundException | IllegalAccessException var1) {
i = null;
}
INSTANCE = i;
}

private static Matrix4f shaderFix(PoseStack stack, Camera camera, GameRenderer gameRenderer, Minecraft minecraft, LocalPlayer player) {
// mostly taken from: https://github.com/IrisShaders/Iris/blob/multiloader-new/common/src/main/java/net/irisshaders/iris/mixin/MixinModelViewBobbing.java#L98-L134
// which in turn is mostly taken from GameRenderer
Expand All @@ -39,7 +27,7 @@ private static Matrix4f shaderFix(PoseStack stack, Camera camera, GameRenderer g

Matrix4f instance = stack.last().pose();

float f = minecraft.getDeltaTracker().getGameTimeDeltaPartialTick(false);
float f = minecraft.getTimer().getGameTimeDeltaPartialTick(false);
float h = minecraft.options.screenEffectScale().get().floatValue();
float i = Mth.lerp(f, player.oSpinningEffectIntensity, player.spinningEffectIntensity) * h * h;
if (i > 0.0F) {
Expand All @@ -57,12 +45,8 @@ private static Matrix4f shaderFix(PoseStack stack, Camera camera, GameRenderer g
}

public static void fixIrisShaders(PoseStack stack, Camera camera, GameRenderer gr, Minecraft minecraft) {
if (IrisCompat.INSTANCE != null) {
if (IrisCompat.INSTANCE.isShaderPackInUse()) {
if (minecraft.player != null) {
stack.last().pose().set(shaderFix(stack, camera, gr, minecraft, minecraft.player));
}
}
if (UtilDefinition.INSTANCE.shadersEnabled() && minecraft.player != null) {
stack.last().pose().set(shaderFix(stack, camera, gr, minecraft, minecraft.player));
}
}
}
2 changes: 2 additions & 0 deletions common/src/main/java/dev/schmarrn/lighty/event/Compute.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ public static void render(@Nullable Frustum frustum, PoseStack matrixStack, Matr
GameRenderer gameRenderer = minecraft.gameRenderer;
Camera camera = gameRenderer.getMainCamera();

matrixStack.pushPose();

// fixes view-bobbing and hurt-tilt causing the overlay to move when playing with shaders
// applies bobbing effects to the matrixStack because it isn't applied to the projection matrix
IrisCompat.fixIrisShaders(matrixStack, camera, gameRenderer, minecraft);
Expand Down
16 changes: 14 additions & 2 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.7-SNAPSHOT'
}

version = "${mod_version}+${minecraft_version}"
Expand All @@ -16,6 +16,17 @@ repositories {
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven {url = "https://maven.terraformersmc.com/releases/"} // Mod Menu repository
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
filter {
includeGroup "maven.modrinth"
}
}
}

loom {
Expand Down Expand Up @@ -49,8 +60,9 @@ dependencies {
modImplementation "com.terraformersmc:modmenu:${modmenu_version}"
modImplementation fabricApi.module("fabric-screen-api-v1", rootProject.findProperty("fabric_api_version"))

modImplementation "maven.modrinth:iris:${iris_version}-fabric"

compileOnly project(":common")
compileOnly(files(rootProject.getRootDir().path + "/iris_api.jar"))
}

compileJava {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@
import dev.schmarrn.lighty.UtilDefinition;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.loader.api.FabricLoader;
import net.irisshaders.iris.api.v0.IrisApi;
import net.minecraft.client.KeyMapping;

import java.nio.file.Path;

public class UtilFabricImpl implements UtilDefinition {
private static final IrisApi INSTANCE;
static {
IrisApi i;
try {
i = (IrisApi)Class.forName("net.irisshaders.iris.apiimpl.IrisApiV0Impl").getField("INSTANCE").get(null);
} catch (NoSuchFieldException | ClassNotFoundException | IllegalAccessException var1) {
i = null;
}
INSTANCE = i;
}

@Override
public KeyMapping registerKeyBinding(KeyMapping mapping) {
Expand All @@ -32,4 +43,9 @@ public KeyMapping registerKeyBinding(KeyMapping mapping) {
public Path getConfigDir() {
return FabricLoader.getInstance().getConfigDir();
}

@Override
public boolean shadersEnabled() {
return INSTANCE != null && INSTANCE.isShaderPackInUse();
}
}
18 changes: 10 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
org.gradle.jvmargs=-Xmx2048M

minecraft_version=1.21
minecraft_version_lower_bound=1.21
minecraft_version=1.21.1
minecraft_version_lower_bound=1.21.1

fabric_enabled=true
neoforge_enabled=false
neoforge_enabled=true

issue_url=https://github.com/SchmarrnDevs/Lighty/issues

Expand All @@ -13,17 +13,19 @@ maven_group=dev.schmarrn
mod_name=Lighty

fabric_loader_version=0.15.11
fabric_api_version=0.100.1+1.21
fabric_api_version=0.107.0+1.21.1

modmenu_version = 11.0.0-beta.1
iris_version = 1.8.0-beta.7+1.21.1
sodium_version = mc1.21.1-0.6.0-beta.4

# neo stuff
neo_version=21.0.0-beta
minecraft_version_range=[1.21,1.22)
neo_version_range=[21.0.0-beta,)
neo_version=21.1.76
minecraft_version_range=[1.21.1,1.22)
neo_version_range=[21.1.0-beta,)
loader_version_range=[2,)
mapping_channel=official
mapping_version=1.21
mapping_version=1.21.1
mod_id=lighty
mod_license=Apache-2.0
mod_authors=andi_makes, agnor99, Alveel
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
Binary file removed iris_api.jar
Binary file not shown.
16 changes: 14 additions & 2 deletions neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@ plugins {
id 'java-library'
id 'eclipse'
id 'idea'
id 'net.neoforged.gradle.userdev' version '7.0.142'
id 'net.neoforged.gradle.userdev' version '7.0.165'
}

version = "${mod_version}+${minecraft_version}"
group = rootProject.findProperty("maven_group")

repositories {
mavenLocal()
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
filter {
includeGroup "maven.modrinth"
}
}
}

base {
Expand Down Expand Up @@ -48,7 +59,8 @@ dependencies {
implementation "net.neoforged:neoforge:${neo_version}"

compileOnly project(":common")
compileOnly(files(rootProject.getRootDir().path + "/iris_api.jar"))
implementation "maven.modrinth:iris:${iris_version}-neoforge"
implementation "maven.modrinth:sodium:${sodium_version}-neoforge"
}

// This block of code expands all declared replace properties in the specified resource targets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package dev.schhmarrn.lighty.forge;

import dev.schmarrn.lighty.UtilDefinition;
import net.irisshaders.iris.api.v0.IrisApi;
import net.minecraft.client.KeyMapping;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
Expand All @@ -28,6 +29,16 @@

@EventBusSubscriber(value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD)
public class UtilForgeImpl implements UtilDefinition {
private static final IrisApi INSTANCE;
static {
IrisApi i;
try {
i = (IrisApi)Class.forName("net.irisshaders.iris.apiimpl.IrisApiV0Impl").getField("INSTANCE").get(null);
} catch (NoSuchFieldException | ClassNotFoundException | IllegalAccessException var1) {
i = null;
}
INSTANCE = i;
}

private static final List<KeyMapping> MAPPINGS = new ArrayList<>();

Expand All @@ -42,6 +53,11 @@ public Path getConfigDir() {
return FMLPaths.CONFIGDIR.get();
}

@Override
public boolean shadersEnabled() {
return INSTANCE != null && INSTANCE.isShaderPackInUse();
}

@SubscribeEvent
public static void registerKeyBindings(RegisterKeyMappingsEvent event) {
MAPPINGS.forEach(event::register);
Expand Down

0 comments on commit 7663a22

Please sign in to comment.