Skip to content

Commit

Permalink
Expert cooker
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Jun 20, 2024
1 parent fd38c38 commit 7eddf3c
Show file tree
Hide file tree
Showing 16 changed files with 277 additions and 151 deletions.
24 changes: 0 additions & 24 deletions LICENSE-TEMPLATE

This file was deleted.

8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# gradle.properties file -- CHANGE THE VALUES STARTING WITH `mod_*` AND REMOVE THIS COMMENT.

# Sets the name of your mod.
mod_name=ExampleMod
mod_name=ColorSaturation
# Sets the id of your mod that mod loaders use to recognize it.
mod_id=examplemod
mod_id=colorsaturation
# Sets the version of your mod. Make sure to update this when you make changes according to semver.
mod_version=1.0.0
mod_version=1.0.0-alpha1
# Sets the name of the jar file that you put in your 'mods' folder.
mod_archives_name=ExampleMod
mod_archives_name=ColorSaturation

# Gradle Configuration -- DO NOT TOUCH THESE VALUES.
polyfrost.defaults.loom=3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.polyfrost.example;
package org.polyfrost.colorsaturation;

import org.polyfrost.example.command.ExampleCommand;
import org.polyfrost.example.config.TestConfig;
import cc.polyfrost.oneconfig.events.EventManager;
import org.polyfrost.colorsaturation.command.SaturationCommand;
import org.polyfrost.colorsaturation.config.SaturationConfig;
import cc.polyfrost.oneconfig.events.event.InitializationEvent;
import net.minecraftforge.fml.common.Mod;
import cc.polyfrost.oneconfig.utils.commands.CommandManager;
Expand All @@ -13,21 +14,20 @@
* @see Mod
* @see InitializationEvent
*/
@Mod(modid = ExampleMod.MODID, name = ExampleMod.NAME, version = ExampleMod.VERSION)
public class ExampleMod {
@Mod(modid = ColorSaturation.MODID, name = ColorSaturation.NAME, version = ColorSaturation.VERSION)
public class ColorSaturation {

// Sets the variables from `gradle.properties`. See the `blossom` config in `build.gradle.kts`.
public static final String MODID = "@ID@";
public static final String NAME = "@NAME@";
public static final String VERSION = "@VER@";
@Mod.Instance(MODID)
public static ExampleMod INSTANCE; // Adds the instance of the mod, so we can access other variables.
public static TestConfig config;
public static SaturationConfig config;

// Register the config and commands.
@Mod.EventHandler
public void onInit(FMLInitializationEvent event) {
config = new TestConfig();
CommandManager.INSTANCE.registerCommand(new ExampleCommand());
config = new SaturationConfig();
CommandManager.INSTANCE.registerCommand(new SaturationCommand());
EventManager.INSTANCE.register(new Saturation());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.polyfrost.colorsaturation;

import net.minecraft.client.shader.ShaderGroup;

public interface EntityRendererHook {
ShaderGroup colorSaturation$getSaturationShader();
void colorSaturation$setSaturationShader(ShaderGroup saturationShader);
}
89 changes: 89 additions & 0 deletions src/main/java/org/polyfrost/colorsaturation/Saturation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.polyfrost.colorsaturation;

import cc.polyfrost.oneconfig.events.event.RenderEvent;
import cc.polyfrost.oneconfig.events.event.Stage;
import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
import cc.polyfrost.oneconfig.libs.universal.UResolution;
import net.minecraft.client.shader.Shader;
import net.minecraft.client.shader.ShaderGroup;
import net.minecraft.client.shader.ShaderUniform;
import net.minecraft.util.ResourceLocation;
import org.polyfrost.colorsaturation.config.SaturationConfig;
import org.polyfrost.colorsaturation.mixin.ShaderGroupAccessor;

import java.io.IOException;
import java.util.List;

public class Saturation {
private static boolean lastEnabled = false;

private static final ResourceLocation phosphorBlur = new ResourceLocation("minecraft:shaders/post/color_convolve.json");

@Subscribe
private void onRenderTick(RenderEvent event) {
if (event.stage != Stage.END) {
return;
}

// Only update the shader if one is active
if (!isShaderActive() || lastEnabled != ColorSaturation.config.enabled) {
lastEnabled = ColorSaturation.config.enabled;
reloadShader();
}
}

public static void reloadShader() {
if (UMinecraft.getWorld() == null) {
return;
}

if (!isShaderActive() && ColorSaturation.config.enabled) {
try {
final ShaderGroup saturationShader = new ShaderGroup(UMinecraft.getMinecraft().getTextureManager(), UMinecraft.getMinecraft().getResourceManager(), UMinecraft.getMinecraft().getFramebuffer(), phosphorBlur);
saturationShader.createBindFramebuffers(UResolution.getWindowWidth(), UResolution.getWindowHeight());
((EntityRendererHook) UMinecraft.getMinecraft().entityRenderer).colorSaturation$setSaturationShader(saturationShader);
reloadSaturation();
} catch (IOException e) {
e.printStackTrace();
}
} else if (isShaderActive() && !ColorSaturation.config.enabled) {
final EntityRendererHook entityRenderer = (EntityRendererHook) UMinecraft.getMinecraft().entityRenderer;
if (entityRenderer.colorSaturation$getSaturationShader() != null) {
entityRenderer.colorSaturation$getSaturationShader().deleteShaderGroup();
}

entityRenderer.colorSaturation$setSaturationShader(null);
}
}

public static void reloadSaturation() {
try {
final List<Shader> listShaders = ((ShaderGroupAccessor) ((EntityRendererHook) UMinecraft.getMinecraft().entityRenderer).colorSaturation$getSaturationShader()).getListShaders();

if (listShaders == null) {
return;
}

for (Shader shader : listShaders) {
ShaderUniform su = shader.getShaderManager().getShaderUniform("Saturation");

if (su == null) {
continue;
}

su.set(SaturationConfig.saturation);
}
} catch (IllegalArgumentException ex) {
ex.printStackTrace();
}
}

private static boolean isShaderActive() {
return ((EntityRendererHook) UMinecraft.getMinecraft().entityRenderer).colorSaturation$getSaturationShader() != null
//#if MC<=11202
&& net.minecraft.client.renderer.OpenGlHelper.shadersSupported
//#endif
;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.polyfrost.colorsaturation.command;

import org.polyfrost.colorsaturation.ColorSaturation;
import cc.polyfrost.oneconfig.utils.commands.annotations.Command;
import cc.polyfrost.oneconfig.utils.commands.annotations.Main;

@Command(value = ColorSaturation.MODID, description = "Access the " + ColorSaturation.NAME + " GUI.")
public class SaturationCommand {
@Main
private void handle() {
ColorSaturation.config.openGui();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.polyfrost.colorsaturation.config;

import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.config.annotations.Info;
import cc.polyfrost.oneconfig.config.annotations.Slider;
import cc.polyfrost.oneconfig.config.annotations.Switch;
import cc.polyfrost.oneconfig.config.data.InfoType;
import cc.polyfrost.oneconfig.config.data.Mod;
import cc.polyfrost.oneconfig.config.data.ModType;
import org.polyfrost.colorsaturation.ColorSaturation;
import org.polyfrost.colorsaturation.Saturation;

/**
* The main Config entrypoint that extends the Config type and inits the config options.
* See <a href="https://docs.polyfrost.cc/oneconfig/config/adding-options">this link</a> for more config Options
*/
public class SaturationConfig extends Config {

@Info(
text = "This mod will ONLY work if either Fast Render is disabled or Force Disable Fast Render is enabled.",
size = 2,
type = InfoType.WARNING
)
private boolean agajsjg = false;

@Switch(
name = "Force Disable Fast Render"
)
public static boolean forceDisableFastRender = true;

@Slider(
name = "Example Slider",
min = -1f, max = 5 // Minimum and maximum values for the slider.
)
public static float saturation = 1;

public SaturationConfig() {
super(new Mod(ColorSaturation.NAME, ModType.UTIL_QOL), ColorSaturation.MODID + ".json");
initialize();

addListener("saturation", () -> {
if (enabled) {
Saturation.reloadSaturation();
}
});
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.polyfrost.colorsaturation.mixin;

import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.shader.ShaderGroup;
import org.polyfrost.colorsaturation.EntityRendererHook;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(EntityRenderer.class)
public class EntityRendererMixin implements EntityRendererHook {
@Shadow
private ShaderGroup theShaderGroup;
@Unique
private ShaderGroup colorSaturation$saturationShader;

@Inject(method = "isShaderActive", at = @At("HEAD"), cancellable = true)
private void onIsShaderActive(CallbackInfoReturnable<Boolean> cir) {
if (colorSaturation$saturationShader != null && OpenGlHelper.shadersSupported) {
cir.setReturnValue(true);
}
}

@Inject(method = "getShaderGroup", at = @At("HEAD"), cancellable = true)
private void onGetShaderGroup(CallbackInfoReturnable<ShaderGroup> cir) {
if (colorSaturation$saturationShader != null && OpenGlHelper.shadersSupported && this.theShaderGroup == null) {
cir.setReturnValue(colorSaturation$saturationShader);
}
}

@Inject(method = "updateShaderGroupSize", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;createBindEntityOutlineFbs(II)V"))
private void updatePhosphor(int width, int height, CallbackInfo ci) {
if (colorSaturation$saturationShader != null) {
colorSaturation$saturationShader.createBindFramebuffers(width, height);
}
}

@Inject(method = "updateCameraAndRender", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;renderEntityOutlineFramebuffer()V", shift = At.Shift.AFTER))
private void renderPhosphor(float partialTicks, long nanoTime, CallbackInfo ci) {
if (this.colorSaturation$saturationShader != null) {
GlStateManager.matrixMode(5890);
GlStateManager.pushMatrix();
GlStateManager.loadIdentity();
this.colorSaturation$saturationShader.loadShaderGroup(partialTicks);
GlStateManager.popMatrix();
}
}

@Override
public ShaderGroup colorSaturation$getSaturationShader() {
return colorSaturation$saturationShader;
}

@Override
public void colorSaturation$setSaturationShader(ShaderGroup saturationShader) {
this.colorSaturation$saturationShader = saturationShader;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.polyfrost.colorsaturation.mixin;

import org.polyfrost.colorsaturation.ColorSaturation;
import org.polyfrost.colorsaturation.config.SaturationConfig;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Pseudo
@Mixin(targets = "Config", remap = false)
public class OptifineConfigMixin {
@Dynamic("OptiFine")
@Inject(method = "isFastRender", at = @At("HEAD"), cancellable = true)
private static void cancelFastRender(CallbackInfoReturnable<Boolean> cir) {
if (ColorSaturation.config.enabled && SaturationConfig.forceDisableFastRender) {
cir.setReturnValue(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.polyfrost.colorsaturation.mixin;

import net.minecraft.client.shader.Shader;
import net.minecraft.client.shader.ShaderGroup;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.List;

@Mixin(ShaderGroup.class)
public interface ShaderGroupAccessor {
@Accessor
List<Shader> getListShaders();
}
21 changes: 0 additions & 21 deletions src/main/java/org/polyfrost/example/command/ExampleCommand.java

This file was deleted.

Loading

0 comments on commit 7eddf3c

Please sign in to comment.