diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
3 files changed, 151 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/chroma/ChromaFontRenderer.kt b/src/main/java/at/hannibal2/skyhanni/features/chroma/ChromaFontRenderer.kt new file mode 100644 index 000000000..981b7b33a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/chroma/ChromaFontRenderer.kt @@ -0,0 +1,66 @@ +package at.hannibal2.skyhanni.features.chroma + +import at.hannibal2.skyhanni.utils.ColorUtils +import at.hannibal2.skyhanni.utils.shader.ShaderHelper +import net.minecraft.client.renderer.GlStateManager +import org.lwjgl.opengl.GL11 + +/** + * Class to handle chroma font rendering + * + * Modified class from SkyblockAddons + * + * Credit: [DrawStateFontRenderer.java](https://github.com/BiscuitDevelopment/SkyblockAddons/blob/main/src/main/java/codes/biscuit/skyblockaddons/utils/draw/DrawStateFontRenderer.java) + */ +class ChromaFontRenderer(private val baseColor: Int) { + + private var chromaOn = false + + fun startChroma() { + chromaOn = true + } + + fun endChroma() { + chromaOn = false + } + + fun loadChromaEnv() { + if (chromaOn) { + newChromaEnv() + } + } + + fun restoreChromaEnv() { + if (ShaderHelper.areShadersSupported()) { + if (!chromaOn) ChromaShaderManager.end() + } + } + + fun newChromaEnv() : ChromaFontRenderer { + if (ShaderHelper.areShadersSupported()) { + ChromaShaderManager.begin() + GlStateManager.shadeModel(GL11.GL_SMOOTH) + } + return this + } + + fun bindActualColor() : ChromaFontRenderer { + GlStateManager.color( + ColorUtils.getRed(baseColor).toFloat() / 255f, + ColorUtils.getGreen(baseColor).toFloat() / 255f, + ColorUtils.getBlue(baseColor).toFloat() / 255f, + ColorUtils.getAlpha(baseColor).toFloat() / 255f + ) + return this + } + + fun endChromaEnv() : ChromaFontRenderer { + if (ShaderHelper.areShadersSupported()) { + ChromaShaderManager.end() + GlStateManager.shadeModel(GL11.GL_FLAT) + } + return this + } + + fun getChromaState() = chromaOn +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/chroma/ChromaShader.kt b/src/main/java/at/hannibal2/skyhanni/features/chroma/ChromaShader.kt new file mode 100644 index 000000000..00215b032 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/chroma/ChromaShader.kt @@ -0,0 +1,47 @@ +package at.hannibal2.skyhanni.features.chroma + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.MinecraftData +import at.hannibal2.skyhanni.mixins.transformers.AccessorMinecraft +import at.hannibal2.skyhanni.utils.shader.Shader +import at.hannibal2.skyhanni.utils.shader.Uniform +import net.minecraft.client.Minecraft + +/** + * Modified from SkyblockAddons + * + * Credit: [ChromaShader.java](https://github.com/BiscuitDevelopment/SkyblockAddons/blob/main/src/main/java/codes/biscuit/skyblockaddons/shader/chroma/ChromaShader.java) + */ +object ChromaShader : Shader("chroma", "chroma") { + + val INSTANCE: ChromaShader + get() = this + + override fun registerUniforms() { + registerUniform(Uniform.UniformType.FLOAT, "chromaSize") { + SkyHanniMod.feature.chroma.chromaSize * (Minecraft.getMinecraft().displayWidth / 100f) + } + registerUniform(Uniform.UniformType.FLOAT, "timeOffset") { + var ticks = (MinecraftData.totalTicks / 2) + (Minecraft.getMinecraft() as AccessorMinecraft).timer.renderPartialTicks + + ticks = when (SkyHanniMod.feature.chroma.chromaDirection) { + 0, 2 -> ticks + 1, 3 -> -ticks + else -> ticks + } + + val chromaSpeed = SkyHanniMod.feature.chroma.chromaSpeed / 360f + ticks * chromaSpeed + } + registerUniform(Uniform.UniformType.FLOAT, "saturation") { + SkyHanniMod.feature.chroma.chromaSaturation + } + registerUniform(Uniform.UniformType.BOOL, "forwardDirection") { + when (SkyHanniMod.feature.chroma.chromaDirection) { + 0, 1 -> true + 2, 3 -> false + else -> true + } + } + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/chroma/ChromaShaderManager.kt b/src/main/java/at/hannibal2/skyhanni/features/chroma/ChromaShaderManager.kt new file mode 100644 index 000000000..ccf0ec21e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/chroma/ChromaShaderManager.kt @@ -0,0 +1,38 @@ +package at.hannibal2.skyhanni.features.chroma + +import at.hannibal2.skyhanni.utils.shader.ShaderManager + +/** + * Object to handle enabling / disabling the chroma shader when rendering text + * + * Modified from SkyblockAddons + * + * Credit: [MulticolorShaderManager.java](https://github.com/BiscuitDevelopment/SkyblockAddons/blob/main/src/main/java/codes/biscuit/skyblockaddons/core/chroma/MulticolorShaderManager.java) + */ +object ChromaShaderManager { + + private var chromaEnabled = false + + fun begin() { + disable() + enable() + } + + fun end() { + disable() + } + + private fun enable() { + if (!chromaEnabled) { + chromaEnabled = true + ShaderManager.enableShader("chroma") + } + } + + private fun disable() { + if (chromaEnabled) { + chromaEnabled = false + ShaderManager.disableShader() + } + } +}
\ No newline at end of file |