Remove the "Rendering" clickbox and replace it with a "Risky" one; add a nohurtcam feature
This commit is contained in:
parent
88f097be01
commit
ca70cc7fb1
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,12 +4,12 @@ import fr.username404.snowygui.gui.Element
|
||||||
import fr.username404.snowygui.gui.SnowyScreen
|
import fr.username404.snowygui.gui.SnowyScreen
|
||||||
import fr.username404.snowygui.gui.elements.ClickBox
|
import fr.username404.snowygui.gui.elements.ClickBox
|
||||||
import fr.username404.snowygui.gui.elements.ClickButton
|
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
|
import net.minecraft.network.chat.TranslatableComponent
|
||||||
|
|
||||||
private var baseXAxis: Double = 4.0
|
private var baseXAxis: Double = 4.0
|
||||||
internal fun newBox(translationKey: String): ClickBox {
|
internal fun newBox(translationKey: String, color: Int = 0x6C9E9D): ClickBox {
|
||||||
val result = ClickBox(baseXAxis, 4.0, TranslatableComponent(translationKey))
|
val result = ClickBox(baseXAxis, 4.0, name = TranslatableComponent(translationKey), color = color)
|
||||||
baseXAxis += 86
|
baseXAxis += 86
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ object ClickGui: SnowyScreen() {
|
||||||
private inline fun buttonsContext(args: (ClickButton) -> Unit) = boxContext { it.buttons.values.forEach(args) }
|
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 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 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 {
|
override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
components.forEach {
|
components.forEach {
|
||||||
|
|
|
@ -28,8 +28,8 @@ abstract class Element(
|
||||||
): Renderable {
|
): Renderable {
|
||||||
open var width = originalWidth; open var height = originalHeight
|
open var width = originalWidth; open var height = originalHeight
|
||||||
open var x = xOrigin; open var y = yOrigin
|
open var x = xOrigin; open var y = yOrigin
|
||||||
internal fun withinBounds(coordinateX: Double, coordinateY: Double): Boolean =
|
internal fun withinBounds(coordinateX: Double, coordinateY: Double, offsetWidth: Double = 0.0, offsetHeight: Double = 0.0): Boolean =
|
||||||
((coordinateX >= this.x) && (coordinateX <= (this.x + this.width))) and ((coordinateY >= this.y) && (coordinateY <= (this.y + this.height)))
|
((coordinateX >= this.x) && (coordinateX <= (this.x + this.width + offsetWidth))) and ((coordinateY >= this.y) && (coordinateY <= (this.y + this.height + offsetHeight)))
|
||||||
companion object {
|
companion object {
|
||||||
private var caughtError: Boolean = false
|
private var caughtError: Boolean = false
|
||||||
fun fromRenderable(r: Renderable, x: Double, y: Double, width: Int, height: Int): Element {
|
fun fromRenderable(r: Renderable, x: Double, y: Double, width: Int, height: Int): Element {
|
||||||
|
@ -55,8 +55,9 @@ abstract class Element(
|
||||||
|
|
||||||
abstract class ColoredElement(
|
abstract class ColoredElement(
|
||||||
x: Double, y: Double, width: Int, height: Int,
|
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) {
|
) : Element(x, y, width, height) {
|
||||||
|
open var color = color; protected set
|
||||||
companion object {
|
companion object {
|
||||||
const val TransparentColor: Int = -0x1
|
const val TransparentColor: Int = -0x1
|
||||||
@JvmStatic protected fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer {
|
@JvmStatic protected fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer {
|
||||||
|
|
|
@ -14,15 +14,17 @@ import net.minecraft.client.Minecraft
|
||||||
import net.minecraft.network.chat.TranslatableComponent
|
import net.minecraft.network.chat.TranslatableComponent
|
||||||
import org.lwjgl.opengl.GL20
|
import org.lwjgl.opengl.GL20
|
||||||
|
|
||||||
|
const val clickboxHeightOffset: Int = 80
|
||||||
class ClickBox(
|
class ClickBox(
|
||||||
x: Double, y: Double,
|
x: Double, y: Double,
|
||||||
|
color: Int = 0x6C9E9D,
|
||||||
private val name: TranslatableComponent? = null
|
private val name: TranslatableComponent? = null
|
||||||
): ColoredElement(x, y, 80, 10, 0x6C9E9D, 0.5F) {
|
): ColoredElement(x, y, 80, 10, color, 0.5F) {
|
||||||
val buttons = mutableMapOf<String, ClickButton>() // Can contain up to 16 buttons
|
val buttons = mutableMapOf<String, ClickButton>() // Can contain up to 16 buttons
|
||||||
fun addButtons(vararg collect: Pair<String, (() -> Unit)?>, color: Int = 0x6C9E9D, kind: Type = Type.TOGGLE): ClickBox {
|
fun addButtons(vararg collect: Pair<String, (() -> Unit)?>, kind: Type = Type.TOGGLE): ClickBox {
|
||||||
buttons.putAll(
|
buttons.putAll(
|
||||||
collect.map {
|
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
|
return this
|
||||||
|
@ -30,7 +32,7 @@ class ClickBox(
|
||||||
@JvmField
|
@JvmField
|
||||||
val buttonsProgressBar: ColoredElement = object: ColoredElement(
|
val buttonsProgressBar: ColoredElement = object: ColoredElement(
|
||||||
(x + width), y + height + 3,
|
(x + width), y + height + 3,
|
||||||
color = color, width = 3, height = 74,
|
color = color, width = 3, height = clickboxHeightOffset - 6,
|
||||||
opacity = 0.75F
|
opacity = 0.75F
|
||||||
) {
|
) {
|
||||||
override fun render(poseStack: PoseStack?) {
|
override fun render(poseStack: PoseStack?) {
|
||||||
|
@ -44,12 +46,14 @@ class ClickBox(
|
||||||
init { height = 8 }
|
init { height = 8 }
|
||||||
}
|
}
|
||||||
var barStage: Int = 1; private set
|
var barStage: Int = 1; private set
|
||||||
fun scroll(supplied: Double) {
|
fun scroll(d: Double, e: Double, supplied: Double) {
|
||||||
with(buttonsProgressBar) {
|
if (withinBounds(d, e, offsetHeight = clickboxHeightOffset.toDouble())) {
|
||||||
if ((height != 8 || (supplied < 0)) && ((height != originalHeight) || (supplied > 0))) {
|
with(buttonsProgressBar) {
|
||||||
height -= supplied.toInt()
|
if ((height != 8 || (supplied < 0)) && ((height != originalHeight) || (supplied > 0))) {
|
||||||
if (buttons.isNotEmpty()) (height / 8).let {
|
height -= supplied.toInt()
|
||||||
if (it > 0) barStage = it
|
if (buttons.isNotEmpty()) (height / 8).let {
|
||||||
|
if (it > 0) barStage = it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +76,7 @@ class ClickBox(
|
||||||
vertex(x + inclination, y, 0.0).colorEnd()
|
vertex(x + inclination, y, 0.0).colorEnd()
|
||||||
|
|
||||||
// Render the box:
|
// Render the box:
|
||||||
val currentHeight = (y + height) + 80.0
|
val currentHeight = y + (height + clickboxHeightOffset)
|
||||||
vertex(x, currentHeight, 0.0).colorEnd()
|
vertex(x, currentHeight, 0.0).colorEnd()
|
||||||
vertex(x + width + inclination, currentHeight, 0.0).colorEnd()
|
vertex(x + width + inclination, currentHeight, 0.0).colorEnd()
|
||||||
vertex(x + width + inclination, y + height, 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
|
y = this@ClickBox.y + this@ClickBox.height + 3
|
||||||
}.display(poseStack)
|
}.display(poseStack)
|
||||||
buttons.values.forEachIndexed { num, button ->
|
buttons.values.forEachIndexed { num, button ->
|
||||||
val fullHeight = (y + height.toDouble())..(y + height + 80.0)
|
val fullHeight = (y + height.toDouble())..(y + height + clickboxHeightOffset)
|
||||||
button.also {
|
button.also {
|
||||||
it.x = x + 3
|
it.x = x + 3
|
||||||
it.y = y + 3 + height + (((num + 1) - barStage) * 9)
|
it.y = y + 3 + height + (((num + 1) - barStage) * 9)
|
||||||
|
|
|
@ -12,11 +12,12 @@ import net.minecraft.client.gui.components.events.GuiEventListener
|
||||||
|
|
||||||
class ClickButton(
|
class ClickButton(
|
||||||
x: Double = 0.0, y: Double = 0.0,
|
x: Double = 0.0, y: Double = 0.0,
|
||||||
width: Int = 73, height: Int = 8,
|
width: Int = 73, height: Int = 8, getColorFrom: ColoredElement? = null,
|
||||||
color: Int, private val kind: Type = Type.TOGGLE,
|
private val kind: Type = Type.TOGGLE,
|
||||||
private val title: String = "",
|
private val title: String = "",
|
||||||
private val action: (() -> Unit)? = null,
|
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 {
|
companion object {
|
||||||
enum class Type {
|
enum class Type {
|
||||||
TOGGLE,
|
TOGGLE,
|
||||||
|
|
|
@ -4,22 +4,25 @@ import fr.username404.snowygui.ClickGui
|
||||||
import fr.username404.snowygui.newBox
|
import fr.username404.snowygui.newBox
|
||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
|
|
||||||
private object Storage {
|
object Storage {
|
||||||
var oldGamma = -1.0
|
private var oldGamma = -1.0
|
||||||
}
|
var hurtCamera: Boolean = true; private set
|
||||||
|
|
||||||
fun ClickGui.addComponents() {
|
fun ClickGui.addComponents() {
|
||||||
addComps(
|
addComps(
|
||||||
newBox("snowy.clickbox.misc").addButtons(
|
newBox("snowy.clickbox.misc").addButtons(
|
||||||
"GammaBoost" to {
|
"GammaBoost" to {
|
||||||
with(Minecraft.getInstance().options) {
|
with(Minecraft.getInstance().options) {
|
||||||
gamma = if (gamma != 1400.0) {
|
gamma = if (gamma != 1400.0) {
|
||||||
Storage.oldGamma = gamma
|
oldGamma = gamma
|
||||||
1400.0
|
1400.0
|
||||||
} else Storage.oldGamma
|
} else oldGamma
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
),
|
||||||
),
|
newBox("snowy.clickbox.risky", color = 0x660000).addButtons(
|
||||||
newBox("snowy.clickbox.rendering").addButtons()
|
"NoHurtCamera" to { hurtCamera = !hurtCamera }
|
||||||
)
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -5,5 +5,5 @@
|
||||||
"key.snowy.opengui": "Open the snowy gui",
|
"key.snowy.opengui": "Open the snowy gui",
|
||||||
"key.snowy.configkey": "Open the snowy configuration screen",
|
"key.snowy.configkey": "Open the snowy configuration screen",
|
||||||
"snowy.clickbox.misc": "Miscellaneous",
|
"snowy.clickbox.misc": "Miscellaneous",
|
||||||
"snowy.clickbox.rendering": "Rendering"
|
"snowy.clickbox.risky": "Risky"
|
||||||
}
|
}
|
|
@ -5,5 +5,5 @@
|
||||||
"key.snowy.opengui": "Ouvrir l'interface de snowy",
|
"key.snowy.opengui": "Ouvrir l'interface de snowy",
|
||||||
"key.snowy.configkey": "Ouvrir l'écran de configuration de snowy",
|
"key.snowy.configkey": "Ouvrir l'écran de configuration de snowy",
|
||||||
"snowy.clickbox.misc": "Divers",
|
"snowy.clickbox.misc": "Divers",
|
||||||
"snowy.clickbox.rendering": "Rendu"
|
"snowy.clickbox.risky": "Risqué"
|
||||||
}
|
}
|
|
@ -6,7 +6,8 @@
|
||||||
"KeysAccessor",
|
"KeysAccessor",
|
||||||
"KeyMappings",
|
"KeyMappings",
|
||||||
"EndTickMixin",
|
"EndTickMixin",
|
||||||
"TitleScreenMixin"
|
"TitleScreenMixin",
|
||||||
|
"RendererMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|
Loading…
Reference in New Issue