Skip to content

Commit f38db93

Browse files
committed
Merge branch 'master' into feature/combat
2 parents ae4e40f + 9d0d382 commit f38db93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+565
-488
lines changed

common/src/main/kotlin/com/lambda/Lambda.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import com.mojang.authlib.GameProfile
3232
import com.mojang.blaze3d.systems.RenderSystem.recordRenderCall
3333
import net.minecraft.block.Block
3434
import net.minecraft.client.MinecraftClient
35+
import net.minecraft.item.ItemStack
36+
import net.minecraft.text.Text
3537
import net.minecraft.util.math.BlockPos
3638
import org.apache.logging.log4j.LogManager
3739
import org.apache.logging.log4j.Logger
@@ -61,6 +63,8 @@ object Lambda {
6163
.registerTypeAdapter(Block::class.java, BlockSerializer)
6264
.registerTypeAdapter(GameProfile::class.java, GameProfileSerializer)
6365
.registerTypeAdapter(Optional::class.java, OptionalSerializer)
66+
.registerTypeAdapter(ItemStack::class.java, ItemStackSerializer)
67+
.registerTypeAdapter(Text::class.java, Text.Serializer())
6468
.create()
6569

6670
fun initialize(block: (Long) -> Unit) {

common/src/main/kotlin/com/lambda/config/groups/Targeting.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import com.lambda.interaction.rotation.Rotation.Companion.dist
2424
import com.lambda.interaction.rotation.Rotation.Companion.rotation
2525
import com.lambda.interaction.rotation.Rotation.Companion.rotationTo
2626
import com.lambda.threading.runSafe
27-
import com.lambda.util.math.VecUtils.distSq
27+
import com.lambda.util.math.distSq
2828
import com.lambda.util.world.fastEntitySearch
2929
import net.minecraft.client.network.ClientPlayerEntity
3030
import net.minecraft.client.network.OtherClientPlayerEntity
@@ -41,16 +41,16 @@ import java.util.UUID
4141
* based on player settings and entity characteristics. It allows for specifying which types of entities
4242
* are targetable, the range of targeting, and various other conditions for targeting.
4343
*
44-
* @property owner The [Configurable] instance used to get and set configuration options for targeting.
45-
* @property predicate The predicate used to determine whether the targeting settings are visible and active.
46-
* @property defaultRange The default range within which entities can be targeted.
47-
* @property maxRange The maximum range within which entities can be targeted.
44+
* @param owner The [Configurable] instance used to get and set configuration options for targeting.
45+
* @param predicate The predicate used to determine whether the targeting settings are visible and active.
46+
* @param defaultRange The default range within which entities can be targeted.
47+
* @param maxRange The maximum range within which entities can be targeted.
4848
*/
4949
abstract class Targeting(
50-
owner: Configurable,
51-
predicate: () -> Boolean = { true },
52-
defaultRange: Double,
53-
maxRange: Double,
50+
private val owner: Configurable,
51+
private val predicate: () -> Boolean = { true },
52+
private val defaultRange: Double,
53+
private val maxRange: Double,
5454
) : TargetingConfig {
5555

5656
/**
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.config.serializer
19+
20+
import com.google.gson.JsonDeserializationContext
21+
import com.google.gson.JsonDeserializer
22+
import com.google.gson.JsonElement
23+
import com.google.gson.JsonObject
24+
import com.google.gson.JsonSerializationContext
25+
import com.google.gson.JsonSerializer
26+
import net.minecraft.item.ItemStack
27+
import net.minecraft.nbt.StringNbtReader
28+
import net.minecraft.nbt.visitor.StringNbtWriter
29+
import net.minecraft.registry.Registries
30+
import net.minecraft.util.Identifier
31+
import java.lang.reflect.Type
32+
33+
object ItemStackSerializer : JsonSerializer<ItemStack>, JsonDeserializer<ItemStack> {
34+
override fun serialize(
35+
stack: ItemStack,
36+
typeOfSrc: Type,
37+
context: JsonSerializationContext
38+
): JsonElement =
39+
JsonObject().apply {
40+
addProperty("id", stack.item.registryEntry.key.get().value.toString())
41+
addProperty("count", stack.count)
42+
stack.nbt?.let { addProperty("tag", StringNbtWriter().apply(it)) }
43+
}
44+
45+
override fun deserialize(
46+
json: JsonElement,
47+
typeOfT: Type,
48+
context: JsonDeserializationContext
49+
): ItemStack {
50+
val id = json.asJsonObject.get("id").asString
51+
val count = json.asJsonObject.get("count").asInt
52+
val nbt = json.asJsonObject?.get("tag")?.asString
53+
54+
val item = Registries.ITEM.get(Identifier(id))
55+
56+
return ItemStack(item, count).apply { nbt?.let { setNbt(StringNbtReader.parse(it)) } }
57+
}
58+
}

common/src/main/kotlin/com/lambda/core/TimerManager.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,33 @@ package com.lambda.core
1919

2020
import com.lambda.event.EventFlow.post
2121
import com.lambda.event.events.ClientEvent
22+
import kotlin.concurrent.fixedRateTimer
2223

2324
object TimerManager : Loadable {
2425
var lastTickLength: Float = 50f
2526

2627
override fun load() = "Loaded Timer Manager"
2728

29+
private const val TICK_DELAY = 50L
30+
private var start = 0L
31+
val fixedTickDelta get() = (System.currentTimeMillis() - start).mod(TICK_DELAY).toDouble() / TICK_DELAY
32+
33+
init {
34+
fixedRateTimer(
35+
daemon = true,
36+
name = "Scheduler-Lambda-Tick",
37+
initialDelay = 0,
38+
period = TICK_DELAY
39+
) {
40+
if (start == 0L) start = System.currentTimeMillis()
41+
ClientEvent.FixedTick(this).post()
42+
}
43+
}
44+
2845
fun getLength(): Float {
2946
var length = 50f
3047

31-
ClientEvent.Timer(1.0).post {
48+
ClientEvent.TimerUpdate(1.0).post {
3249
length /= speed.toFloat()
3350
}
3451

common/src/main/kotlin/com/lambda/event/EventFlow.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.lambda.threading.runSafe
2525
import kotlinx.coroutines.*
2626
import kotlinx.coroutines.channels.BufferOverflow
2727
import kotlinx.coroutines.flow.*
28+
import java.util.*
2829

2930

3031
/**

common/src/main/kotlin/com/lambda/event/events/ClientEvent.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
package com.lambda.event.events
1919

2020
import com.lambda.event.Event
21+
import com.lambda.event.EventFlow
2122
import com.lambda.event.callback.Cancellable
2223
import com.lambda.event.callback.ICancellable
2324
import net.minecraft.client.sound.SoundInstance
25+
import java.util.TimerTask
2426

2527
sealed class ClientEvent {
2628
/**
@@ -38,10 +40,20 @@ sealed class ClientEvent {
3840
*
3941
* @property speed The speed of the timer.
4042
*/
41-
data class Timer(var speed: Double) : Event
43+
data class TimerUpdate(var speed: Double) : Event
4244

4345
/**
4446
* Triggered before playing a sound
4547
*/
4648
data class Sound(val sound: SoundInstance) : ICancellable by Cancellable()
49+
50+
/**
51+
* Represents a fixed tick event in the application.
52+
*
53+
* A fixed tick can be used to execute a specific task consistently at regular intervals, based on the provided
54+
* timer task. This event is part of the event system and can be subscribed to for handling the specified timer task.
55+
*
56+
* @property timerTask The task that is executed during this fixed tick event.
57+
*/
58+
data class FixedTick(val timerTask: TimerTask) : Event
4759
}

common/src/main/kotlin/com/lambda/event/listener/SafeListener.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.lambda.event.Event
2222
import com.lambda.event.EventFlow
2323
import com.lambda.event.Muteable
2424
import com.lambda.threading.runConcurrent
25+
import com.lambda.threading.runGameScheduled
2526
import com.lambda.threading.runSafe
2627
import com.lambda.util.Pointer
2728
import com.lambda.util.selfReference
@@ -121,7 +122,7 @@ class SafeListener<T : Event>(
121122
noinline function: SafeContext.(T) -> Unit = {},
122123
): SafeListener<T> {
123124
val listener = SafeListener<T>(priority, this, alwaysListen) { event ->
124-
function(event)
125+
runGameScheduled { function(event) }
125126
}
126127

127128
EventFlow.syncListeners.subscribe(listener)

common/src/main/kotlin/com/lambda/graphics/renderer/esp/DynamicAABB.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717

1818
package com.lambda.graphics.renderer.esp
1919

20-
import com.lambda.util.math.VecUtils.minus
21-
import com.lambda.util.math.VecUtils.plus
22-
import com.lambda.util.extension.max
23-
import com.lambda.util.extension.min
2420
import com.lambda.util.extension.prevPos
21+
import com.lambda.util.math.minus
2522
import net.minecraft.entity.Entity
2623
import net.minecraft.util.math.Box
2724

common/src/main/kotlin/com/lambda/gui/api/LambdaGui.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.lambda.gui.api
1919

2020
import com.lambda.Lambda.mc
2121
import com.lambda.event.Muteable
22+
import com.lambda.event.events.ClientEvent
2223
import com.lambda.event.events.RenderEvent
2324
import com.lambda.event.events.TickEvent
2425
import com.lambda.event.listener.SafeListener.Companion.listen

common/src/main/kotlin/com/lambda/gui/api/component/core/DockingRect.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,15 @@ abstract class DockingRect {
5757
var screenSize: Vec2d = Vec2d.ZERO
5858

5959
var position: Vec2d
60-
get() = relativeToAbs(relativePos).coerceIn(0.0, screenSize.x - size.x, 0.0, screenSize.y - size.y)
60+
get() = relativeToAbs(relativePos)
61+
.coerceIn(0.0, screenSize.x - size.x, 0.0, screenSize.y - size.y)
6162
set(value) {
62-
relativePos = absToRelative(value.roundToStep(ClickGui.dockingGridSize)); if (autoDocking) autoDocking()
63+
relativePos = absToRelative(value.roundToStep(ClickGui.dockingGridSize))
64+
if (autoDocking) autoDocking()
6365
}
6466

65-
private val dockingOffset get() = (screenSize - size) * Vec2d(dockingH.multiplier, dockingV.multiplier)
67+
private val dockingOffset get() =
68+
(screenSize - size) * Vec2d(dockingH.multiplier, dockingV.multiplier)
6669

6770
private fun relativeToAbs(posIn: Vec2d) = posIn + dockingOffset
6871
private fun absToRelative(posIn: Vec2d) = posIn - dockingOffset

0 commit comments

Comments
 (0)