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.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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<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(
|
||||
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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 }
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
}
|
|
@ -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é"
|
||||
}
|
|
@ -6,7 +6,8 @@
|
|||
"KeysAccessor",
|
||||
"KeyMappings",
|
||||
"EndTickMixin",
|
||||
"TitleScreenMixin"
|
||||
"TitleScreenMixin",
|
||||
"RendererMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Reference in New Issue