diff --git a/LICENSE-TEMPLATE b/LICENSE-TEMPLATE deleted file mode 100644 index fdddb29..0000000 --- a/LICENSE-TEMPLATE +++ /dev/null @@ -1,24 +0,0 @@ -This is free and unencumbered software released into the public domain. - -Anyone is free to copy, modify, publish, use, compile, sell, or -distribute this software, either in source code form or as a compiled -binary, for any purpose, commercial or non-commercial, and by any -means. - -In jurisdictions that recognize copyright laws, the author or authors -of this software dedicate any and all copyright interest in the -software to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and -successors. We intend this dedication to be an overt act of -relinquishment in perpetuity of all present and future rights to this -software under copyright law. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -For more information, please refer to diff --git a/gradle.properties b/gradle.properties index f8f0b3b..21c5c0d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/java/org/polyfrost/example/ExampleMod.java b/src/main/java/org/polyfrost/colorsaturation/ColorSaturation.java similarity index 56% rename from src/main/java/org/polyfrost/example/ExampleMod.java rename to src/main/java/org/polyfrost/colorsaturation/ColorSaturation.java index 043a208..86e18b1 100644 --- a/src/main/java/org/polyfrost/example/ExampleMod.java +++ b/src/main/java/org/polyfrost/colorsaturation/ColorSaturation.java @@ -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; @@ -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()); } } diff --git a/src/main/java/org/polyfrost/colorsaturation/EntityRendererHook.java b/src/main/java/org/polyfrost/colorsaturation/EntityRendererHook.java new file mode 100644 index 0000000..66e4a60 --- /dev/null +++ b/src/main/java/org/polyfrost/colorsaturation/EntityRendererHook.java @@ -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); +} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/colorsaturation/Saturation.java b/src/main/java/org/polyfrost/colorsaturation/Saturation.java new file mode 100644 index 0000000..0cc3c63 --- /dev/null +++ b/src/main/java/org/polyfrost/colorsaturation/Saturation.java @@ -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 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 + ; + } +} diff --git a/src/main/java/org/polyfrost/colorsaturation/command/SaturationCommand.java b/src/main/java/org/polyfrost/colorsaturation/command/SaturationCommand.java new file mode 100644 index 0000000..41a405f --- /dev/null +++ b/src/main/java/org/polyfrost/colorsaturation/command/SaturationCommand.java @@ -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(); + } +} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/colorsaturation/config/SaturationConfig.java b/src/main/java/org/polyfrost/colorsaturation/config/SaturationConfig.java new file mode 100644 index 0000000..88dce15 --- /dev/null +++ b/src/main/java/org/polyfrost/colorsaturation/config/SaturationConfig.java @@ -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 this link 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(); + } + }); + } +} + diff --git a/src/main/java/org/polyfrost/colorsaturation/mixin/EntityRendererMixin.java b/src/main/java/org/polyfrost/colorsaturation/mixin/EntityRendererMixin.java new file mode 100644 index 0000000..647ae9f --- /dev/null +++ b/src/main/java/org/polyfrost/colorsaturation/mixin/EntityRendererMixin.java @@ -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 cir) { + if (colorSaturation$saturationShader != null && OpenGlHelper.shadersSupported) { + cir.setReturnValue(true); + } + } + + @Inject(method = "getShaderGroup", at = @At("HEAD"), cancellable = true) + private void onGetShaderGroup(CallbackInfoReturnable 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; + } +} diff --git a/src/main/java/org/polyfrost/colorsaturation/mixin/OptifineConfigMixin.java b/src/main/java/org/polyfrost/colorsaturation/mixin/OptifineConfigMixin.java new file mode 100644 index 0000000..fe3c5e0 --- /dev/null +++ b/src/main/java/org/polyfrost/colorsaturation/mixin/OptifineConfigMixin.java @@ -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 cir) { + if (ColorSaturation.config.enabled && SaturationConfig.forceDisableFastRender) { + cir.setReturnValue(false); + } + } +} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/colorsaturation/mixin/ShaderGroupAccessor.java b/src/main/java/org/polyfrost/colorsaturation/mixin/ShaderGroupAccessor.java new file mode 100644 index 0000000..3144719 --- /dev/null +++ b/src/main/java/org/polyfrost/colorsaturation/mixin/ShaderGroupAccessor.java @@ -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 getListShaders(); +} diff --git a/src/main/java/org/polyfrost/example/command/ExampleCommand.java b/src/main/java/org/polyfrost/example/command/ExampleCommand.java deleted file mode 100644 index b4373a3..0000000 --- a/src/main/java/org/polyfrost/example/command/ExampleCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.polyfrost.example.command; - -import org.polyfrost.example.ExampleMod; -import cc.polyfrost.oneconfig.utils.commands.annotations.Command; -import cc.polyfrost.oneconfig.utils.commands.annotations.Main; - -/** - * An example command implementing the Command api of OneConfig. - * Registered in ExampleMod.java with `CommandManager.INSTANCE.registerCommand(new ExampleCommand());` - * - * @see Command - * @see Main - * @see ExampleMod - */ -@Command(value = ExampleMod.MODID, description = "Access the " + ExampleMod.NAME + " GUI.") -public class ExampleCommand { - @Main - private void handle() { - ExampleMod.INSTANCE.config.openGui(); - } -} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/example/config/TestConfig.java b/src/main/java/org/polyfrost/example/config/TestConfig.java deleted file mode 100644 index a4cc343..0000000 --- a/src/main/java/org/polyfrost/example/config/TestConfig.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.polyfrost.example.config; - -import org.polyfrost.example.ExampleMod; -import org.polyfrost.example.hud.TestHud; -import cc.polyfrost.oneconfig.config.Config; -import cc.polyfrost.oneconfig.config.annotations.Dropdown; -import cc.polyfrost.oneconfig.config.annotations.HUD; -import cc.polyfrost.oneconfig.config.annotations.Slider; -import cc.polyfrost.oneconfig.config.annotations.Switch; -import cc.polyfrost.oneconfig.config.data.Mod; -import cc.polyfrost.oneconfig.config.data.ModType; -import cc.polyfrost.oneconfig.config.data.OptionSize; - -/** - * The main Config entrypoint that extends the Config type and inits the config options. - * See this link for more config Options - */ -public class TestConfig extends Config { - @HUD( - name = "Example HUD" - ) - public TestHud hud = new TestHud(); - - @Switch( - name = "Example Switch", - size = OptionSize.SINGLE // Optional - ) - public static boolean exampleSwitch = false; // The default value for the boolean Switch. - - @Slider( - name = "Example Slider", - min = 0f, max = 100f, // Minimum and maximum values for the slider. - step = 10 // The amount of steps that the slider should have. - ) - public static float exampleSlider = 50f; // The default value for the float Slider. - - @Dropdown( - name = "Example Dropdown", // Name of the Dropdown - options = {"Option 1", "Option 2", "Option 3", "Option 4"} // Options available. - ) - public static int exampleDropdown = 1; // Default option (in this case "Option 2") - - public TestConfig() { - super(new Mod(ExampleMod.NAME, ModType.UTIL_QOL), ExampleMod.MODID + ".json"); - initialize(); - } -} - diff --git a/src/main/java/org/polyfrost/example/hud/TestHud.java b/src/main/java/org/polyfrost/example/hud/TestHud.java deleted file mode 100644 index cd0dfa7..0000000 --- a/src/main/java/org/polyfrost/example/hud/TestHud.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.polyfrost.example.hud; - -import cc.polyfrost.oneconfig.hud.SingleTextHud; -import org.polyfrost.example.config.TestConfig; - -/** - * An example OneConfig HUD that is started in the config and displays text. - * - * @see TestConfig#hud - */ -public class TestHud extends SingleTextHud { - public TestHud() { - super("Test", true); - } - - @Override - public String getText(boolean example) { - return "I'm an example HUD"; - } -} diff --git a/src/main/java/org/polyfrost/example/mixin/MinecraftMixin.java b/src/main/java/org/polyfrost/example/mixin/MinecraftMixin.java deleted file mode 100644 index cc1304c..0000000 --- a/src/main/java/org/polyfrost/example/mixin/MinecraftMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.polyfrost.example.mixin; - -import net.minecraft.client.Minecraft; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -/** - * An example mixin using SpongePowered's Mixin library - * - * @see Inject - * @see Mixin - */ -@Mixin(Minecraft.class) -public class MinecraftMixin { - @Inject(method = "startGame", at = @At(value = "HEAD")) - private void onStartGame(CallbackInfo ci) { - System.out.println("This is a message from an example mod!"); - } -} diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 9028106..1b11a57 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -8,7 +8,7 @@ "url": "", "updateUrl": "", "authorList": [ - "Your Name" + "Polyfrost" ], "credits": "", "logoFile": "", diff --git a/src/main/resources/mixins.examplemod.json b/src/main/resources/mixins.colorsaturation.json similarity index 57% rename from src/main/resources/mixins.examplemod.json rename to src/main/resources/mixins.colorsaturation.json index c5a6f21..d97b243 100644 --- a/src/main/resources/mixins.examplemod.json +++ b/src/main/resources/mixins.colorsaturation.json @@ -1,13 +1,15 @@ { "compatibilityLevel": "JAVA_8", "minVersion": "0.7", - "package": "org.polyfrost.example.mixin", + "package": "org.polyfrost.colorsaturation.mixin", "refmap": "mixins.${id}.refmap.json", "injectors": { "maxShiftBy": 5 }, "client": [ - "MinecraftMixin" + "EntityRendererMixin", + "OptifineConfigMixin", + "ShaderGroupAccessor" ], "verbose": true }