generated from Polyfrost/OneConfigExampleMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
277 additions
and
151 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/org/polyfrost/colorsaturation/EntityRendererHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
89
src/main/java/org/polyfrost/colorsaturation/Saturation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/polyfrost/colorsaturation/command/SaturationCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/org/polyfrost/colorsaturation/config/SaturationConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}); | ||
} | ||
} | ||
|
64 changes: 64 additions & 0 deletions
64
src/main/java/org/polyfrost/colorsaturation/mixin/EntityRendererMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/polyfrost/colorsaturation/mixin/OptifineConfigMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/polyfrost/colorsaturation/mixin/ShaderGroupAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
src/main/java/org/polyfrost/example/command/ExampleCommand.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.