feat: added player fly speed controls

Signed-off-by: moonleay <contact@moonleay.net>
This commit is contained in:
moonleay 2024-05-17 01:10:54 +02:00
parent 6a89e5683f
commit 42737446b2
Signed by: moonleay
GPG key ID: 82667543CCD715FB
7 changed files with 70 additions and 13 deletions

View file

@ -25,5 +25,5 @@ import net.moonleay.gimbal.client.config.enums.ToastSettings
data class GimbalClientConfig(
val guiSettings: GimbalGuiSettings = GimbalGuiSettings(),
val toastSettings: ToastSettings = ToastSettings.ALL,
val playerFlySpeed: Int = 0,
val playerFlySpeed: Int = 100,
)

View file

@ -22,6 +22,6 @@ import kotlinx.serialization.Serializable
@Serializable
data class ScaledRes(
val scaledX: Double,
val scaledY: Double,
val scaledX: Double, // offsetX
val scaledY: Double, // offsetY
)

View file

@ -185,11 +185,15 @@ class GimbalSettingsGui(private val parent: Screen, private val cfg: ClientConfi
150,
20,
Text.translatable(TranslationKeys.Gui.Config.PLAYER_FLY_SPEED),
NumberUtil.interpolate(this.playerFlySpeed.toDouble(), 50.0, 500.0, 0.0, 1.0),
50.0,
500.0,
NumberUtil.linearInterpolate(this.playerFlySpeed.toDouble(), 100.0, 1000.0, 0.0, 1.0),
100.0,
1000.0,
) { value ->
this.playerFlySpeed = NumberUtil.interpolate(value, 0.0, 1.0, 50.0, 500.0).toInt()
this.playerFlySpeed = NumberUtil.linearInterpolate(value, 0.0, 1.0, 100.0, 1000.0).toInt()
if (client!!.player != null && client!!.player!!.isCreative) {
client!!.player!!.abilities.flySpeed = (this.playerFlySpeed / 100) * 0.05f
}
val oldConfig = cfg.config
val newConfig = GimbalClientConfig(

View file

@ -36,12 +36,12 @@ class GimbalSliderWidget(
SliderWidget(x, y, width, height, text, value) {
init {
this.message = this.text.copy()
.append(": " + (NumberUtil.interpolate(this.value, 0.0, 1.0, this.lowerEnd, this.upperEnd).toInt()))
.append(": " + (NumberUtil.linearInterpolate(this.value, 0.0, 1.0, this.lowerEnd, this.upperEnd).toInt()))
}
override fun updateMessage() {
this.message = this.text.copy()
.append(": " + (NumberUtil.interpolate(this.value, 0.0, 1.0, this.lowerEnd, this.upperEnd).toInt()))
.append(": " + (NumberUtil.linearInterpolate(this.value, 0.0, 1.0, this.lowerEnd, this.upperEnd).toInt()))
}
override fun applyValue() {

View file

@ -21,17 +21,24 @@ package net.moonleay.gimbal.client.util
object NumberUtil {
/**
* Interpolate a Position between two numbers
* Interpolate a number between two numbers in a linear way
*/
fun interpolate(number: Double, min: Double, max: Double, lowerEnd: Double, upperEnd: Double): Double {
val toAddToMin = (0 - min) * -1
fun linearInterpolate(number: Double, min: Double, max: Double, lowerEnd: Double, upperEnd: Double): Double {
val subtractFromNr = (0 - min) * -1
val minMaxDiff = max - min
val onePercent = minMaxDiff / 100.0
val percentOfNumber = (number - toAddToMin) / onePercent
val percentOfNumber = (number - subtractFromNr) / onePercent
val toAddToLowerEnd = (0 - lowerEnd) * -1
val upperLowerDiff = upperEnd - lowerEnd
val onePercentOfEnd = upperLowerDiff / 100.0
return (percentOfNumber * onePercentOfEnd) + toAddToLowerEnd
}
/**
* Interpolate a number between two numbers in a logarithmic way
*/
fun logarithmicInterpolate(number: Double, min: Double, max: Double, lowerEnd: Double, upperEnd: Double): Double {
TODO("Not impl.")
}
}

View file

@ -0,0 +1,45 @@
/*
* Gimbal
* Copyright (C) 2024 moonleay
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.moonleay.gimbal.mixin;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.packet.s2c.play.PlayerAbilitiesS2CPacket;
import net.moonleay.gimbal.client.ClientMain;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ClientPlayNetworkHandler.class)
public abstract class PlayerFlySpeedMixin {
@Shadow
@Final
private MinecraftClient client;
@Inject(method = "onPlayerAbilities", at = @At(value = "RETURN"))
private void func(PlayerAbilitiesS2CPacket packet, CallbackInfo ci) {
this.client.player.getAbilities().setFlySpeed((ClientMain.CONFIG.getConfig().getPlayerFlySpeed() / 100) * 0.05f);
//client!!.player!!.abilities.flySpeed = (this.playerFlySpeed / 100) * 0.05f
}
}

View file

@ -16,6 +16,7 @@
"HudMixin",
"NoClipMixin$CameraMixin",
"NormalModeMixin",
"PlayerFlySpeedMixin",
"YouInjectButtonMixin$GameMenuScreenMixin",
"YouInjectButtonMixin$TitleScreenMixin"
],