Skip to content
Merged
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
6 changes: 6 additions & 0 deletions src/api/java/net/optifine/shaders/Shaders.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.optifine.shaders;

/// Adapted and minimized from OptiFine
public class Shaders {
public static boolean shaderPackLoaded;
}
27 changes: 16 additions & 11 deletions src/main/java/gregtech/api/util/Mods.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@

import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.FMLLaunchHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.optifine.shaders.Shaders;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -79,23 +81,26 @@ public enum Mods {
Vintagium(Names.VINTAGIUM),
Alfheim(Names.ALFHEIM),

// Special Optifine handler, but consolidated here for simplicity
Optifine(null) {
OptiFine(null) {

@Override
public boolean isModLoaded() {
if (this.modLoaded == null) {
try {
Class<?> c = Class.forName("net.optifine.shaders.Shaders");
Field f = c.getDeclaredField("shaderPackLoaded");
f.setAccessible(true);
this.modLoaded = f.getBoolean(null);
} catch (Exception ignored) {
this.modLoaded = false;
}
this.modLoaded = FMLCommonHandler.instance().getSide().isClient() &&
FMLClientHandler.instance().hasOptifine();
}
return this.modLoaded;
}
},

// Special Optifine shader handler, but consolidated here for simplicity
ShadersMod(null) {

@Override
public boolean isModLoaded() {
// Check shader pack state at real time instead of caching it
return OptiFine.isModLoaded() && Shaders.shaderPackLoaded;
}
};

public static class Names {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected void processQuad() {
updateColor(normal[v], color[v], x, y, z, tint, multiplier);

// When enabled this causes the rendering to be black with Optifine
if (!Mods.Optifine.isModLoaded() && diffuse) {
if (!Mods.ShadersMod.isModLoaded() && diffuse) {
float d = LightUtil.diffuseLight(normal[v][0], normal[v][1], normal[v][2]);
for (int i = 0; i < 3; i++) {
color[v][i] *= d;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public VertexLighterSmoothAoSpecial(BlockColors colors) {

@Override
protected void updateLightmap(float[] normal, float[] lightmap, float x, float y, float z) {
if (Mods.Optifine.isModLoaded()) {
if (Mods.ShadersMod.isModLoaded()) {
super.updateLightmap(normal, lightmap, x, y, z);
return;
}
Expand All @@ -28,7 +28,7 @@ protected void updateLightmap(float[] normal, float[] lightmap, float x, float y
protected void updateColor(float[] normal, float[] color, float x, float y, float z, float tint, int multiplier) {
super.updateColor(normal, color, x, y, z, tint, multiplier);

if (Mods.Optifine.isModLoaded()) {
if (Mods.ShadersMod.isModLoaded()) {
return;
}

Expand Down Expand Up @@ -146,7 +146,7 @@ protected float getAo(float x, float y, float z) {

@Override
public void updateBlockInfo() {
if (Mods.Optifine.isModLoaded()) {
if (Mods.ShadersMod.isModLoaded()) {
super.updateBlockInfo();
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/gregtech/client/utils/BloomEffectUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static BlockRenderLayer getEffectiveBloomLayer() {
*/
@Contract("null -> _; !null -> !null")
public static BlockRenderLayer getEffectiveBloomLayer(BlockRenderLayer fallback) {
return Mods.Optifine.isModLoaded() ? fallback : bloom;
return Mods.ShadersMod.isModLoaded() ? fallback : bloom;
}

/**
Expand Down Expand Up @@ -115,7 +115,7 @@ public static BlockRenderLayer getEffectiveBloomLayer(boolean isBloomActive) {
*/
@Contract("_, null -> _; _, !null -> !null")
public static BlockRenderLayer getEffectiveBloomLayer(boolean isBloomActive, BlockRenderLayer fallback) {
return Mods.Optifine.isModLoaded() || !isBloomActive ? fallback : bloom;
return Mods.ShadersMod.isModLoaded() || !isBloomActive ? fallback : bloom;
}

/**
Expand Down Expand Up @@ -253,7 +253,7 @@ public static BloomRenderTicket registerBloomRender(@Nullable IRenderSetup setup
@NotNull IBloomEffect render,
@Nullable Predicate<BloomRenderTicket> validityChecker,
@Nullable Supplier<World> worldContext) {
if (Mods.Optifine.isModLoaded()) return BloomRenderTicket.INVALID;
if (Mods.ShadersMod.isModLoaded()) return BloomRenderTicket.INVALID;
BloomRenderTicket ticket = new BloomRenderTicket(setup, bloomType, render, validityChecker, worldContext);
BLOOM_RENDER_LOCK.lock();
try {
Expand Down Expand Up @@ -302,7 +302,7 @@ public static int renderBloomBlockLayer(RenderGlobal renderGlobal,
@NotNull Entity entity) {
Minecraft.getMinecraft().profiler.endStartSection("BTLayer");

if (Mods.Optifine.isModLoaded()) {
if (Mods.ShadersMod.isModLoaded()) {
return renderGlobal.renderBlockLayer(blockRenderLayer, partialTicks, pass, entity);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gregtech/client/utils/CTMHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class CTMHooks {
public static ThreadLocal<Boolean> ENABLE = new ThreadLocal<>();

public static boolean checkLayerWithOptiFine(boolean canRenderInLayer, byte layers, BlockRenderLayer layer) {
if (Mods.Optifine.isModLoaded()) {
if (Mods.ShadersMod.isModLoaded()) {
if (canRenderInLayer) {
if (layer == BloomEffectUtil.getBloomLayer()) return false;
} else if ((layers >> BloomEffectUtil.getBloomLayer().ordinal() & 1) == 1 &&
Expand All @@ -50,7 +50,7 @@ public static boolean checkLayerWithOptiFine(boolean canRenderInLayer, byte laye
public static List<BakedQuad> getQuadsWithOptiFine(List<BakedQuad> ret, BlockRenderLayer layer,
IBakedModel bakedModel, IBlockState state, EnumFacing side,
long rand) {
if (Mods.Optifine.isModLoaded() && CTMHooks.ENABLE.get() == null) {
if (Mods.ShadersMod.isModLoaded() && CTMHooks.ENABLE.get() == null) {
if (layer == BloomEffectUtil.getBloomLayer()) {
return Collections.emptyList();
} else if (layer == BloomEffectUtil.getEffectiveBloomLayer()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class DepthTextureUtil {
private static int lastWidth, lastHeight;

private static boolean shouldRenderDepthTexture() {
return lastBind && !Mods.Optifine.isModLoaded() && ConfigHolder.client.hookDepthTexture &&
return lastBind && !Mods.ShadersMod.isModLoaded() && ConfigHolder.client.hookDepthTexture &&
OpenGlHelper.isFramebufferEnabled();
}

Expand Down
Loading