diff --git a/common/src/main/java/com/lambda/mixin/world/ClientWorldMixin.java b/common/src/main/java/com/lambda/mixin/world/ClientWorldMixin.java index bc0c91157..9078e475e 100644 --- a/common/src/main/java/com/lambda/mixin/world/ClientWorldMixin.java +++ b/common/src/main/java/com/lambda/mixin/world/ClientWorldMixin.java @@ -3,7 +3,6 @@ import com.lambda.event.EventFlow; import com.lambda.event.events.WorldEvent; import com.lambda.module.modules.render.WorldColors; -import com.lambda.util.math.ColorUtils; import net.minecraft.block.BlockState; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; @@ -32,14 +31,20 @@ private void addEntity(Entity entity, CallbackInfo ci) { @Inject(method = "getCloudsColor", at = @At("HEAD"), cancellable = true) private void getCloudsColorInject(float tickDelta, CallbackInfoReturnable cir) { if (WorldColors.INSTANCE.isEnabled() && WorldColors.getCustomClouds()) { - cir.setReturnValue(ColorUtils.getVec3d(WorldColors.getCloudColor())); + var color = WorldColors.getCloudColor(); + + cir.setReturnValue( + new Vec3d(color.getRed(), color.getGreen(), color.getBlue())); } } @Inject(method = "getSkyColor", at = @At("HEAD"), cancellable = true) private void getSkyColorInject(Vec3d cameraPos, float tickDelta, CallbackInfoReturnable cir) { if (WorldColors.INSTANCE.isEnabled() && WorldColors.getCustomSky()) { - cir.setReturnValue(ColorUtils.getVec3d(WorldColors.getSkyColor())); + var color = WorldColors.getSkyColor(); + + cir.setReturnValue( + new Vec3d(color.getRed(), color.getGreen(), color.getBlue())); } } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/com/lambda/core/registry/AgnosticRegistries.kt b/common/src/main/kotlin/com/lambda/core/registry/AgnosticRegistries.kt index 1b842346f..87658b7c4 100644 --- a/common/src/main/kotlin/com/lambda/core/registry/AgnosticRegistries.kt +++ b/common/src/main/kotlin/com/lambda/core/registry/AgnosticRegistries.kt @@ -1,7 +1,6 @@ package com.lambda.core.registry import com.lambda.util.Communication.warn -import jdk.internal.org.jline.keymap.KeyMap.key import net.minecraft.registry.Registry import net.minecraft.registry.RegistryKey import net.minecraft.registry.entry.RegistryEntry diff --git a/common/src/main/kotlin/com/lambda/graphics/animation/Animation.kt b/common/src/main/kotlin/com/lambda/graphics/animation/Animation.kt index 5d9dfdacc..dbbd88edf 100644 --- a/common/src/main/kotlin/com/lambda/graphics/animation/Animation.kt +++ b/common/src/main/kotlin/com/lambda/graphics/animation/Animation.kt @@ -1,7 +1,7 @@ package com.lambda.graphics.animation import com.lambda.Lambda.mc -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import com.lambda.util.extension.partialTicks import kotlin.math.abs import kotlin.reflect.KProperty @@ -11,7 +11,7 @@ class Animation(initialValue: Double, val update: (Double) -> Double) { private var currValue = initialValue operator fun getValue(thisRef: Any?, property: KProperty<*>) = - lerp(prevValue, currValue, mc.partialTicks) + lerp(mc.partialTicks, prevValue, currValue) operator fun setValue(thisRef: Any?, property: KProperty<*>, valueIn: Double) = setValue(valueIn) @@ -38,7 +38,6 @@ class Animation(initialValue: Double, val update: (Double) -> Double) { fun AnimationTicker.exp(target: () -> Double, speed: Double) = exp(target, target, { speed }, { true }) - @Suppress("NAME_SHADOWING") fun AnimationTicker.exp(min: () -> Double, max: () -> Double, speed: () -> Double, flag: () -> Boolean) = Animation(min()) { val min = min() @@ -46,7 +45,7 @@ class Animation(initialValue: Double, val update: (Double) -> Double) { val target = if (flag()) max else min if (abs(target - it) < CLAMP * abs(max - min)) target - else lerp(it, target, speed()) + else lerp(speed(), it, target) }.apply(::register) // Exponent animation never reaches target value diff --git a/common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/FontRenderer.kt b/common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/FontRenderer.kt index 1155946ad..a4fc18e1f 100644 --- a/common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/FontRenderer.kt +++ b/common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/FontRenderer.kt @@ -7,9 +7,9 @@ import com.lambda.graphics.renderer.gui.font.glyph.GlyphInfo import com.lambda.graphics.shader.Shader import com.lambda.module.modules.client.LambdaMoji import com.lambda.module.modules.client.RenderSettings -import com.lambda.util.math.ColorUtils.a -import com.lambda.util.math.ColorUtils.setAlpha import com.lambda.util.math.Vec2d +import com.lambda.util.math.a +import com.lambda.util.math.setAlpha import java.awt.Color class FontRenderer( diff --git a/common/src/main/kotlin/com/lambda/graphics/renderer/gui/rect/OutlineRectRenderer.kt b/common/src/main/kotlin/com/lambda/graphics/renderer/gui/rect/OutlineRectRenderer.kt index 84aa4ed88..3405a26fc 100644 --- a/common/src/main/kotlin/com/lambda/graphics/renderer/gui/rect/OutlineRectRenderer.kt +++ b/common/src/main/kotlin/com/lambda/graphics/renderer/gui/rect/OutlineRectRenderer.kt @@ -3,7 +3,7 @@ package com.lambda.graphics.renderer.gui.rect import com.lambda.graphics.buffer.vao.IRenderContext import com.lambda.graphics.buffer.vao.vertex.VertexAttrib import com.lambda.graphics.shader.Shader -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import com.lambda.util.math.MathUtils.toInt import com.lambda.util.math.MathUtils.toRadian import com.lambda.util.math.Rect @@ -53,7 +53,7 @@ class OutlineRectRenderer : AbstractRectRenderer( val min = angleRange.first.toDouble() val max = angleRange.last.toDouble() val p = it.toDouble() / quality - val angle = lerp(min, max, p).toRadian() + val angle = lerp(p, min, max).toRadian() val pos = base + Vec2d(cos(angle), -sin(angle)) * round val s = shade.toInt().toDouble() @@ -91,4 +91,4 @@ class OutlineRectRenderer : AbstractRectRenderer( companion object { private val shader = Shader("renderer/rect_outline") } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/com/lambda/gui/api/component/WindowComponent.kt b/common/src/main/kotlin/com/lambda/gui/api/component/WindowComponent.kt index 7cf4c0044..1f965c2e5 100644 --- a/common/src/main/kotlin/com/lambda/gui/api/component/WindowComponent.kt +++ b/common/src/main/kotlin/com/lambda/gui/api/component/WindowComponent.kt @@ -12,12 +12,12 @@ import com.lambda.module.modules.client.ClickGui import com.lambda.module.modules.client.GuiSettings import com.lambda.module.modules.client.GuiSettings.primaryColor import com.lambda.util.Mouse -import com.lambda.util.math.ColorUtils.multAlpha -import com.lambda.util.math.ColorUtils.setAlpha -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import com.lambda.util.math.MathUtils.toInt import com.lambda.util.math.Rect import com.lambda.util.math.Vec2d +import com.lambda.util.math.multAlpha +import com.lambda.util.math.setAlpha import java.awt.Color import kotlin.math.abs @@ -64,7 +64,7 @@ abstract class WindowComponent( private val animation = gui.animation private val showAnimation by animation.exp(0.0, 1.0, 0.6, ::isOpen) - override val childShowAnimation get() = lerp(0.0, showAnimation, gui.childShowAnimation) + override val childShowAnimation get() = lerp(gui.childShowAnimation, 0.0, showAnimation) private val actualHeight get() = height + padding * 2 * isOpen.toInt() private var renderHeightAnimation by animation.exp({ 0.0 }, ::actualHeight, 0.6, ::isOpen) diff --git a/common/src/main/kotlin/com/lambda/gui/api/component/button/ButtonComponent.kt b/common/src/main/kotlin/com/lambda/gui/api/component/button/ButtonComponent.kt index b89bbb7ca..acf08a6c7 100644 --- a/common/src/main/kotlin/com/lambda/gui/api/component/button/ButtonComponent.kt +++ b/common/src/main/kotlin/com/lambda/gui/api/component/button/ButtonComponent.kt @@ -9,10 +9,10 @@ import com.lambda.module.modules.client.GuiSettings import com.lambda.sound.LambdaSound import com.lambda.sound.SoundManager.playSoundRandomly import com.lambda.util.Mouse -import com.lambda.util.math.ColorUtils.multAlpha -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import com.lambda.util.math.Rect import com.lambda.util.math.Vec2d +import com.lambda.util.math.multAlpha import java.awt.Color abstract class ButtonComponent( @@ -22,7 +22,7 @@ abstract class ButtonComponent( abstract val size: Vec2d abstract val text: String - protected open val textColor get() = lerp(Color.WHITE, GuiSettings.mainColor, activeAnimation).multAlpha(showAnimation) + protected open val textColor get() = lerp(activeAnimation, Color.WHITE, GuiSettings.mainColor).multAlpha(showAnimation) protected open val centerText = false protected abstract var activeAnimation: Double @@ -37,7 +37,7 @@ abstract class ButtonComponent( private var hoverRectAnimation by animation.exp({ 0.0 }, { 1.0 }, { if (renderHovered) 0.6 else 0.07 }, ::renderHovered) protected var hoverFontAnimation by animation.exp(0.0, 1.0, 0.5, ::renderHovered) protected var pressAnimation by animation.exp(0.0, 1.0, 0.5) { activeButton != null } - protected val interactAnimation get() = lerp(hoverRectAnimation, 1.5, pressAnimation) * 0.4 + protected val interactAnimation get() = lerp(pressAnimation, hoverRectAnimation, 1.5) * 0.4 override val childShowAnimation: Double get() = owner.childShowAnimation protected open val showAnimation get() = owner.childShowAnimation @@ -45,7 +45,7 @@ abstract class ButtonComponent( private val renderHovered get() = hovered || System.currentTimeMillis() - lastHoveredTime < 110 // Removes button shrinking if there's no space between buttons - protected val shrinkAnimation get() = lerp(0.0, interactAnimation, ClickGui.buttonStep) + protected val shrinkAnimation get() = lerp(ClickGui.buttonStep, 0.0, interactAnimation) open fun performClickAction(e: GuiEvent.MouseClick) {} diff --git a/common/src/main/kotlin/com/lambda/gui/api/component/button/InputBarOverlay.kt b/common/src/main/kotlin/com/lambda/gui/api/component/button/InputBarOverlay.kt index 1cc6a8509..f96f0d888 100644 --- a/common/src/main/kotlin/com/lambda/gui/api/component/button/InputBarOverlay.kt +++ b/common/src/main/kotlin/com/lambda/gui/api/component/button/InputBarOverlay.kt @@ -7,11 +7,11 @@ import com.lambda.gui.api.component.core.list.ChildComponent import com.lambda.gui.api.component.core.list.ChildLayer import com.lambda.module.modules.client.ClickGui import com.lambda.util.KeyCode -import com.lambda.util.math.ColorUtils.multAlpha -import com.lambda.util.math.ColorUtils.setAlpha -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import com.lambda.util.math.Rect import com.lambda.util.math.Vec2d +import com.lambda.util.math.multAlpha +import com.lambda.util.math.setAlpha import java.awt.Color import kotlin.math.abs @@ -51,19 +51,19 @@ abstract class InputBarOverlay (val renderer: RenderLayer, owner: ChildLayer.Dra // Value text renderer.font.apply { val text = getText() - val scale = lerp(0.5, 1.0, 1.0 - activeAnimation) + val scale = lerp(1.0 - activeAnimation, 0.5, 1.0) val position = Vec2d(rect.right, rect.center.y) - Vec2d(ClickGui.windowPadding + getWidth(text, scale), 0.0) - val color = Color.WHITE.setAlpha(lerp(0.0, 1.0 - activeAnimation, showAnimation)) + val color = Color.WHITE.setAlpha(lerp(showAnimation, 0.0, 1.0 - activeAnimation)) build(text, position, color, scale) } val textStartX = rect.left + ClickGui.windowPadding + interactAnimation + hoverFontAnimation - val textColor = Color.WHITE.setAlpha(lerp(0.0, activeAnimation, showAnimation)) + val textColor = Color.WHITE.setAlpha(lerp(showAnimation, 0.0, activeAnimation)) // Typing field renderer.font.apply { - val scale = lerp(0.5, 1.0, activeAnimation) - pressAnimation * 0.08 + val scale = lerp(activeAnimation, 0.5, 1.0) - pressAnimation * 0.08 val position = Vec2d(textStartX, rect.center.y) targetOffset = getWidth(typed, scale) @@ -72,12 +72,12 @@ abstract class InputBarOverlay (val renderer: RenderLayer, owner: ChildLayer.Dra // Separator renderer.filled.apply { - val shrink = lerp(rect.size.y * 0.5, 2 + abs(typeAnimation), activeAnimation) + val shrink = lerp(activeAnimation, rect.size.y * 0.5, 2 + abs(typeAnimation)) val rect = Rect( Vec2d(0.0, rect.top + shrink), Vec2d(1.0, rect.bottom - shrink) - ) + Vec2d(lerp(rect.right, textStartX + offset + 2, activeAnimation), 0.0) + ) + Vec2d(lerp(activeAnimation, rect.right, textStartX + offset + 2), 0.0) build(rect, color = textColor.multAlpha(0.8)) } @@ -125,4 +125,4 @@ abstract class InputBarOverlay (val renderer: RenderLayer, owner: ChildLayer.Dra isActive = !isActive if (isActive) typed = getText().filter { isCharAllowed("", it) } } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/com/lambda/gui/api/component/button/ListButton.kt b/common/src/main/kotlin/com/lambda/gui/api/component/button/ListButton.kt index b66d8443d..b040a232b 100644 --- a/common/src/main/kotlin/com/lambda/gui/api/component/button/ListButton.kt +++ b/common/src/main/kotlin/com/lambda/gui/api/component/button/ListButton.kt @@ -4,11 +4,11 @@ import com.lambda.graphics.animation.Animation.Companion.exp import com.lambda.gui.api.GuiEvent import com.lambda.gui.api.component.core.list.ChildLayer import com.lambda.module.modules.client.ClickGui -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import com.lambda.util.math.Vec2d abstract class ListButton(owner: ChildLayer.Drawable<*, *>) : ButtonComponent(owner) { - override val position get() = Vec2d(0.0, lerp(0.0, renderHeightOffset, owner.childShowAnimation)) + override val position get() = Vec2d(0.0, lerp(owner.childShowAnimation, 0.0, renderHeightOffset)) override val size get() = Vec2d(FILL_PARENT, ClickGui.buttonHeight) open val listStep get() = ClickGui.buttonStep @@ -24,4 +24,4 @@ abstract class ListButton(owner: ChildLayer.Drawable<*, *>) : ButtonComponent(ow } super.onEvent(e) } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/com/lambda/gui/api/component/core/DockingRect.kt b/common/src/main/kotlin/com/lambda/gui/api/component/core/DockingRect.kt index 87c9a0cac..6d23c95e5 100644 --- a/common/src/main/kotlin/com/lambda/gui/api/component/core/DockingRect.kt +++ b/common/src/main/kotlin/com/lambda/gui/api/component/core/DockingRect.kt @@ -1,7 +1,7 @@ package com.lambda.gui.api.component.core import com.lambda.module.modules.client.ClickGui -import com.lambda.util.math.MathUtils.coerceIn +import com.lambda.util.math.coerceIn import com.lambda.util.math.MathUtils.roundToStep import com.lambda.util.math.Rect import com.lambda.util.math.Vec2d @@ -80,4 +80,4 @@ abstract class DockingRect { CENTER(0.5), BOTTOM(1.0) } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/LambdaClickGui.kt b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/LambdaClickGui.kt index 934209857..42884c548 100644 --- a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/LambdaClickGui.kt +++ b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/LambdaClickGui.kt @@ -12,7 +12,7 @@ import com.lambda.module.Module import com.lambda.module.modules.client.ClickGui import com.lambda.module.modules.client.GuiSettings import com.lambda.module.modules.client.GuiSettings.primaryColor -import com.lambda.util.math.ColorUtils.multAlpha +import com.lambda.util.math.multAlpha import com.lambda.util.math.Vec2d import java.awt.Color @@ -75,4 +75,4 @@ object LambdaClickGui : AbstractClickGui("ClickGui", ClickGui) { } }) } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/ModuleButton.kt b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/ModuleButton.kt index df80cf068..33ab92480 100644 --- a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/ModuleButton.kt +++ b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/ModuleButton.kt @@ -19,12 +19,12 @@ import com.lambda.module.modules.client.GuiSettings import com.lambda.sound.LambdaSound import com.lambda.sound.SoundManager.playSoundRandomly import com.lambda.util.Mouse -import com.lambda.util.math.ColorUtils.multAlpha -import com.lambda.util.math.ColorUtils.setAlpha -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import com.lambda.util.math.MathUtils.toInt import com.lambda.util.math.Rect import com.lambda.util.math.Vec2d +import com.lambda.util.math.multAlpha +import com.lambda.util.math.setAlpha import com.lambda.util.math.transform import java.awt.Color import kotlin.math.abs @@ -45,7 +45,7 @@ class ModuleButton( override val isActive get() = isOpen private val openAnimation by animation.exp(0.0, 1.0, 0.7, ::isOpen) - override val childShowAnimation get() = lerp(0.0, openAnimation, owner.childShowAnimation) + override val childShowAnimation get() = lerp(owner.childShowAnimation, 0.0, openAnimation) private var settingsHeight = 0.0 private var renderHeight by animation.exp(::settingsHeight, 0.6) @@ -134,7 +134,7 @@ class ModuleButton( val left = rect - Vec2d(rect.size.x, 0.0) val right = rect + Vec2d(rect.size.x, 0.0) - val rect = lerp(left, right, activeAnimation) + val rect = lerp(activeAnimation, left, right) .clamp(rect) .shrink(shrinkAnimation) diff --git a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/SettingButton.kt b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/SettingButton.kt index 5b405b985..b95a1890e 100644 --- a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/SettingButton.kt +++ b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/SettingButton.kt @@ -5,7 +5,7 @@ import com.lambda.graphics.animation.Animation.Companion.exp import com.lambda.gui.api.GuiEvent import com.lambda.gui.api.component.button.ListButton import com.lambda.gui.api.component.core.list.ChildLayer -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp abstract class SettingButton>( val setting: T, @@ -18,8 +18,8 @@ abstract class SettingButton>( private var prevTickVisible = false private var visibilityAnimation by animation.exp(0.0, 1.0, 0.6, ::visible) - override val showAnimation get() = lerp(0.0, super.showAnimation, visibilityAnimation) - override val renderHeightOffset get() = renderHeightAnimation + lerp(-size.y, 0.0, visibilityAnimation) + override val showAnimation get() = lerp(visibilityAnimation, 0.0, super.showAnimation) + override val renderHeightOffset get() = renderHeightAnimation + lerp(visibilityAnimation, -size.y, 0.0) override var activeAnimation = 0.0 override fun onEvent(e: GuiEvent) { @@ -34,4 +34,4 @@ abstract class SettingButton>( } open fun unfocus() {} -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/BindButton.kt b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/BindButton.kt index 6a071bd2b..2658f9f38 100644 --- a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/BindButton.kt +++ b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/BindButton.kt @@ -8,7 +8,7 @@ import com.lambda.gui.impl.AbstractClickGui import com.lambda.gui.impl.clickgui.buttons.ModuleButton import com.lambda.gui.impl.clickgui.buttons.SettingButton import com.lambda.util.KeyCode -import com.lambda.util.math.ColorUtils.multAlpha +import com.lambda.util.math.multAlpha import com.lambda.util.extension.displayValue class BindButton( diff --git a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/BooleanButton.kt b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/BooleanButton.kt index 4601472c8..4b50550bd 100644 --- a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/BooleanButton.kt +++ b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/BooleanButton.kt @@ -10,18 +10,18 @@ import com.lambda.module.modules.client.GuiSettings import com.lambda.sound.LambdaSound import com.lambda.sound.SoundManager.playSoundRandomly import com.lambda.util.Mouse -import com.lambda.util.math.ColorUtils.multAlpha -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import com.lambda.util.math.Rect import com.lambda.util.math.Rect.Companion.inv import com.lambda.util.math.Vec2d +import com.lambda.util.math.multAlpha class BooleanButton( setting: BooleanSetting, owner: ChildLayer.Drawable, ModuleButton>, ) : SettingButton(setting, owner) { private var active by animation.exp(0.0, 1.0, 0.6, ::value) - private val zoomAnimation get() = lerp(2.0, 0.0, showAnimation) + private val zoomAnimation get() = lerp(showAnimation, 2.0, 0.0) private val checkboxRect get() = Rect(rect.rightTop - Vec2d(rect.size.y * 1.65, 0.0), rect.rightBottom) @@ -30,7 +30,7 @@ class BooleanButton( private val knobStart get() = Rect.basedOn(checkboxRect.leftTop, Vec2d.ONE * checkboxRect.size.y) private val knobEnd get() = Rect.basedOn(checkboxRect.rightBottom, Vec2d.ONE * checkboxRect.size.y * -1.0).inv() - private val checkboxKnob get() = lerp(knobStart, knobEnd, active).shrink(1.0 + zoomAnimation + interactAnimation) + private val checkboxKnob get() = lerp(active, knobStart, knobEnd).shrink(1.0 + zoomAnimation + interactAnimation) override fun onEvent(e: GuiEvent) { super.onEvent(e) diff --git a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/EnumSlider.kt b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/EnumSlider.kt index bcdc653b8..aba909bc2 100644 --- a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/EnumSlider.kt +++ b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/EnumSlider.kt @@ -6,12 +6,12 @@ import com.lambda.gui.api.component.core.list.ChildLayer import com.lambda.gui.impl.clickgui.buttons.ModuleButton import com.lambda.gui.impl.clickgui.buttons.SettingButton import com.lambda.module.modules.client.ClickGui -import com.lambda.util.math.ColorUtils.setAlpha import com.lambda.util.math.MathUtils.floorToInt -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import com.lambda.util.math.Vec2d import com.lambda.util.math.transform import com.lambda.util.extension.displayValue +import com.lambda.util.math.setAlpha import java.awt.Color class EnumSlider>( @@ -32,10 +32,10 @@ class EnumSlider>( renderer.font.apply { val text = value.displayValue val progress = 1.0 - activeAnimation - val scale = lerp(0.5, 1.0, progress) + val scale = lerp(progress, 0.5, 1.0) val width = getWidth(text, scale) val position = Vec2d(rect.right, rect.center.y) - Vec2d(ClickGui.windowPadding + width, 0.0) - val color = Color.WHITE.setAlpha(lerp(0.0, progress, showAnimation)) + val color = Color.WHITE.setAlpha(lerp(showAnimation, 0.0, progress)) build(text, position, color, scale) } diff --git a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/NumberSlider.kt b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/NumberSlider.kt index b4b3ca532..bb6109b00 100644 --- a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/NumberSlider.kt +++ b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/NumberSlider.kt @@ -8,10 +8,10 @@ import com.lambda.gui.impl.AbstractClickGui import com.lambda.gui.impl.clickgui.buttons.ModuleButton import com.lambda.gui.impl.clickgui.buttons.SettingButton import com.lambda.util.Mouse -import com.lambda.util.math.ColorUtils.multAlpha -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import com.lambda.util.math.MathUtils.roundToStep import com.lambda.util.math.MathUtils.typeConvert +import com.lambda.util.math.multAlpha import com.lambda.util.math.normalize class NumberSlider( @@ -68,9 +68,9 @@ class NumberSlider( override fun setValueByProgress(progress: Double) { setValue( lerp( + progress, setting.range.start.toDouble(), - setting.range.endInclusive.toDouble(), - progress + setting.range.endInclusive.toDouble() ) ) } @@ -78,4 +78,4 @@ class NumberSlider( private fun setValue(valueIn: Double) { value = value.typeConvert(valueIn.roundToStep(setting.step.toDouble())) } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/Slider.kt b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/Slider.kt index 5247f9e15..7cb0ccba0 100644 --- a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/Slider.kt +++ b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/Slider.kt @@ -11,9 +11,9 @@ import com.lambda.module.modules.client.GuiSettings import com.lambda.sound.LambdaSound import com.lambda.sound.SoundManager.playSound import com.lambda.util.Mouse -import com.lambda.util.math.ColorUtils.multAlpha -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import com.lambda.util.math.Vec2d +import com.lambda.util.math.multAlpha import com.lambda.util.math.transform abstract class Slider>( @@ -23,7 +23,7 @@ abstract class Slider>( // Force this slider to follow mouse when dragging instead of rounding to the closest setting value private val progressAnimation by animation.exp({ mouseX?.let(::getProgressByMouse) ?: progress }, 0.6) - private val renderProgress get() = lerp(0.0, progressAnimation, showAnimation) + private val renderProgress get() = lerp(showAnimation, 0.0, progressAnimation) protected abstract fun setValueByProgress(progress: Double) private var lastPlayedValue = value @@ -73,7 +73,7 @@ abstract class Slider>( lastPlayedValue = value lastPlayedTiming = time - playSound(LambdaSound.BUTTON_CLICK.event, lerp(0.9, 1.2, progress)) + playSound(LambdaSound.BUTTON_CLICK.event, lerp(progress, 0.9, 1.2)) } private fun getProgressByMouse(mouseX: Double) = diff --git a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/StringButton.kt b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/StringButton.kt index 5226e4278..61e06de82 100644 --- a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/StringButton.kt +++ b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/StringButton.kt @@ -7,7 +7,7 @@ import com.lambda.gui.api.component.core.list.ChildLayer import com.lambda.gui.impl.AbstractClickGui import com.lambda.gui.impl.clickgui.buttons.ModuleButton import com.lambda.gui.impl.clickgui.buttons.SettingButton -import com.lambda.util.math.ColorUtils.multAlpha +import com.lambda.util.math.multAlpha class StringButton( setting: StringSetting, @@ -41,4 +41,4 @@ class StringButton( if (!inputBar.isActive) (owner.gui as? AbstractClickGui)?.unfocusSettings() inputBar.toggle() } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/com/lambda/interaction/RotationManager.kt b/common/src/main/kotlin/com/lambda/interaction/RotationManager.kt index 508d159b4..b8d0a65c9 100644 --- a/common/src/main/kotlin/com/lambda/interaction/RotationManager.kt +++ b/common/src/main/kotlin/com/lambda/interaction/RotationManager.kt @@ -17,7 +17,7 @@ import com.lambda.interaction.rotation.RotationMode import com.lambda.module.modules.client.Baritone import com.lambda.threading.runGameScheduled import com.lambda.threading.runSafe -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import com.lambda.util.math.MathUtils.toRadian import com.lambda.util.math.Vec2d import com.lambda.util.extension.partialTicks @@ -132,7 +132,7 @@ object RotationManager : Loadable { private val smoothRotation get() = - lerp(prevRotation, currentRotation, mc.partialTicks) + lerp(mc.partialTicks, prevRotation, currentRotation) @JvmStatic val lockRotation @@ -180,7 +180,7 @@ object RotationManager : Loadable { val config = currentContext?.config ?: return null if (config.rotationMode == RotationMode.SILENT) return null - val rot = lerp(prevRotation, currentRotation, deltaTime) + val rot = lerp(deltaTime, prevRotation, currentRotation) return Vec2d(rot.yaw, rot.pitch) } diff --git a/common/src/main/kotlin/com/lambda/module/hud/TickShiftCharge.kt b/common/src/main/kotlin/com/lambda/module/hud/TickShiftCharge.kt index fb7e8701e..d5a0851f1 100644 --- a/common/src/main/kotlin/com/lambda/module/hud/TickShiftCharge.kt +++ b/common/src/main/kotlin/com/lambda/module/hud/TickShiftCharge.kt @@ -7,7 +7,7 @@ import com.lambda.module.modules.client.GuiSettings import com.lambda.module.modules.client.GuiSettings.primaryColor import com.lambda.module.modules.movement.TickShift import com.lambda.module.tag.ModuleTag -import com.lambda.util.math.ColorUtils.multAlpha +import com.lambda.util.math.multAlpha import com.lambda.util.math.Rect import java.awt.Color @@ -52,4 +52,4 @@ object TickShiftCharge : HudModule( ) } } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt b/common/src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt index a17f46a0e..157977e01 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt @@ -19,7 +19,7 @@ import com.lambda.module.Module import com.lambda.module.tag.ModuleTag import com.lambda.threading.runConcurrent import com.lambda.threading.runSafe -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import com.lambda.util.math.MathUtils.random import com.lambda.util.math.VecUtils.distSq import com.lambda.util.math.VecUtils.minus @@ -196,13 +196,13 @@ object KillAura : Module( ) val random = Vec3d( - lerp(box.minX, box.maxX, shakeRandom.x), - lerp(box.minY, box.maxY, shakeRandom.x), - lerp(box.minZ, box.maxZ, shakeRandom.x) + lerp(shakeRandom.x, box.minX, box.maxX), + lerp(shakeRandom.x, box.minY, box.maxY), + lerp(shakeRandom.x, box.minZ, box.maxZ) ) - vec = lerp(vec, box.center, centerFactor) // Mix with center - vec = lerp(vec, random, shakeFactor) // Apply shaking + vec = lerp(centerFactor, vec, box.center) // Mix with center + vec = lerp(shakeFactor, vec, random) // Apply shaking // Raycast run { @@ -308,4 +308,4 @@ object KillAura : Module( lastAttackTime = 0L hitDelay = 100.0 } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/com/lambda/module/modules/debug/RenderTest.kt b/common/src/main/kotlin/com/lambda/module/modules/debug/RenderTest.kt index c1b6be5ec..2d0eb6b03 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/debug/RenderTest.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/debug/RenderTest.kt @@ -6,7 +6,7 @@ import com.lambda.graphics.renderer.esp.DynamicAABB.Companion.dynamicBox import com.lambda.graphics.renderer.esp.builders.build import com.lambda.module.Module import com.lambda.module.tag.ModuleTag -import com.lambda.util.math.ColorUtils.setAlpha +import com.lambda.util.math.setAlpha import com.lambda.util.world.entitySearch import net.minecraft.entity.LivingEntity import net.minecraft.util.math.Box diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/BackTrack.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/BackTrack.kt index 99f71b5b7..7123f2f62 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/BackTrack.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/BackTrack.kt @@ -16,11 +16,11 @@ import com.lambda.util.ClientPacket import com.lambda.util.PacketUtils.handlePacketSilently import com.lambda.util.PacketUtils.sendPacketSilently import com.lambda.util.ServerPacket -import com.lambda.util.math.ColorUtils.multAlpha -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import com.lambda.util.math.VecUtils.dist import com.lambda.util.math.VecUtils.minus import com.lambda.util.math.VecUtils.plus +import com.lambda.util.math.multAlpha import net.minecraft.entity.LivingEntity import net.minecraft.network.packet.s2c.play.EntityAnimationS2CPacket import net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket @@ -100,7 +100,7 @@ object BackTrack : Module( val c1 = GuiSettings.primaryColor val c2 = Color.RED val p = target.hurtTime / 10.0 - val c = lerp(c1, c2, p) + val c = lerp(p, c1, c2) it.renderer.build(box, c.multAlpha(0.3), c.multAlpha(0.8)) } diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/Blink.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/Blink.kt index 702931923..ff11fb20f 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/Blink.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/Blink.kt @@ -13,7 +13,7 @@ import com.lambda.module.tag.ModuleTag import com.lambda.util.ClientPacket import com.lambda.util.PacketUtils.handlePacketSilently import com.lambda.util.PacketUtils.sendPacketSilently -import com.lambda.util.math.ColorUtils.setAlpha +import com.lambda.util.math.setAlpha import com.lambda.util.math.VecUtils.minus import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt b/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt index dd0840faf..60bc3e033 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt @@ -12,7 +12,7 @@ import com.lambda.module.tag.ModuleTag import com.lambda.util.math.transform import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket.Action -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import net.minecraft.util.math.Box import java.awt.Color @@ -109,16 +109,16 @@ object FastBreak : Module( boxSet.forEach { box -> val previousFactor = interaction.currentBreakingProgress - breakDelta val nextFactor = interaction.currentBreakingProgress - val currentFactor = lerp(previousFactor, nextFactor, mc.tickDelta) + val currentFactor = lerp(mc.tickDelta, previousFactor, nextFactor) val fillColour = if (fillColourMode == ColourMode.Dynamic) { - lerp(startFillColour, endFillColour, currentFactor.toDouble()) + lerp(currentFactor.toDouble(), startFillColour, endFillColour) } else { staticFillColour } val outlineColour = if (outlineColourMode == ColourMode.Dynamic) { - lerp(startOutlineColour, endOutlineColour, currentFactor.toDouble()) + lerp(currentFactor.toDouble(), startOutlineColour, endOutlineColour) } else { staticOutlineColour } @@ -148,26 +148,26 @@ object FastBreak : Module( val boxCenter = Box(box.center, box.center) when (renderMode) { RenderMode.Out -> { - return lerp(boxCenter, box, factor.toDouble()) + return lerp(factor.toDouble(), boxCenter, box) } RenderMode.In -> { - return lerp(box, boxCenter, factor.toDouble()) + return lerp(factor.toDouble(), box, boxCenter) } RenderMode.InOut -> { return if (factor >= 0.5f) { - lerp(boxCenter, box, (factor.toDouble() - 0.5) * 2) + lerp((factor.toDouble() - 0.5) * 2, boxCenter, box) } else { - lerp(box, boxCenter, factor.toDouble() * 2) + lerp(factor.toDouble() * 2, box, boxCenter) } } RenderMode.OutIn -> { return if (factor >= 0.5f) { - lerp(box, boxCenter, (factor.toDouble() - 0.5) * 2) + lerp((factor.toDouble() - 0.5) * 2, box, boxCenter) } else { - lerp(boxCenter, box, factor.toDouble() * 2) + lerp(factor.toDouble() * 2, boxCenter, box) } } diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt b/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt index 0c6946fe8..b6b2792ec 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt @@ -15,7 +15,7 @@ import com.lambda.module.Module import com.lambda.module.modules.client.TaskFlow import com.lambda.module.tag.ModuleTag import com.lambda.util.BlockUtils.blockState -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap import net.minecraft.block.BlockState import net.minecraft.enchantment.EnchantmentHelper @@ -572,20 +572,20 @@ object PacketMine : Module( } else { listOf(Box(0.0, 0.0, 0.0, 1.0, 1.0, 1.0)) } - boxes = boxes.map { val reSized = lerp(Box(it.center, it.center), it, renderQueueSize.toDouble()); reSized.offset(pos) } + boxes = boxes.map { val reSized = lerp(renderQueueSize.toDouble(), Box(it.center, it.center), it); reSized.offset(pos) } val indexFactor = blockQueue.indexOf(pos).toDouble() / blockQueue.size.toDouble() val fillColour = if (queueFillColourMode == ColourMode.Static) { queueStaticFillColour } else { - lerp(queueStartFillColour, queueEndFillColour, indexFactor) + lerp(indexFactor, queueStartFillColour, queueEndFillColour) } val outlineColour = if (queueOutlineColourMode == ColourMode.Static) { queueStaticOutlineColour } else { - lerp(queueStartOutlineColour, queueEndOutlineColour, indexFactor) + lerp(indexFactor, queueStartOutlineColour, queueEndOutlineColour) } boxes.forEach { box -> @@ -1212,12 +1212,12 @@ object PacketMine : Module( } val previousFactor = previousMiningProgress * threshold val nextFactor = miningProgress * threshold - val currentFactor = lerp(previousFactor, nextFactor, mc.tickDelta) + val currentFactor = lerp(mc.tickDelta, previousFactor, nextFactor) val paused = (pauseWhileUsingItems && player.isUsingItem) || pausedForRotation || awaitingQueueBreak val fillColour = if (fillColourMode == ColourMode.Dynamic) { - val lerpColour = lerp(startFillColour, endFillColour, currentFactor.toDouble()) + val lerpColour = lerp(currentFactor.toDouble(), startFillColour, endFillColour) if (!paused) { lastLerpFillColour = lerpColour lerpColour @@ -1229,7 +1229,7 @@ object PacketMine : Module( } val outlineColour = if (outlineColourMode == ColourMode.Dynamic) { - val lerpColour = lerp(startOutlineColour, endOutlineColour, currentFactor.toDouble()) + val lerpColour = lerp(currentFactor.toDouble(), startOutlineColour, endOutlineColour) if (!paused) { lastLerpOutlineColour = lerpColour lerpColour @@ -1287,26 +1287,26 @@ object PacketMine : Module( val boxCenter = Box(box.center, box.center) when (renderMode) { RenderMode.Out -> { - return lerp(boxCenter, box, factor.toDouble()) + return lerp(factor.toDouble(), boxCenter, box) } RenderMode.In -> { - return lerp(box, boxCenter, factor.toDouble()) + return lerp(factor.toDouble(), box, boxCenter) } RenderMode.InOut -> { return if (factor >= 0.5f) { - lerp(boxCenter, box, (factor.toDouble() - 0.5) * 2) + lerp((factor.toDouble() - 0.5) * 2, boxCenter, box) } else { - lerp(box, boxCenter, factor.toDouble() * 2) + lerp(factor.toDouble() * 2, box, boxCenter) } } RenderMode.OutIn -> { return if (factor >= 0.5f) { - lerp(box, boxCenter, (factor.toDouble() - 0.5) * 2) + lerp((factor.toDouble() - 0.5) * 2, box, boxCenter) } else { - lerp(boxCenter, box, factor.toDouble() * 2) + lerp(factor.toDouble() * 2, boxCenter, box) } } @@ -1412,4 +1412,4 @@ object PacketMine : Module( return f } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt b/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt index 6cc7cc3bf..392da9db9 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt @@ -21,8 +21,7 @@ import com.lambda.module.Module import com.lambda.module.modules.client.GuiSettings import com.lambda.module.modules.client.GuiSettings.colorSpeed import com.lambda.module.tag.ModuleTag -import com.lambda.util.math.ColorUtils.multAlpha -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import com.lambda.util.math.MathUtils.random import com.lambda.util.math.VecUtils import com.lambda.util.math.VecUtils.plus @@ -30,6 +29,7 @@ import com.lambda.util.math.VecUtils.times import com.lambda.util.math.transform import com.lambda.util.player.MovementUtils.moveDelta import com.lambda.util.extension.partialTicks +import com.lambda.util.math.multAlpha import com.lambda.util.world.raycast.RayCastMask import net.minecraft.entity.Entity import net.minecraft.util.math.Vec3d @@ -176,10 +176,10 @@ object Particles : Module( } val (c1, c2) = GuiSettings.primaryColor to GuiSettings.secondaryColor - val color = lerp(c1, c2, sin(colorTicks) * 0.5 + 0.5).multAlpha(alpha * alphaSetting) + val color = lerp(sin(colorTicks) * 0.5 + 0.5, c1, c2).multAlpha(alpha * alphaSetting) - val position = lerp(prevPos, position, mc.partialTicks) - val size = if (lay) environmentSize else sizeSetting * lerp(0.5, 1.0, alpha) + val position = lerp(mc.partialTicks, prevPos, position) + val size = if (lay) environmentSize else sizeSetting * lerp(alpha, 0.5, 1.0) withVertexTransform(buildWorldProjection(position, size, projRotation)) { vao.use { diff --git a/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt b/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt index 56604c22d..824571bd3 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/render/WorldColors.kt @@ -2,7 +2,7 @@ package com.lambda.module.modules.render import com.lambda.module.Module import com.lambda.module.tag.ModuleTag -import com.lambda.util.math.ColorUtils.vec3d +import com.lambda.util.math.asVec3d import net.minecraft.util.math.Vec3d import java.awt.Color @@ -26,5 +26,5 @@ object WorldColors : Module( @JvmStatic fun backgroundColor(base: Vec3d) = - if (customFog && isEnabled) fogColor.vec3d else base -} \ No newline at end of file + if (customFog && isEnabled) fogColor.asVec3d else base +} diff --git a/common/src/main/kotlin/com/lambda/util/extension/Entity.kt b/common/src/main/kotlin/com/lambda/util/extension/Entity.kt index 8285498f3..0306c133d 100644 --- a/common/src/main/kotlin/com/lambda/util/extension/Entity.kt +++ b/common/src/main/kotlin/com/lambda/util/extension/Entity.kt @@ -1,7 +1,7 @@ package com.lambda.util.extension import com.lambda.interaction.rotation.Rotation -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import net.minecraft.entity.Entity import net.minecraft.entity.LivingEntity import net.minecraft.util.math.Vec3d @@ -16,4 +16,4 @@ var LivingEntity.isElytraFlying get() = isFallFlying set(value) { setFlag(7, value) } -fun Vec3d.interpolate(other: Vec3d, t: Double) = lerp(this, other, t) +fun Vec3d.interpolate(other: Vec3d, t: Double) = lerp(t, this, other) diff --git a/common/src/main/kotlin/com/lambda/util/math/Color.kt b/common/src/main/kotlin/com/lambda/util/math/Color.kt index 7efa7779f..63629a7ff 100644 --- a/common/src/main/kotlin/com/lambda/util/math/Color.kt +++ b/common/src/main/kotlin/com/lambda/util/math/Color.kt @@ -1,11 +1,11 @@ package com.lambda.util.math +import net.minecraft.util.math.Vec3d import java.awt.Color val Color.hsb get() = Color.RGBtoHSB(red, green, blue, null) .map(Float::toDouble) - .toDoubleArray() fun DoubleArray.readHSB(): Color = Color.getHSBColor(this[0].toFloat(), this[1].toFloat(), this[2].toFloat()) @@ -13,7 +13,15 @@ val Color.hue get() = hsb[0] val Color.saturation get() = hsb[1] val Color.brightness get() = hsb[2] -val Color.r get() = red / 255f -val Color.g get() = green / 255f -val Color.b get() = blue / 255f -val Color.a get() = alpha / 255f +fun Color.setAlpha(value: Double) = + Color(red, green, blue, (value * 255.0).coerceIn(0.0, 255.0).toInt()) + +fun Color.multAlpha(value: Double) = + Color(red, green, blue, (value * alpha).coerceIn(0.0, 255.0).toInt()) + +val Color.r get() = red / 255.0 +val Color.g get() = green / 255.0 +val Color.b get() = blue / 255.0 +val Color.a get() = alpha / 255.0 + +val Color.asVec3d get() = Vec3d(r, g, b) diff --git a/common/src/main/kotlin/com/lambda/util/math/ColorUtils.kt b/common/src/main/kotlin/com/lambda/util/math/ColorUtils.kt deleted file mode 100644 index 6adec5efd..000000000 --- a/common/src/main/kotlin/com/lambda/util/math/ColorUtils.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.lambda.util.math - -import net.minecraft.util.math.Vec3d -import java.awt.Color - -object ColorUtils { - fun Color.setAlpha(value: Double) = - Color(red, green, blue, (value * 255.0).coerceIn(0.0, 255.0).toInt()) - - fun Color.multAlpha(value: Double) = - Color(red, green, blue, (value * alpha).coerceIn(0.0, 255.0).toInt()) - - val Color.r get() = red.toDouble() / 255.0 - val Color.g get() = green.toDouble() / 255.0 - val Color.b get() = blue.toDouble() / 255.0 - val Color.a get() = alpha.toDouble() / 255.0 - - @JvmStatic - val Color.vec3d get() = Vec3d(r, g, b) -} \ No newline at end of file diff --git a/common/src/main/kotlin/com/lambda/util/math/Linear.kt b/common/src/main/kotlin/com/lambda/util/math/Linear.kt new file mode 100644 index 000000000..500e840eb --- /dev/null +++ b/common/src/main/kotlin/com/lambda/util/math/Linear.kt @@ -0,0 +1,253 @@ +package com.lambda.util.math + +import com.lambda.interaction.rotation.Rotation +import net.minecraft.util.math.Box +import net.minecraft.util.math.Vec3d +import java.awt.Color +import kotlin.math.max +import kotlin.math.min +import kotlin.random.Random.Default.nextDouble + +/** + * Iterates over the double range with the specified step. + */ +fun ClosedRange.step(step: Double) = object : DoubleIterator() { + private var next = start + override fun hasNext() = next <= endInclusive + override fun nextDouble() = next.also { next += step } +} + +/** + * Iterates over the float range with the specified step. + */ +fun ClosedRange.step(step: Float) = object : FloatIterator() { + private var next = start + override fun hasNext() = next <= endInclusive + override fun nextFloat() = next.also { next += step } +} + +/** + * Returns a random number within the range. + */ +fun ClosedRange.random() = nextDouble(start, endInclusive) + +/** + * Converts a value from one range to a normalized value between 0 and 1. + */ +fun ClosedRange.normalize(value: Double): Double = + transform(value, 0.0, 1.0) + +/** + * Converts a value from one range to a normalized value between 0 and 1. + */ +fun ClosedRange.normalize(value: Float): Float = + transform(value, 0f, 1f) + +/** + * Inverts the range. + */ +fun ClosedRange.inv() = endInclusive to start + +/** + * Converts a value from one range to another while keeping the ratio using linear interpolation. + * + * @param value The value to convert. + * @param min The minimum of the new range. + * @param max The maximum of the new range. + * + * @return The converted value. + */ +fun ClosedRange.transform( + value: Double, + min: Double, + max: Double, +): Double = + transform(value, start, endInclusive, min, max) + +/** + * Converts a value from one range to another while keeping the ratio using linear interpolation. + * + * @param value The value to convert. + * @param min The minimum of the new range. + * @param max The maximum of the new range. + * + * @return The converted value. + */ +fun ClosedRange.transform( + value: Float, + min: Float, + max: Float, +): Float = + transform(value, start, endInclusive, min, max) + +/** + * Linear interpolation between two axes-aligned boxes. + * + * @param start The start box. + * @param end The end box. + */ +fun lerp(value: Double, start: Box, end: Box) = + Box( + lerp(value, start.minX, end.minX), + lerp(value, start.minY, end.minY), + lerp(value, start.minZ, end.minZ), + lerp(value, start.maxX, end.maxX), + lerp(value, start.maxY, end.maxY), + lerp(value, start.maxZ, end.maxZ), + ) + +/** + * Linear interpolation between two 2d vectors. + * + * @param start The start vector. + * @param end The end vector. + */ +fun lerp(value: Double, start: Vec2d, end: Vec2d) = + Vec2d( + lerp(value, start.x, end.x), + lerp(value, start.y, end.y), + ) + +/** + * Linear interpolation between two 3d vectors. + */ +fun lerp(value: Double, start: Vec3d, end: Vec3d) = + Vec3d( + lerp(start.x, end.x, value), + lerp(start.y, end.y, value), + lerp(start.z, end.z, value), + ) + +/** + * Linear interpolation between two rotations. + */ +fun lerp(value: Double, start: Rotation, end: Rotation) = + Rotation( + lerp(value, start.yaw, end.yaw), + lerp(value, start.pitch, end.pitch), + ) + +/** + * Linear interpolation between two rectangles + */ +fun lerp(value: Double, start: Rect, end: Rect) = + Rect( + lerp(value, start.leftTop, end.leftTop), + lerp(value, start.rightBottom, end.rightBottom), + ) + +/** + * Linear interpolation between two colors. + */ +fun lerp(value: Double, start: Color, end: Color) = + Color( + lerp(value, start.r, end.r).toFloat(), + lerp(value, start.g, end.g).toFloat(), + lerp(value, start.b, end.b).toFloat(), + lerp(value, start.a, end.a).toFloat(), + ) + +/** + * Performs linear interpolation between two Double values. + * + * This function calculates the value at a specific point + * between [start] and [end] based on the interpolation factor [value]. + * The interpolation factor [value] is clamped between zero + * and one to ensure the result stays within the range of [start] and [end]. + * + * @param start The start value. + * @param end The end value. + * @param value The interpolation factor, typically between 0 (representing [start]) and 1 (representing [end]). + * @return The interpolated value between [start] and [end]. + */ +fun lerp(value: Double, start: Double, end: Double) = + transform(value.coerceIn(0.0, 1.0), 0.0, 1.0, start, end) + +/** + * Performs linear interpolation between two Float values. + * + * This function calculates the value at a specific point + * between [start] and [end] based on the interpolation factor [value]. + * The interpolation factor [value] is clamped between zero + * and one to ensure the result stays within the range of [start] and [end]. + * + * @param start The start value. + * @param end The end value. + * @param value The interpolation factor, typically between 0 (representing [start]) and 1 (representing [end]). + * + * @return The interpolated value between [start] and [end]. + */ +fun lerp(value: Float, start: Float, end: Float) = + transform(value.coerceIn(0f, 1f), 0f, 1f, start, end) + +/** + * Converts a value from one range to another while keeping the ratio using linear map. + * + * @param value The value to convert. + * @param ogStart The original start value. + * @param ogEnd The original end value. + * @param nStart The new start value. + * @param nEnd The new end value. + * + * @return The converted value. + * @see Linear Map + */ +fun transform( + value: Double, + ogStart: Double, + ogEnd: Double, + nStart: Double, + nEnd: Double, +): Double = + nStart + (value - ogStart) * ((nEnd - nStart) / (ogEnd - ogStart)) + +/** + * Converts a value from one range to another while keeping the ratio using linear map. + * + * @param value The value to convert. + * @param ogStart The original start value. + * @param ogEnd The original end value. + * @param nStart The new start value. + * @param nEnd The new end value. + * + * @return The converted value. + * @see Linear Map + */ +fun transform( + value: Float, + ogStart: Float, + ogEnd: Float, + nStart: Float, + nEnd: Float, +): Float = + nStart + (value - ogStart) * ((nEnd - nStart) / (ogEnd - ogStart)) + + +/** + * Coerces a value to be within the range. + */ +fun ClosedRange.coerceIn(value: Double) = value.coerceIn(start, endInclusive) + +/** + * Coerces a value to be within the range. + */ +fun ClosedRange.coerceIn(value: Float) = value.coerceIn(start, endInclusive) + +/** + * Coerces a value to be within a 2d vector. + * + * @param minX The minimum x value. + * @param maxX The maximum x value. + * @param minY The minimum y value. + * @param maxY The maximum y value. + */ +fun Vec2d.coerceIn( + minX: Double, + maxX: Double, + minY: Double, + maxY: Double, +) = + Vec2d( + max(minX, min(x, maxX)), + max(minY, min(y, maxY)) + ) diff --git a/common/src/main/kotlin/com/lambda/util/math/MathUtils.kt b/common/src/main/kotlin/com/lambda/util/math/MathUtils.kt index d9fa1776b..a09120649 100644 --- a/common/src/main/kotlin/com/lambda/util/math/MathUtils.kt +++ b/common/src/main/kotlin/com/lambda/util/math/MathUtils.kt @@ -1,16 +1,5 @@ package com.lambda.util.math -import com.lambda.interaction.rotation.Rotation -import com.lambda.module.modules.client.ClickGui -import com.lambda.util.math.ColorUtils.a -import com.lambda.util.math.ColorUtils.b -import com.lambda.util.math.ColorUtils.g -import com.lambda.util.math.ColorUtils.r -import net.minecraft.util.math.Box -import com.lambda.util.math.MathUtils.roundToStep -import net.fabricmc.loader.impl.lib.sat4j.core.Vec -import net.minecraft.util.math.Vec3d -import java.awt.Color import java.math.BigDecimal import java.math.RoundingMode import kotlin.math.* @@ -89,85 +78,4 @@ object MathUtils { } inline val Int.sq: Int get() = this * this - - /** - * Performs linear interpolation between two Float values. - * - * This function calculates the value at a specific point - * between [start] and [end] based on the interpolation factor [factor]. - * The interpolation factor [factor] is clamped between zero - * and one to ensure the result stays within the range of [start] and [end]. - * - * @param start The start value. - * @param end The end value. - * @param factor The interpolation factor, typically between 0 (representing [start]) and 1 (representing [end]). - * @return The interpolated value between [start] and [end]. - */ - fun lerp(start: Float, end: Float, factor: Float) = - start + ((end - start) * factor.coerceIn(0f, 1f)) - - /** - * Performs linear interpolation between two Double values. - * - * This function calculates the value at a specific point - * between [start] and [end] based on the interpolation factor [factor]. - * The interpolation factor [factor] is clamped between zero - * and one to ensure the result stays within the range of [start] and [end]. - * - * @param start The start value. - * @param end The end value. - * @param factor The interpolation factor, typically between 0 (representing [start]) and 1 (representing [end]). - * @return The interpolated value between [start] and [end]. - */ - fun lerp(start: Double, end: Double, factor: Double) = - start + ((end - start) * factor.coerceIn(0.0, 1.0)) - - fun lerp(start: Box, end: Box, factor: Double) = - Box( - lerp(start.minX, end.minX, factor), - lerp(start.minY, end.minY, factor), - lerp(start.minZ, end.minZ, factor), - lerp(start.maxX, end.maxX, factor), - lerp(start.maxY, end.maxY, factor), - lerp(start.maxZ, end.maxZ, factor) - ) - - fun lerp(start: Vec3d, end: Vec3d, factor: Double) = - Vec3d( - lerp(start.x, end.x, factor), - lerp(start.y, end.y, factor), - lerp(start.z, end.z, factor) - ) - - fun lerp(start: Vec2d, end: Vec2d, factor: Double) = - Vec2d( - lerp(start.x, end.x, factor), - lerp(start.y, end.y, factor) - ) - - fun lerp(start: Rect, end: Rect, factor: Double) = - Rect( - lerp(start.leftTop, end.leftTop, factor), - lerp(start.rightBottom, end.rightBottom, factor) - ) - - fun lerp(start: Rotation, end: Rotation, factor: Double) = - Rotation( - lerp(start.yaw, end.yaw, factor), - lerp(start.pitch, end.pitch, factor) - ) - - fun lerp(c1: Color, c2: Color, p: Double) = - Color( - lerp(c1.r, c2.r, p).toFloat(), - lerp(c1.g, c2.g, p).toFloat(), - lerp(c1.b, c2.b, p).toFloat(), - lerp(c1.a, c2.a, p).toFloat() - ) - - fun Vec2d.coerceIn(minX: Double, maxX: Double, minY: Double, maxY: Double) = - Vec2d( - max(minX, min(x, maxX)), - max(minY, min(y, maxY)) - ) } diff --git a/common/src/main/kotlin/com/lambda/util/math/Range.kt b/common/src/main/kotlin/com/lambda/util/math/Range.kt deleted file mode 100644 index a97862381..000000000 --- a/common/src/main/kotlin/com/lambda/util/math/Range.kt +++ /dev/null @@ -1,109 +0,0 @@ -package com.lambda.util.math - -import kotlin.random.Random.Default.nextDouble - -/** - * Iterates over the double range with the specified step. - */ -fun ClosedRange.step(step: Double) = object : DoubleIterator() { - private var next = start - override fun hasNext() = next <= endInclusive - override fun nextDouble() = next.also { next += step } -} - -/** - * Iterates over the float range with the specified step. - */ -fun ClosedRange.step(step: Float) = object : FloatIterator() { - private var next = start - override fun hasNext() = next <= endInclusive - override fun nextFloat() = next.also { next += step } -} - -/** - * Returns a random number within the range. - */ -fun ClosedRange.random() = nextDouble(start, endInclusive) - -/** - * Converts a value from one range to a normalized value between 0 and 1. - */ -fun ClosedRange.normalize(value: Double): Double = - scale(value, 0.0, 1.0) - -/** - * Converts a value from one range to a normalized value between 0 and 1. - */ -fun ClosedRange.normalize(value: Float): Float = - scale(value, 0.0f, 1.0f) - -/** - * Inverts the range. - */ -fun ClosedRange.inverted() = endInclusive to start - -/** - * Sinusoidal interpolation between two values. - */ -fun ClosedRange.sinInterpolate(value: Double): Double = - transform(value, start, endInclusive, -1.0, 1.0) - -/** - * Sinusoidal interpolation between two values. - */ -fun ClosedRange.sinInterpolate(value: Float): Float = - transform(value, start, endInclusive, -1.0f, 1.0f) - -/** - * Converts a value from one range to another while keeping the ratio using linear interpolation. - * @param value The value to convert. - * @param minIn The minimum of the new range. - * @param maxIn The maximum of the new range. - * @return The converted value. - */ -fun ClosedRange.scale(value: Double, minIn: Double, maxIn: Double): Double = - transform(value, start, endInclusive, minIn, maxIn) - -/** - * Converts a value from one range to another while keeping the ratio using linear interpolation. - * @param value The value to convert. - * @param minIn The minimum of the new range. - * @param maxIn The maximum of the new range. - * @return The converted value. - */ -fun ClosedRange.scale(value: Float, minIn: Float, maxIn: Float): Float = - transform(value, start, endInclusive, minIn, maxIn) - -/** - * Converts a value from one range to another while keeping the ratio using linear interpolation. - * @param value The value to convert. - * @param x1 The minimum of the old range. - * @param y1 The maximum of the old range. - * @param x2 The minimum of the new range. - * @param y2 The maximum of the new range. - * @return The converted value. - * @see Linear Interpolation - */ -fun transform(value: Double, x1: Double, y1: Double, x2: Double, y2: Double): Double = - (x2 + (value - x1) * ((y2 - x2) / (y1 - x1))) - -/** - * Converts a value from one range to another while keeping the ratio using linear interpolation. - * @param value The value to convert. - * @param x1 The minimum of the old range. - * @param y1 The maximum of the old range. - * @param x2 The minimum of the new range. - * @param y2 The maximum of the new range. - * @return The converted value. - * @see Linear Interpolation - */ -fun transform(value: Float, x1: Float, y1: Float, x2: Float, y2: Float): Float = - (x2 + (value - x1) * ((y2 - x2) / (y1 - x1))) - - -/** - * Coerces a value to be within the range. - * @param value The value to clamp. - * @return The clamped value. - */ -fun ClosedRange.coerceIn(value: Double) = value.coerceIn(start, endInclusive) diff --git a/common/src/main/kotlin/com/lambda/util/math/Rect.kt b/common/src/main/kotlin/com/lambda/util/math/Rect.kt index ace18112f..8488fb076 100644 --- a/common/src/main/kotlin/com/lambda/util/math/Rect.kt +++ b/common/src/main/kotlin/com/lambda/util/math/Rect.kt @@ -1,6 +1,6 @@ package com.lambda.util.math -import com.lambda.util.math.MathUtils.lerp +import com.lambda.util.math.lerp import kotlin.math.max import kotlin.math.min @@ -16,7 +16,7 @@ data class Rect(private val pos1: Vec2d, private val pos2: Vec2d) { val leftBottom get() = Vec2d(left, bottom) val size get() = Vec2d(right - left, bottom - top) - val center get() = lerp(pos1, pos2, 0.5) + val center get() = lerp(0.5, pos1, pos2) operator fun plus(vec2d: Vec2d) = Rect(pos1 + vec2d, pos2 + vec2d) operator fun minus(vec2d: Vec2d) = Rect(pos1 - vec2d, pos2 - vec2d)