From ca70cc7fb150ca5dca49cb5168b2b11c323ff230 Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Tue, 4 May 2021 21:08:59 +0200 Subject: [PATCH] Remove the "Rendering" clickbox and replace it with a "Risky" one; add a nohurtcam feature --- .../snowygui/mixins/RendererMixin.java | 17 +++++++++ .../fr/username404/snowygui/ClickGui.kt | 8 ++--- .../fr/username404/snowygui/gui/Element.kt | 7 ++-- .../snowygui/gui/elements/ClickBox.kt | 28 ++++++++------- .../snowygui/gui/elements/ClickButton.kt | 7 ++-- .../snowygui/misc/addComponents.kt | 35 ++++++++++--------- .../resources/assets/snowygui/lang/en_us.json | 2 +- .../resources/assets/snowygui/lang/fr_fr.json | 2 +- .../src/main/resources/snowygui-mixins.json | 3 +- 9 files changed, 68 insertions(+), 41 deletions(-) create mode 100644 common/src/main/java/fr/username404/snowygui/mixins/RendererMixin.java diff --git a/common/src/main/java/fr/username404/snowygui/mixins/RendererMixin.java b/common/src/main/java/fr/username404/snowygui/mixins/RendererMixin.java new file mode 100644 index 0000000..66905cc --- /dev/null +++ b/common/src/main/java/fr/username404/snowygui/mixins/RendererMixin.java @@ -0,0 +1,17 @@ +package fr.username404.snowygui.mixins; + +import com.mojang.blaze3d.vertex.PoseStack; +import fr.username404.snowygui.misc.Storage; +import net.minecraft.client.renderer.GameRenderer; +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; + +@Mixin(GameRenderer.class) +public class RendererMixin { + @Inject(method = "bobHurt", at = @At("HEAD"), cancellable = true) + private void onHurt(PoseStack poseStack, float f, CallbackInfo ci) { + if (!Storage.INSTANCE.getHurtCamera()) ci.cancel(); + } +} diff --git a/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt b/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt index f25f473..54ac909 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt @@ -4,12 +4,12 @@ import fr.username404.snowygui.gui.Element import fr.username404.snowygui.gui.SnowyScreen import fr.username404.snowygui.gui.elements.ClickBox import fr.username404.snowygui.gui.elements.ClickButton -import fr.username404.snowygui.misc.addComponents +import fr.username404.snowygui.misc.Storage.addComponents import net.minecraft.network.chat.TranslatableComponent private var baseXAxis: Double = 4.0 -internal fun newBox(translationKey: String): ClickBox { - val result = ClickBox(baseXAxis, 4.0, TranslatableComponent(translationKey)) +internal fun newBox(translationKey: String, color: Int = 0x6C9E9D): ClickBox { + val result = ClickBox(baseXAxis, 4.0, name = TranslatableComponent(translationKey), color = color) baseXAxis += 86 return result } @@ -23,7 +23,7 @@ object ClickGui: SnowyScreen() { private inline fun buttonsContext(args: (ClickButton) -> Unit) = boxContext { it.buttons.values.forEach(args) } override fun mouseClicked(d: Double, e: Double, i: Int): Boolean { buttonsContext { it.mouseClicked(d, e, i) }; return false } override fun mouseReleased(d: Double, e: Double, i: Int): Boolean { buttonsContext { it.mouseReleased(d, e, i) }; return false } - override fun mouseScrolled(d: Double, e: Double, f: Double): Boolean { boxContext { it.scroll(f) }; return false } + override fun mouseScrolled(d: Double, e: Double, f: Double): Boolean { boxContext { it.scroll(d, e, f) }; return false } override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean { if (i == 0) { components.forEach { diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt index 9b27fd8..73d943b 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt @@ -28,8 +28,8 @@ abstract class Element( ): Renderable { open var width = originalWidth; open var height = originalHeight open var x = xOrigin; open var y = yOrigin - internal fun withinBounds(coordinateX: Double, coordinateY: Double): Boolean = - ((coordinateX >= this.x) && (coordinateX <= (this.x + this.width))) and ((coordinateY >= this.y) && (coordinateY <= (this.y + this.height))) + internal fun withinBounds(coordinateX: Double, coordinateY: Double, offsetWidth: Double = 0.0, offsetHeight: Double = 0.0): Boolean = + ((coordinateX >= this.x) && (coordinateX <= (this.x + this.width + offsetWidth))) and ((coordinateY >= this.y) && (coordinateY <= (this.y + this.height + offsetHeight))) companion object { private var caughtError: Boolean = false fun fromRenderable(r: Renderable, x: Double, y: Double, width: Int, height: Int): Element { @@ -55,8 +55,9 @@ abstract class Element( abstract class ColoredElement( x: Double, y: Double, width: Int, height: Int, - protected open var color: Int, protected var opacity: Float, + color: Int = TransparentColor, protected var opacity: Float, ) : Element(x, y, width, height) { + open var color = color; protected set companion object { const val TransparentColor: Int = -0x1 @JvmStatic protected fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer { diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt index f19ceb2..8d02f52 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt @@ -14,15 +14,17 @@ import net.minecraft.client.Minecraft import net.minecraft.network.chat.TranslatableComponent import org.lwjgl.opengl.GL20 +const val clickboxHeightOffset: Int = 80 class ClickBox( x: Double, y: Double, + color: Int = 0x6C9E9D, private val name: TranslatableComponent? = null -): ColoredElement(x, y, 80, 10, 0x6C9E9D, 0.5F) { +): ColoredElement(x, y, 80, 10, color, 0.5F) { val buttons = mutableMapOf() // Can contain up to 16 buttons - fun addButtons(vararg collect: Pair Unit)?>, color: Int = 0x6C9E9D, kind: Type = Type.TOGGLE): ClickBox { + fun addButtons(vararg collect: Pair Unit)?>, kind: Type = Type.TOGGLE): ClickBox { buttons.putAll( collect.map { - it.first to ClickButton(title = it.first, action = it.second, color = color, kind = kind) + it.first to ClickButton(title = it.first, action = it.second, getColorFrom = this, kind = kind) } ) return this @@ -30,7 +32,7 @@ class ClickBox( @JvmField val buttonsProgressBar: ColoredElement = object: ColoredElement( (x + width), y + height + 3, - color = color, width = 3, height = 74, + color = color, width = 3, height = clickboxHeightOffset - 6, opacity = 0.75F ) { override fun render(poseStack: PoseStack?) { @@ -44,12 +46,14 @@ class ClickBox( init { height = 8 } } var barStage: Int = 1; private set - fun scroll(supplied: Double) { - with(buttonsProgressBar) { - if ((height != 8 || (supplied < 0)) && ((height != originalHeight) || (supplied > 0))) { - height -= supplied.toInt() - if (buttons.isNotEmpty()) (height / 8).let { - if (it > 0) barStage = it + fun scroll(d: Double, e: Double, supplied: Double) { + if (withinBounds(d, e, offsetHeight = clickboxHeightOffset.toDouble())) { + with(buttonsProgressBar) { + if ((height != 8 || (supplied < 0)) && ((height != originalHeight) || (supplied > 0))) { + height -= supplied.toInt() + if (buttons.isNotEmpty()) (height / 8).let { + if (it > 0) barStage = it + } } } } @@ -72,7 +76,7 @@ class ClickBox( vertex(x + inclination, y, 0.0).colorEnd() // Render the box: - val currentHeight = (y + height) + 80.0 + val currentHeight = y + (height + clickboxHeightOffset) vertex(x, currentHeight, 0.0).colorEnd() vertex(x + width + inclination, currentHeight, 0.0).colorEnd() vertex(x + width + inclination, y + height, 0.0).colorEnd() @@ -92,7 +96,7 @@ class ClickBox( y = this@ClickBox.y + this@ClickBox.height + 3 }.display(poseStack) buttons.values.forEachIndexed { num, button -> - val fullHeight = (y + height.toDouble())..(y + height + 80.0) + val fullHeight = (y + height.toDouble())..(y + height + clickboxHeightOffset) button.also { it.x = x + 3 it.y = y + 3 + height + (((num + 1) - barStage) * 9) diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickButton.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickButton.kt index 1c8f798..0d22982 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickButton.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickButton.kt @@ -12,11 +12,12 @@ import net.minecraft.client.gui.components.events.GuiEventListener class ClickButton( x: Double = 0.0, y: Double = 0.0, - width: Int = 73, height: Int = 8, - color: Int, private val kind: Type = Type.TOGGLE, + width: Int = 73, height: Int = 8, getColorFrom: ColoredElement? = null, + private val kind: Type = Type.TOGGLE, private val title: String = "", private val action: (() -> Unit)? = null, -): ColoredElement(x, y, width, height, color, 0.60F), GuiEventListener { +): ColoredElement(x, y, width, height, opacity = 0.60F), GuiEventListener { + override var color: Int = getColorFrom?.color ?: super.color companion object { enum class Type { TOGGLE, diff --git a/common/src/main/kotlin/fr/username404/snowygui/misc/addComponents.kt b/common/src/main/kotlin/fr/username404/snowygui/misc/addComponents.kt index beb9505..338af9f 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/misc/addComponents.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/misc/addComponents.kt @@ -4,22 +4,25 @@ import fr.username404.snowygui.ClickGui import fr.username404.snowygui.newBox import net.minecraft.client.Minecraft -private object Storage { - var oldGamma = -1.0 -} +object Storage { + private var oldGamma = -1.0 + var hurtCamera: Boolean = true; private set -fun ClickGui.addComponents() { - addComps( - newBox("snowy.clickbox.misc").addButtons( - "GammaBoost" to { - with(Minecraft.getInstance().options) { - gamma = if (gamma != 1400.0) { - Storage.oldGamma = gamma - 1400.0 - } else Storage.oldGamma + fun ClickGui.addComponents() { + addComps( + newBox("snowy.clickbox.misc").addButtons( + "GammaBoost" to { + with(Minecraft.getInstance().options) { + gamma = if (gamma != 1400.0) { + oldGamma = gamma + 1400.0 + } else oldGamma + } } - } - ), - newBox("snowy.clickbox.rendering").addButtons() - ) + ), + newBox("snowy.clickbox.risky", color = 0x660000).addButtons( + "NoHurtCamera" to { hurtCamera = !hurtCamera } + ), + ) + } } \ No newline at end of file diff --git a/common/src/main/resources/assets/snowygui/lang/en_us.json b/common/src/main/resources/assets/snowygui/lang/en_us.json index 95dab0e..ea14405 100644 --- a/common/src/main/resources/assets/snowygui/lang/en_us.json +++ b/common/src/main/resources/assets/snowygui/lang/en_us.json @@ -5,5 +5,5 @@ "key.snowy.opengui": "Open the snowy gui", "key.snowy.configkey": "Open the snowy configuration screen", "snowy.clickbox.misc": "Miscellaneous", - "snowy.clickbox.rendering": "Rendering" + "snowy.clickbox.risky": "Risky" } \ No newline at end of file diff --git a/common/src/main/resources/assets/snowygui/lang/fr_fr.json b/common/src/main/resources/assets/snowygui/lang/fr_fr.json index 14293fc..008f257 100644 --- a/common/src/main/resources/assets/snowygui/lang/fr_fr.json +++ b/common/src/main/resources/assets/snowygui/lang/fr_fr.json @@ -5,5 +5,5 @@ "key.snowy.opengui": "Ouvrir l'interface de snowy", "key.snowy.configkey": "Ouvrir l'écran de configuration de snowy", "snowy.clickbox.misc": "Divers", - "snowy.clickbox.rendering": "Rendu" + "snowy.clickbox.risky": "Risqué" } \ No newline at end of file diff --git a/common/src/main/resources/snowygui-mixins.json b/common/src/main/resources/snowygui-mixins.json index 6b8c6ca..1fe9d0c 100644 --- a/common/src/main/resources/snowygui-mixins.json +++ b/common/src/main/resources/snowygui-mixins.json @@ -6,7 +6,8 @@ "KeysAccessor", "KeyMappings", "EndTickMixin", - "TitleScreenMixin" + "TitleScreenMixin", + "RendererMixin" ], "injectors": { "defaultRequire": 1