From 6f1e41eec899599788499bbed849f117a3291b45 Mon Sep 17 00:00:00 2001 From: ccetl Date: Sun, 15 Sep 2024 11:38:38 +0200 Subject: [PATCH 1/3] feat: module zoom --- .../mixins/minecraft/client/MixinMouse.java | 25 ++++- .../minecraft/render/MixinGameRenderer.java | 14 ++- .../interfaces/ChatHudLineAddition.java | 2 +- .../liquidbounce/event/EventManager.kt | 3 +- .../liquidbounce/event/events/WindowEvents.kt | 4 + .../features/module/ModuleManager.kt | 1 + .../module/modules/render/ModuleZoom.kt | 104 ++++++++++++++++++ .../liquidbounce/render/RenderShortcuts.kt | 2 - .../assets/liquidbounce/lang/en_us.json | 1 + 9 files changed, 147 insertions(+), 9 deletions(-) create mode 100644 src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleZoom.kt diff --git a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/client/MixinMouse.java b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/client/MixinMouse.java index 7f0be6ddd85..90c92c05b53 100644 --- a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/client/MixinMouse.java +++ b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/client/MixinMouse.java @@ -19,11 +19,11 @@ package net.ccbluex.liquidbounce.injection.mixins.minecraft.client; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.sugar.Local; import net.ccbluex.liquidbounce.event.EventManager; -import net.ccbluex.liquidbounce.event.events.MouseButtonEvent; -import net.ccbluex.liquidbounce.event.events.MouseCursorEvent; -import net.ccbluex.liquidbounce.event.events.MouseRotationEvent; -import net.ccbluex.liquidbounce.event.events.MouseScrollEvent; +import net.ccbluex.liquidbounce.event.events.*; +import net.ccbluex.liquidbounce.features.module.modules.render.ModuleZoom; import net.minecraft.client.Mouse; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -51,6 +51,13 @@ private void hookMouseScroll(long window, double horizontal, double vertical, Ca EventManager.INSTANCE.callEvent(new MouseScrollEvent(horizontal, vertical)); } + @Inject(method = "onMouseScroll", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSpectator()Z", shift = At.Shift.BEFORE), cancellable = true) + private void hookMouseScroll(long window, double horizontal, double vertical, CallbackInfo ci, @Local(ordinal = 2) int k) { + if (EventManager.INSTANCE.callEvent(new MouseScrollInHotbarEvent(k)).isCancelled()) { + ci.cancel(); + } + } + /** * Hook mouse cursor event */ @@ -59,6 +66,16 @@ private void hookCursorPos(long window, double x, double y, CallbackInfo callbac EventManager.INSTANCE.callEvent(new MouseCursorEvent(x, y)); } + @ModifyExpressionValue(method = "updateMouse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/Perspective;isFirstPerson()Z")) + private boolean injectZoomCondition1(boolean original) { + return original || ModuleZoom.INSTANCE.getEnabled(); + } + + @ModifyExpressionValue(method = "updateMouse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingSpyglass()Z")) + private boolean injectZoomCondition2(boolean original) { + return original || ModuleZoom.INSTANCE.getEnabled(); + } + /** * Hook mouse cursor event */ diff --git a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/render/MixinGameRenderer.java b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/render/MixinGameRenderer.java index 4e97a6043f9..062bcd70d9a 100644 --- a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/render/MixinGameRenderer.java +++ b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/render/MixinGameRenderer.java @@ -16,7 +16,6 @@ * You should have received a copy of the GNU General Public License * along with LiquidBounce. If not, see . */ - package net.ccbluex.liquidbounce.injection.mixins.minecraft.render; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; @@ -246,4 +245,17 @@ private void hookShowFloatingItem(ItemStack floatingItem, CallbackInfo ci) { } } + @ModifyExpressionValue(method = "getFov", at = @At(value = "INVOKE", target = "Ljava/lang/Integer;intValue()I", remap = false)) + private int hookGetFov(int original) { + int result; + + if (ModuleZoom.INSTANCE.getEnabled()) { + return ModuleZoom.INSTANCE.getFov(true, 0); + } else { + result = ModuleZoom.INSTANCE.getFov(false, original); + } + + return result; + } + } diff --git a/src/main/java/net/ccbluex/liquidbounce/interfaces/ChatHudLineAddition.java b/src/main/java/net/ccbluex/liquidbounce/interfaces/ChatHudLineAddition.java index a51a591d317..bf96b7119d3 100644 --- a/src/main/java/net/ccbluex/liquidbounce/interfaces/ChatHudLineAddition.java +++ b/src/main/java/net/ccbluex/liquidbounce/interfaces/ChatHudLineAddition.java @@ -26,7 +26,7 @@ public interface ChatHudLineAddition { /** * Sets the count of the message. * This indicates how many times this massage has already been sent in - * {@link net.ccbluex.liquidbounce.features.module.modules.misc.ModuleBetterChat}. + * {@link net.ccbluex.liquidbounce.features.module.modules.misc.betterchat.ModuleBetterChat}. */ void liquid_bounce$setCount(int count); diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt b/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt index c4992818cb7..9f88f557d7d 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt @@ -120,7 +120,8 @@ val ALL_EVENT_CLASSES: Array> = arrayOf( SpaceSeperatedNamesChangeEvent::class, ClickGuiScaleChangeEvent::class, BrowserUrlChangeEvent::class, - TagEntityEvent::class + TagEntityEvent::class, + MouseScrollInHotbarEvent::class ) /** diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/event/events/WindowEvents.kt b/src/main/kotlin/net/ccbluex/liquidbounce/event/events/WindowEvents.kt index 511714b729f..1f0a7d30c13 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/event/events/WindowEvents.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/event/events/WindowEvents.kt @@ -20,6 +20,7 @@ package net.ccbluex.liquidbounce.event.events +import net.ccbluex.liquidbounce.event.CancellableEvent import net.ccbluex.liquidbounce.event.Event import net.ccbluex.liquidbounce.utils.client.Nameable import net.ccbluex.liquidbounce.web.socket.protocol.event.WebSocketEvent @@ -40,6 +41,9 @@ class MouseButtonEvent(val button: Int, val action: Int, val mods: Int) : Event( @WebSocketEvent class MouseScrollEvent(val horizontal: Double, val vertical: Double) : Event() +@Nameable("mouseScrollInHotbar") +class MouseScrollInHotbarEvent(val speed: Int) : CancellableEvent() + @Nameable("mouseCursor") @WebSocketEvent class MouseCursorEvent(val x: Double, val y: Double) : Event() diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/ModuleManager.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/ModuleManager.kt index 94c6278498d..41d6c041712 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/ModuleManager.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/ModuleManager.kt @@ -268,6 +268,7 @@ object ModuleManager : Listenable, Iterable by modules { ModuleTrueSight, ModuleXRay, ModuleDebug, + ModuleZoom, // World ModuleAutoDisable, diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleZoom.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleZoom.kt new file mode 100644 index 00000000000..074c589662f --- /dev/null +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleZoom.kt @@ -0,0 +1,104 @@ +/* + * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce) + * + * Copyright (c) 2015 - 2024 CCBlueX + * + * LiquidBounce is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LiquidBounce is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LiquidBounce. If not, see . + */ +package net.ccbluex.liquidbounce.features.module.modules.render + +import net.ccbluex.liquidbounce.config.ToggleableConfigurable +import net.ccbluex.liquidbounce.event.events.MouseScrollInHotbarEvent +import net.ccbluex.liquidbounce.event.handler +import net.ccbluex.liquidbounce.features.module.Category +import net.ccbluex.liquidbounce.features.module.Module +import net.ccbluex.liquidbounce.injection.mixins.minecraft.client.MixinMouse +import net.ccbluex.liquidbounce.utils.client.Chronometer +import net.minecraft.util.math.MathHelper +import kotlin.math.abs +import kotlin.math.round + +/** + * Module Zoom + * + * Allows you to zoom. + * + * The mose is slowed down with the help of mixins in [MixinMouse]. + */ +object ModuleZoom : Module("Zoom", Category.RENDER) { + + val zoom by int("Zoom", 30, 10..150) + + object Scroll : ToggleableConfigurable(this, "Scroll", true) { + + val speed by float("Speed", 2f, 0.5f..8f) + + @Suppress("unused") + val onScroll = handler { + previousFov = getFov(true) + targetFov = (targetFov + round(it.speed * this.speed).toInt()).coerceIn(1..179) + reset() + it.cancelEvent() + } + + } + + init { + tree(Scroll) + } + + private val chronometer = Chronometer() + private var targetFov = 0 + private var previousFov = 0 + private var scaledDifference = 0.0 + private var disableAnimationFinished = true + + override fun enable() { + targetFov = zoom + previousFov = getDefaultFov() + reset() + } + + override fun disable() { + previousFov = getFov(true) + chronometer.reset() + targetFov = getDefaultFov() + reset() + disableAnimationFinished = false + } + + fun getFov(enabled: Boolean, original: Int = 0): Int { + if (!enabled && disableAnimationFinished) { + return original + } + + val factor = (chronometer.elapsed / scaledDifference).toFloat().coerceIn(0F..1F) + if (!enabled && factor == 1f) { + disableAnimationFinished = true + } + + return MathHelper.lerp(factor, previousFov, targetFov) + } + + private fun getDefaultFov(): Int { + val fov = mc.options.fov.value + return if (ModuleNoFov.enabled) ModuleNoFov.getFov(fov) else fov + } + + private fun reset() { + chronometer.reset() + scaledDifference = 2.5 * abs(targetFov - previousFov) + } + +} diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/render/RenderShortcuts.kt b/src/main/kotlin/net/ccbluex/liquidbounce/render/RenderShortcuts.kt index 6ac31f3ff10..08eb4c877ce 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/render/RenderShortcuts.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/render/RenderShortcuts.kt @@ -27,9 +27,7 @@ import net.ccbluex.liquidbounce.render.engine.Vec3 import net.ccbluex.liquidbounce.utils.client.mc import net.minecraft.client.gl.ShaderProgram import net.minecraft.client.render.* -import net.minecraft.client.render.VertexFormat import net.minecraft.client.render.VertexFormat.DrawMode -import net.minecraft.client.render.VertexFormats import net.minecraft.client.util.math.MatrixStack import net.minecraft.util.math.Box import net.minecraft.util.math.Direction diff --git a/src/main/resources/assets/liquidbounce/lang/en_us.json b/src/main/resources/assets/liquidbounce/lang/en_us.json index b0f12e40119..99617606cef 100644 --- a/src/main/resources/assets/liquidbounce/lang/en_us.json +++ b/src/main/resources/assets/liquidbounce/lang/en_us.json @@ -568,6 +568,7 @@ "liquidbounce.module.vehicleOneHit.description": "Allows you to break any vehicle with a single hit.", "liquidbounce.module.velocity.description": "Modifies the amount of velocity you take.", "liquidbounce.module.xRay.description": "Only renders selected blocks.", + "liquidbounce.module.zoom.description": "Allows you to make everything in your world appear smaller or bigger.", "liquidbounce.module.antiHunger.description": "Prevents you from getting hungry.", "liquidbounce.module.antiHunger.messages.warnSprint": "Another module caused sprint packets, which could lead to hunger.", "liquidbounce.module.antiHunger.messages.warnBreak": "You are breaking a block, which could lead to hunger.", From 1ff98a65b9271f03487c40a63234d6deee913489 Mon Sep 17 00:00:00 2001 From: ccetl <109693935+ccetl@users.noreply.github.com> Date: Mon, 16 Sep 2024 16:25:27 +0200 Subject: [PATCH 2/3] Update MixinGameRenderer.java --- .../injection/mixins/minecraft/render/MixinGameRenderer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/render/MixinGameRenderer.java b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/render/MixinGameRenderer.java index 179c197e8e3..7cdb30a9a0d 100644 --- a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/render/MixinGameRenderer.java +++ b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/render/MixinGameRenderer.java @@ -254,8 +254,8 @@ private int hookGetFov(int original) { } else { result = ModuleZoom.INSTANCE.getFov(false, original); } - - if (ModuleNoFov.INSTANCE.getEnabled()) { + + if (ModuleNoFov.INSTANCE.getEnabled() && result == original) { return ModuleNoFov.INSTANCE.getFov(result); } From 3df236d70162c0b432c326b99d6d8c1d31573329 Mon Sep 17 00:00:00 2001 From: ccetl <109693935+ccetl@users.noreply.github.com> Date: Sun, 29 Sep 2024 20:36:04 +0200 Subject: [PATCH 3/3] Update ModuleZoom.kt --- .../liquidbounce/features/module/modules/render/ModuleZoom.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleZoom.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleZoom.kt index 074c589662f..175c34d20ee 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleZoom.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleZoom.kt @@ -36,7 +36,7 @@ import kotlin.math.round * * The mose is slowed down with the help of mixins in [MixinMouse]. */ -object ModuleZoom : Module("Zoom", Category.RENDER) { +object ModuleZoom : Module("Zoom", Category.RENDER, bindAction = BindAction.HOLD) { val zoom by int("Zoom", 30, 10..150)