Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Sodium(NeoForge), Fix Iris incompatibility #38

Open
wants to merge 4 commits into
base: 1.21
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.config.IrisConfig;
import net.neoforged.fml.loading.LoadingModList;

import java.io.IOException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;

public class IrisODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {

public static final String SHADER_PACK_NAME = "assets/replaymod/iris/ods";
public static final Path SHADER_PACK_PATH = LoadingModList.get().getModFileById("replaymod").getFile().getSecureJar().getRootPath();

public static IrisODSFrameCapturer INSTANCE;
private final CubicPboOpenGlFrameCapturer left, right;
private final String prevShaderPack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.replaymod.render.hooks;

import com.replaymod.render.utils.FlawlessFrames;
import com.replaymod.render.utils.FlawlessFramesHelper;
// import com.replaymod.render.utils.FlawlessFrames;
// import com.replaymod.render.utils.FlawlessFramesHelper;
import com.replaymod.render.utils.EmbeddiumFlawlessFramesHelper;
import com.replaymod.render.utils.SodiumFlawlessFramesHelper;
import net.minecraft.client.render.WorldRenderer;
import net.neoforged.fml.loading.FMLLoader;
import net.neoforged.fml.loading.LoadingModList;
// import net.neoforged.fml.loading.FMLLoader;
// import net.neoforged.fml.loading.LoadingModList;

public class ForceChunkLoadingHook {

Expand All @@ -13,16 +15,34 @@ public class ForceChunkLoadingHook {
public ForceChunkLoadingHook(WorldRenderer renderGlobal) {
this.hooked = renderGlobal;

if (LoadingModList.get().getModFileById("embeddium") != null) {
/*if (FlawlessFramesHelper.hasEmbeddium()) {
FlawlessFramesHelper.setEnabled(true);
}*/

if (EmbeddiumFlawlessFramesHelper.hasEmbeddium()) {
EmbeddiumFlawlessFramesHelper.setEnabled(true);
}

if (SodiumFlawlessFramesHelper.hasSodium()) {
SodiumFlawlessFramesHelper.setEnabled(true);
}

IForceChunkLoading.from(renderGlobal).replayModRender_setHook(this);
}

public void uninstall() {
IForceChunkLoading.from(hooked).replayModRender_setHook(null);
if (LoadingModList.get().getModFileById("embeddium") != null) {

/*if (FlawlessFramesHelper.hasEmbeddium()) {
FlawlessFramesHelper.setEnabled(false);
}*/

if (EmbeddiumFlawlessFramesHelper.hasEmbeddium()) {
EmbeddiumFlawlessFramesHelper.setEnabled(false);
}

if (SodiumFlawlessFramesHelper.hasSodium()) {
SodiumFlawlessFramesHelper.setEnabled(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.llamalad7.mixinextras.sugar.Local;
import com.replaymod.render.hooks.ForceChunkLoadingHook;
import com.replaymod.render.hooks.IForceChunkLoading;
import com.replaymod.render.utils.FlawlessFrames;
import com.replaymod.render.utils.FlawlessFramesHelper;
// import com.replaymod.render.utils.FlawlessFrames;
// import com.replaymod.render.utils.FlawlessFramesHelper;
import com.replaymod.render.utils.EmbeddiumFlawlessFramesHelper;
import com.replaymod.render.utils.SodiumFlawlessFramesHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.ChunkRenderingDataPreparer;
Expand All @@ -15,7 +17,7 @@
import net.minecraft.client.render.chunk.ChunkBuilder;
import net.minecraft.client.render.chunk.ChunkRendererRegionBuilder;
import net.minecraft.client.util.math.MatrixStack;
import net.neoforged.fml.loading.LoadingModList;
// import net.neoforged.fml.loading.LoadingModList;
import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand Down Expand Up @@ -57,7 +59,16 @@ private void forceAllChunks(CallbackInfo ci, @Local(argsOnly = true) Camera came
if (replayModRender_hook == null) {
return;
}
if (LoadingModList.get().getModFileById("embeddium") != null && FlawlessFramesHelper.hasEmbeddium()) {

/*if (LoadingModList.get().getModFileById("embeddium") != null && FlawlessFramesHelper.hasEmbeddium()) {
return;
}*/

if (EmbeddiumFlawlessFramesHelper.hasEmbeddium() && EmbeddiumFlawlessFramesHelper.supportFlawlessFrames()) {
return;
}

if (SodiumFlawlessFramesHelper.hasSodium() && SodiumFlawlessFramesHelper.supportFlawlessFrames()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import com.replaymod.render.capturer.IrisODSFrameCapturer;
import net.irisshaders.iris.Iris;
import net.neoforged.fml.loading.LoadingModList;
// import net.neoforged.fml.loading.LoadingModList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -17,7 +17,7 @@ public class Mixin_LoadIrisOdsShaderPack {
@Redirect(method = "loadExternalShaderpack", at = @At(value = "INVOKE", target = "Lnet/irisshaders/iris/Iris;getShaderpacksDirectory()Ljava/nio/file/Path;"))
private static Path loadReplayModOdsPack(String name) {
if (IrisODSFrameCapturer.INSTANCE != null && IrisODSFrameCapturer.SHADER_PACK_NAME.equals(name)) {
return LoadingModList.get().getModFileById("replaymod").getFile().getSecureJar().getRootPath();
return IrisODSFrameCapturer.SHADER_PACK_PATH;
} else {
return Iris.getShaderpacksDirectory();
}
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/com/replaymod/render/rendering/VideoRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
import com.replaymod.render.hooks.ForceChunkLoadingHook;
import com.replaymod.render.metadata.MetadataInjector;
import com.replaymod.render.mixin.WorldRendererAccessor;
import com.replaymod.render.utils.FlawlessFrames;
import com.replaymod.render.utils.FlawlessFramesHelper;
// import com.replaymod.render.utils.FlawlessFrames;
// import com.replaymod.render.utils.FlawlessFramesHelper;
import com.replaymod.render.utils.EmbeddiumFlawlessFramesHelper;
import com.replaymod.render.utils.SodiumFlawlessFramesHelper;
import com.replaymod.replay.ReplayHandler;
import com.replaymod.replaystudio.pathing.path.Keyframe;
import com.replaymod.replaystudio.pathing.path.Path;
Expand Down Expand Up @@ -683,13 +685,22 @@ public static String[] checkCompat(Stream<RenderSettings> settings) {

public static String[] checkCompat(RenderSettings settings) {
//#if FABRIC>=1
if ((LoadingModList.get().getModFileById("embeddium") != null || LoadingModList.get().getModFileById("sodium") != null) && !FlawlessFramesHelper.hasEmbeddium()) {
if (EmbeddiumFlawlessFramesHelper.hasEmbeddium() && !EmbeddiumFlawlessFramesHelper.supportFlawlessFrames()) {
return new String[] {
"Rendering is not supported with your Embeddium version.",
"It is missing support for the FREX Flawless Frames API.",
"Either use the Sodium build from replaymod.com or uninstall Sodium before rendering!",
};
}

if (SodiumFlawlessFramesHelper.hasSodium() && !SodiumFlawlessFramesHelper.supportFlawlessFrames()) {
return new String[] {
"Rendering is not supported with your Sodium version.",
"It is missing support for the FREX Flawless Frames API.",
"Either use the Sodium build from replaymod.com or uninstall Sodium before rendering!",
};
}

//#if MC>=11700
if (settings.getRenderMethod() == RenderSettings.RenderMethod.ODS
&& LoadingModList.get().getModFileById("iris") == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@
*
* See https://github.com/grondag/frex/pull/9
*/
public class FlawlessFrames implements FlawlessFramesService {
public class /*lawlessFrames*/ EmbeddiumFlawlessFrames implements FlawlessFramesService {
private static final List<Consumer<Boolean>> CONSUMERS = new CopyOnWriteArrayList<>();
private static boolean hasSodium;
private static boolean supported;

public FlawlessFrames() {}
public EmbeddiumFlawlessFrames() {}

public void acceptController(Function<String, Consumer<Boolean>> controller) {
Consumer<Boolean> consumer = controller.apply(MOD_ID);
CONSUMERS.add(consumer);

if (controller.getClass().getName().contains(".embeddium.") || consumer.getClass().getName().contains(".sodium.")) {
hasSodium = true;
if (controller.getClass().getName().contains(".embeddium.")) {
supported = true;
}
}

public static void setEnabled(boolean enabled) {
CONSUMERS.forEach(it -> it.accept(enabled));
}

public static boolean hasSodium() {
return hasSodium;
public static boolean isSupported() {
return supported;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.replaymod.render.utils;

import net.neoforged.fml.ModList;

public class EmbeddiumFlawlessFramesHelper {

public static boolean hasEmbeddium() {
return /*FlawlessFrames.hasSodium()*/ ModList.get().isLoaded("embeddium");
}

public static boolean supportFlawlessFrames() {
return EmbeddiumFlawlessFrames.isSupported();
}

public static void setEnabled(boolean enabled) {
EmbeddiumFlawlessFrames.setEnabled(enabled);
}
}
13 changes: 0 additions & 13 deletions src/main/java/com/replaymod/render/utils/FlawlessFramesHelper.java

This file was deleted.

43 changes: 43 additions & 0 deletions src/main/java/com/replaymod/render/utils/SodiumFlawlessFrames.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.replaymod.render.utils;

// import org.embeddedt.embeddium.api.service.FlawlessFramesService;
// import org.embeddedt.embeddium.impl.asm.OptionalInterface;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;
import java.util.function.Function;

import static com.replaymod.core.ReplayMod.MOD_ID;

/**
* Uses the "Flawless Frames" FREX feature which allows us to instruct third-party mods to sacrifice performance (even
* beyond the point where it can no longer achieve interactive frame rates) in exchange for a noticeable boost to
* quality.
* In particular also to force-load all chunks with Canvas/Sodium/Bobby.
*
* See https://github.com/grondag/frex/pull/9
*/
public class /*lawlessFrames*/ SodiumFlawlessFrames {
private static final List<Consumer<Boolean>> CONSUMERS = new CopyOnWriteArrayList<>();
private static boolean supported;

public SodiumFlawlessFrames() {}

public static void acceptController(Function<String, Consumer<Boolean>> controller) {
Consumer<Boolean> consumer = controller.apply(MOD_ID);
CONSUMERS.add(consumer);

if (consumer.getClass().getName().contains(".sodium.")) {
supported = true;
}
}

public static void setEnabled(boolean enabled) {
CONSUMERS.forEach(it -> it.accept(enabled));
}

public static boolean isSupported() {
return supported;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.replaymod.render.utils;

import net.neoforged.fml.ModList;

public class SodiumFlawlessFramesHelper {

public static boolean hasSodium() {
return /*FlawlessFrames.hasSodium()*/ ModList.get().isLoaded("sodium");
}

public static boolean supportFlawlessFrames() {
return SodiumFlawlessFrames.isSupported();
}

public static void setEnabled(boolean enabled) {
SodiumFlawlessFrames.setEnabled(enabled);
}
}
3 changes: 3 additions & 0 deletions src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ description='''
A Mod which allows you to record, replay and share your Minecraft experience.
'''

[modproperties.reforgedplaymod]
"frex:flawless_frames_handler" = "com.replaymod.render.utils.SodiumFlawlessFrames"

[[dependencies.reforgedplaymod]]
modId = "neoforge"
type="required"
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
com.replaymod.render.utils.FlawlessFrames
com.replaymod.render.utils.EmbeddiumFlawlessFrames