Skip to content

Commit

Permalink
Add Iris Keybinds, remove some deprecated compat
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchej123 committed Dec 7, 2023
1 parent 940edfb commit 50fcebb
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.gtnewhorizons.angelica.compat.mojang;
package com.gtnewhorizons.angelica.compat;

import net.minecraftforge.common.util.ForgeDirection;
import me.jellysquid.mods.sodium.client.model.quad.properties.ModelQuadFacing;

@Deprecated
public enum Axis {
X,
Y,
Z;

public static Axis fromDirection(ForgeDirection dir) {
public static Axis fromDirection(ModelQuadFacing dir) {
return switch (dir) {
case DOWN, UP -> Y;
case NORTH, SOUTH -> Z;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ public abstract class MixinGameSettings {
@Unique
private static boolean iris$shadersInitialized;

private static Iris iris$Instance;

@Inject(method="Lnet/minecraft/client/settings/GameSettings;loadOptions()V", at=@At("HEAD"))
private void angelica$InitializeShaders(CallbackInfo ci) {
if (iris$shadersInitialized) {
return;
}

iris$shadersInitialized = true;
iris$Instance =new Iris();
iris$Instance.onEarlyInitialize();
Iris.INSTANCE.onEarlyInitialize();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import me.jellysquid.mods.sodium.client.SodiumDebugScreenHandler;
import net.coderbot.iris.Iris;
import net.coderbot.iris.client.IrisDebugScreenHandler;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -48,6 +49,11 @@ public void init(FMLInitializationEvent event) {
}
if(AngelicaConfig.enableIris) {
MinecraftForge.EVENT_BUS.register(IrisDebugScreenHandler.INSTANCE);

Iris.INSTANCE.registerKeybindings();
FMLCommonHandler.instance().bus().register(Iris.INSTANCE);
MinecraftForge.EVENT_BUS.register(Iris.INSTANCE);

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package me.jellysquid.mods.sodium.client.model.quad.properties;

import com.gtnewhorizons.angelica.compat.mojang.Axis;
import com.gtnewhorizons.angelica.compat.mojang.BakedQuad;
import me.jellysquid.mods.sodium.client.model.quad.ModelQuadView;
import com.gtnewhorizons.angelica.compat.Axis;
import com.gtnewhorizons.angelica.compat.nd.Quad;
import net.minecraftforge.common.util.ForgeDirection;

public class ModelQuadFlags {
Expand Down Expand Up @@ -33,10 +32,9 @@ public static boolean contains(int flags, int mask) {
* Calculates the properties of the given quad. This data is used later by the light pipeline in order to make
* certain optimizations.
*/
public static int getQuadFlags(BakedQuad bakedQuad) {
final ModelQuadView quad = (ModelQuadView) bakedQuad;
final ForgeDirection face = bakedQuad.getFace();
final Axis axis = Axis.fromDirection(face);
public static int getQuadFlags(Quad quad) {
final ForgeDirection face = quad.getFace();
final Axis axis = Axis.fromDirection(quad.normal);

float minX = 32.0F;
float minY = 32.0F;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.jellysquid.mods.sodium.client.render.pipeline.context;

import com.gtnewhorizons.angelica.compat.mojang.BlockModels;
import lombok.Getter;
import me.jellysquid.mods.sodium.client.model.light.LightPipelineProvider;
import me.jellysquid.mods.sodium.client.model.light.cache.ArrayLightDataCache;
import me.jellysquid.mods.sodium.client.render.pipeline.BlockRenderer;
Expand All @@ -14,10 +14,11 @@
public class ChunkRenderCacheLocal extends ChunkRenderCache {
private final ArrayLightDataCache lightDataCache;

@Getter
private final BlockRenderer blockRenderer;
@Getter
private final FluidRenderer fluidRenderer;

private final BlockModels blockModels;
@Getter
private final WorldSlice worldSlice;

public ChunkRenderCacheLocal(Minecraft client, WorldClient world) {
Expand All @@ -29,28 +30,11 @@ public ChunkRenderCacheLocal(Minecraft client, WorldClient world) {
this.blockRenderer = new BlockRenderer(client);
this.fluidRenderer = new FluidRenderer(lpp);

// TODO: Sodium
this.blockModels = null; // client.getBakedModelManager().getBlockModels();
}

public BlockModels getBlockModels() {
return this.blockModels;
}

public BlockRenderer getBlockRenderer() {
return this.blockRenderer;
}

public FluidRenderer getFluidRenderer() {
return this.fluidRenderer;
}

public void init(ChunkRenderContext context) {
this.lightDataCache.reset(context.getOrigin());
this.worldSlice.copyData(context);
}

public WorldSlice getWorldSlice() {
return this.worldSlice;
}
}
50 changes: 49 additions & 1 deletion src/main/java/net/coderbot/iris/Iris.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package net.coderbot.iris;

import com.google.common.base.Throwables;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import com.mojang.realmsclient.gui.ChatFormatting;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import lombok.Getter;
import net.coderbot.iris.config.IrisConfig;
import net.coderbot.iris.gl.GLDebug;
Expand All @@ -23,7 +27,9 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.util.ChatComponentText;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.opengl.ContextCapabilities;
import org.lwjgl.opengl.GLContext;
Expand Down Expand Up @@ -87,8 +93,14 @@ public class Iris {
private static String IRIS_VERSION;
private static boolean fallback;

private static final KeyBinding reloadKeybind = new KeyBinding("Reload Shaders", 0, "Iris Keybinds");
private static final KeyBinding toggleShadersKeybind = new KeyBinding("Toggle Shaders", 0, "Iris Keybinds");
private static final KeyBinding shaderpackScreenKeybind = new KeyBinding("Shaderpack Selection Screen", 0, "Iris Keybinds");

public static Iris INSTANCE = new Iris();

// Wrapped in try-catch due to early initializing class
public Iris() {
private Iris() {
isDevelopmentEnvironment = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
// TODO: Iris Backport
// try {
Expand All @@ -99,6 +111,36 @@ public Iris() {
// }catch(Exception ignored) {}
}

@SubscribeEvent
public void onKeypress(InputEvent.KeyInputEvent event) {
if (reloadKeybind.isPressed()) {
final Minecraft mc = Minecraft.getMinecraft();
try {
reload();
if (mc.thePlayer != null) mc.thePlayer.addChatMessage(new ChatComponentText("Shaders Reloaded!"));

} catch (Exception e) {
logger.error("Error while reloading Shaders for Iris!", e);
if (mc.thePlayer != null) mc.thePlayer.addChatMessage(new ChatComponentText( "Failed tgo reload shaders! Reason: " + Throwables.getRootCause(e).getMessage()));
}
} else if (toggleShadersKeybind.isPressed()) {
final Minecraft mc = Minecraft.getMinecraft();
try {
toggleShaders(mc, !irisConfig.areShadersEnabled());
} catch (Exception e) {
logger.error("Error while toggling shaders!", e);

if (mc.thePlayer != null) mc.thePlayer.addChatMessage(new ChatComponentText( "Failed tgo toggle shaders! Reason: " + Throwables.getRootCause(e).getMessage()));
setShadersDisabled();
fallback = true;
}
} else if (shaderpackScreenKeybind.isPressed()) {
final Minecraft mc = Minecraft.getMinecraft();
if (mc.thePlayer != null) mc.thePlayer.addChatMessage(new ChatComponentText( "Shaderpack selection screen is not implemented yet!"));
// minecraft.setScreen(new ShaderPackScreen(null));
}

}
/**
* Called very early on in Minecraft initialization. At this point we *cannot* safely access OpenGL, but we can do some very basic setup, config loading,
* and environment checks.
Expand Down Expand Up @@ -692,4 +734,10 @@ public static ShaderpackDirectoryManager getShaderpacksDirectoryManager() {

return shaderpacksDirectoryManager;
}

public void registerKeybindings() {
ClientRegistry.registerKeyBinding(reloadKeybind);
ClientRegistry.registerKeyBinding(toggleShadersKeybind);
ClientRegistry.registerKeyBinding(shaderpackScreenKeybind);
}
}

0 comments on commit 50fcebb

Please sign in to comment.