Skip to content

Commit

Permalink
config + mek covers
Browse files Browse the repository at this point in the history
  • Loading branch information
ferriarnus committed Dec 25, 2024
1 parent 06ef828 commit f96e188
Show file tree
Hide file tree
Showing 26 changed files with 209 additions and 54 deletions.
9 changes: 8 additions & 1 deletion mod/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ dependencies {
}

implementation("org.embeddedt:embeddium-1.21:${embeddium_version}")


compileOnly("mekanism:Mekanism:1.21.1-10.7.0.55")
runtimeOnly("mekanism:Mekanism:1.21.1-10.7.0.55")

runtimeOnly("curse.maven:xycraft-653786:5601037")
Expand Down Expand Up @@ -199,6 +200,12 @@ dependencies {

runtimeOnly("maven.modrinth:caxton:0.6.0-alpha.5+1.21.1-NEOFORGE")

runtimeOnly("curse.maven:industrial-foregoing-266515:5951082")
runtimeOnly("curse.maven:titanium-287342:5897690")

compileOnly("curse.maven:mekanism-covers-1119874:5831284")
runtimeOnly("curse.maven:mekanism-covers-1119874:5831284")


upstreamTransformerImplementation("io.github.douira:glsl-transformer:2.0.1")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.ferriarnus.monocle.moddedshaders;

import dev.ferriarnus.monocle.moddedshaders.mods.FramedBlocksCamo;
import dev.ferriarnus.monocle.moddedshaders.mods.MekanismCoversCamo;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.BlockAndTintGetter;
Expand All @@ -10,12 +11,16 @@
public class CamoShaders {

private static final boolean FRAMEDBLOCKS = LoadingModList.get().getModFileById("framedblocks") != null;
private static final boolean MEK_COVERS = LoadingModList.get().getModFileById("mekanismcovers") != null;

public static BlockState getBlockstate(BlockAndTintGetter slice, BlockPos pos, BlockState state) {
BlockState camo = state;
if (FRAMEDBLOCKS) {
camo = FramedBlocksCamo.getBlockstate(slice, pos, camo);
}
if (MEK_COVERS) {
camo = MekanismCoversCamo.getBlockstate(slice, pos, camo);
}
return camo.getAppearance(slice, pos, Direction.UP, null, null);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.ferriarnus.monocle.moddedshaders.config;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.CLASS)
@Target(ElementType.TYPE)
public @interface Config {
String value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package dev.ferriarnus.monocle.moddedshaders.config;

import net.minecraft.client.Minecraft;
import net.neoforged.fml.loading.FMLPaths;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Properties;
import java.util.Set;

public class ConfigPlugin implements IMixinConfigPlugin {

private static final String MIXINCONFIG = Type.getDescriptor(Config.class);
private static final Path CONFIG_PATH = FMLPaths.CONFIGDIR.get().resolve("monocle.properties");
public static final String FALSE = "false";
private static final String[] MODS = new String[]{
"justdirethings",
"supplementaries",
"caxton",
"twilightforest",
"enchanted",
"the_bumblezone",
"forbidden_arcanus",
"xycraft",
"immersiveengineering",
"computercraft",
"creeperoverhaul",
"arsnouveau",
"mekanism"
};

@Override
public void onLoad(String mixinPackage) {

}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
try(InputStream stream = this.getClass().getClassLoader().getResourceAsStream(mixinClassName.replace('.', '/') + ".class")) {
ClassReader reader = new ClassReader(stream);
ClassNode node = new ClassNode();
reader.accept(node, ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG);
if (node.invisibleAnnotations == null) {
return true;
}

Properties config = new Properties();
if (!Files.exists(CONFIG_PATH)) {
makeConfig();
}
config.load(Files.newBufferedReader(CONFIG_PATH));

for(AnnotationNode annotation : node.invisibleAnnotations) {
if (annotation.desc.equals(MIXINCONFIG)) {
for(int i = 0; i < annotation.values.size(); i += 2) {
if(annotation.values.get(i).equals("value")) {
String modId = (String) annotation.values.get(i + 1);
if(modId != null) {
if (FALSE.equals(config.getProperty("All")) && FALSE.equals(config.getProperty(modId))) {
return false;
}
}
break;
}
}
}
}

} catch(IOException e) {
e.printStackTrace();
}
return true;
}

private static void makeConfig() {
try (var writer = Files.newBufferedWriter(CONFIG_PATH);){
writer.write("# Modded Shader Config\n");
writer.write("# ====================\n");
writer.write("# Enable/disable all modded shader compat (true/false)\n");
writer.write("All = true\n");
writer.write("# ====================\n");
writer.write("# Enable/disable for individual mods (true/false)\n");
for (String mod : MODS) {
writer.write(mod + " = false\n");
}
} catch (IOException e) {
e.printStackTrace();
}
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {

}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.blaze3d.shaders.Uniform;
import dev.ferriarnus.monocle.moddedshaders.ModdedShaderPipeline;
import dev.ferriarnus.monocle.moddedshaders.config.Config;
import dev.ferriarnus.monocle.moddedshaders.mods.SuppShaders;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.shadows.ShadowRenderingState;
Expand All @@ -16,6 +17,7 @@

import java.util.function.Function;

@Config("supplementaries")
@Mixin(targets = "net/mehvahdjukaar/supplementaries/client/renderers/tiles/BlackboardBlockTileRenderer", remap = false)
public class MixinBlackboardBlockTileRenderer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import dev.ferriarnus.monocle.moddedshaders.ModdedShaderPipeline;
import dev.ferriarnus.monocle.moddedshaders.config.Config;
import dev.ferriarnus.monocle.moddedshaders.mods.CaxtonShaders;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.pipeline.WorldRenderingPhase;
Expand All @@ -15,6 +16,7 @@
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;

@Config("caxton")
@Mixin(targets = "xyz/flirora/caxton/render/CaxtonTextRenderLayers$RenderLayerFunctions")
public class MixinCaxtonTextRenderLayers {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.BufferUploader;
import dev.ferriarnus.monocle.moddedshaders.ModdedShaderPipeline;
import dev.ferriarnus.monocle.moddedshaders.config.Config;
import dev.ferriarnus.monocle.moddedshaders.mods.TWFShaders;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.shadows.ShadowRenderingState;
Expand All @@ -15,6 +16,7 @@
import org.spongepowered.asm.mixin.injection.At;
import twilightforest.client.TFShaders;

@Config("twilightforest")
@Mixin(targets = "twilightforest/client/event/ClientEvents", remap = false)
public class MixinClientEvents {

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

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import dev.ferriarnus.monocle.moddedshaders.config.Config;
import dev.ferriarnus.monocle.moddedshaders.mods.EWShaders;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.shadows.ShadowRenderingState;
Expand All @@ -10,6 +11,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Config("enchanted")
@Mixin(targets = "net/favouriteless/enchanted/client/EParticleRenderTypes", remap = false)
public class MixinEParticleRenderTypes {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ferriarnus.monocle.moddedshaders.mixin.mods;

import dev.ferriarnus.monocle.moddedshaders.config.Config;
import dev.ferriarnus.monocle.moddedshaders.mods.BumbleShaders;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.shadows.ShadowRenderingState;
Expand All @@ -10,6 +11,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Config("the_bumblezone")
@Mixin(targets = "com/telepathicgrunt/the_bumblezone/client/blockentityrenderer/EssenceBlockEntityRenderer", remap = false)
public class MixinEssenceBlockEntityRenderer {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.ferriarnus.monocle.moddedshaders.mixin.mods;

import dev.ferriarnus.monocle.moddedshaders.ModdedShaderPipeline;
import dev.ferriarnus.monocle.moddedshaders.config.Config;
import dev.ferriarnus.monocle.moddedshaders.mods.FAShaders;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.shadows.ShadowRenderingState;
Expand All @@ -11,6 +12,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Config("forbidden_arcanus")
@Mixin(targets = "com/stal111/forbidden_arcanus/client/FAShaders")
public class MixinFAShaders {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.blaze3d.shaders.Uniform;
import dev.ferriarnus.monocle.moddedshaders.ModdedShaderPipeline;
import dev.ferriarnus.monocle.moddedshaders.config.Config;
import dev.ferriarnus.monocle.moddedshaders.mods.SuppShaders;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.shadows.ShadowRenderingState;
Expand All @@ -16,6 +17,7 @@

import java.util.function.Function;

@Config("supplementaries")
@Mixin(targets = "net/mehvahdjukaar/supplementaries/client/renderers/tiles/GlobeBlockTileRenderer")
public class MixinGlobeBlockTileRenderer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mojang.blaze3d.vertex.ByteBufferBuilder;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import dev.ferriarnus.monocle.moddedshaders.config.Config;
import dev.ferriarnus.monocle.moddedshaders.mods.DireShaders;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.shadows.ShadowRenderingState;
Expand All @@ -22,28 +23,12 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Config("justdirethings")
@Mixin(targets = "com/direwolf20/justdirethings/client/blockentityrenders/baseber/GooBlockRender_Base")
public class MixinGooBlockRender_Base {

// @WrapOperation(method = "renderTexturePattern", at = @At(value = "FIELD", target = "Lcom/direwolf20/justdirethings/client/renderers/OurRenderTypes;GooPattern:Lnet/minecraft/client/renderer/RenderType;"))
// public RenderType WrapBuffer(Operation<RenderType> original) {
// if (Iris.isPackInUseQuick() && !ShadowRenderingState.areShadowsCurrentlyBeingRendered()) {
// return DireShaders.GooPattern;
// }
// return original.call();
// }
//
// @WrapOperation(method = "renderTexturePattern", at = @At(value = "FIELD", target = "Lcom/direwolf20/justdirethings/client/renderers/OurRenderTypes;RenderBlockBackface:Lnet/minecraft/client/renderer/RenderType;"))
// public RenderType WrapBuffer2(Operation<RenderType> original) {
// if (Iris.isPackInUseQuick() && !ShadowRenderingState.areShadowsCurrentlyBeingRendered()) {
// return DireShaders.RenderBlockBackface;
// }
// return original.call();
// }

@Unique
private final MultiBufferSource.BufferSource bufferSource = MultiBufferSource.immediate(new ByteBufferBuilder(786432));
private final MultiBufferSource.BufferSource bufferSource2 = MultiBufferSource.immediate(new ByteBufferBuilder(786432));

@Inject(method = "renderTexturePattern", at = @At("HEAD"))
public void head(Direction direction, Level level, BlockPos pos, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedOverlayIn, float transparency, BlockState pattern, BlockState renderState, GooBlockBE_Base gooBlockBE_base, CallbackInfo ci) {
Expand Down Expand Up @@ -72,7 +57,7 @@ public VertexConsumer WrapBuffer(MultiBufferSource instance, RenderType renderTy
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource;getBuffer(Lnet/minecraft/client/renderer/RenderType;)Lcom/mojang/blaze3d/vertex/VertexConsumer;", ordinal = 1))
public VertexConsumer WrapBuffer2(MultiBufferSource instance, RenderType renderType, Operation<VertexConsumer> original) {
if (Iris.isPackInUseQuick() && !ShadowRenderingState.areShadowsCurrentlyBeingRendered()) {
return bufferSource2.getBuffer(DireShaders.RenderBlockBackface);
return bufferSource.getBuffer(DireShaders.RenderBlockBackface);
}
return original.call(instance, renderType);
}
Expand All @@ -81,15 +66,15 @@ public VertexConsumer WrapBuffer2(MultiBufferSource instance, RenderType renderT
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource;getBuffer(Lnet/minecraft/client/renderer/RenderType;)Lcom/mojang/blaze3d/vertex/VertexConsumer;", shift = At.Shift.BEFORE, ordinal = 1))
public void injectEnd1(Direction direction, Level level, BlockPos pos, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedOverlayIn, float transparency, BlockState pattern, BlockState renderState, GooBlockBE_Base gooBlockBE_base, CallbackInfo ci) {
if (Iris.isPackInUseQuick() && !ShadowRenderingState.areShadowsCurrentlyBeingRendered()) {
bufferSource.endBatch();
bufferSource.endBatch(DireShaders.GooPattern);
}
}

@Inject(method = "renderTexturePattern",
at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;popPose()V", shift = At.Shift.AFTER))
public void injectEnd2(Direction direction, Level level, BlockPos pos, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedOverlayIn, float transparency, BlockState pattern, BlockState renderState, GooBlockBE_Base gooBlockBE_base, CallbackInfo ci) {
if (Iris.isPackInUseQuick() && !ShadowRenderingState.areShadowsCurrentlyBeingRendered()) {
bufferSource2.endBatch();
bufferSource.endBatch(DireShaders.RenderBlockBackface);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.ferriarnus.monocle.moddedshaders.mixin.mods;

import dev.ferriarnus.monocle.moddedshaders.ModdedShaderPipeline;
import dev.ferriarnus.monocle.moddedshaders.config.Config;
import dev.ferriarnus.monocle.moddedshaders.mods.IEShaders;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.shadows.ShadowRenderingState;
Expand All @@ -11,6 +12,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Config("immersiveengineering")
@Mixin(targets = "blusunrize/immersiveengineering/client/utils/IEGLShaders", remap = false)
public class MixinIEGLShaders {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import dev.ferriarnus.monocle.moddedshaders.ModdedShaderPipeline;
import dev.ferriarnus.monocle.moddedshaders.config.Config;
import dev.ferriarnus.monocle.moddedshaders.mods.XYShaders;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.shadows.ShadowRenderingState;
Expand All @@ -11,6 +12,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Config("xycraft")
@Mixin(targets = "tv/soaryn/xycraft/machines/client/render/instanced/InstancedIcosphere", remap = false)
public class MixinIcoSphere {

Expand Down
Loading

0 comments on commit f96e188

Please sign in to comment.