Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 7 additions & 26 deletions common/src/main/kotlin/com/lambda/config/groups/Targeting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.lambda.interaction.rotation.Rotation.Companion.rotation
import com.lambda.interaction.rotation.Rotation.Companion.rotationTo
import com.lambda.threading.runSafe
import com.lambda.util.math.VecUtils.distSq
import com.lambda.util.world.WorldUtils.getFastEntities
import com.lambda.util.world.entitySearch
import net.minecraft.client.network.ClientPlayerEntity
import net.minecraft.entity.LivingEntity
import net.minecraft.entity.mob.MobEntity
Expand All @@ -31,16 +31,6 @@ abstract class Targeting(
override val invisible by c.setting("Invisible", true) { vis() }
override val dead by c.setting("Dead", false) { vis() }

fun getEntities(): List<LivingEntity> =
mutableListOf<LivingEntity>().apply {
runSafe {
getFastEntities(
player.pos, targetingRange, this@apply,
predicate = { entity -> validate(player, entity) }
)
}
}

open fun validate(player: ClientPlayerEntity, entity: LivingEntity) = when {
!players && entity.isPlayer -> false
!animals && entity is PassiveEntity -> false
Expand All @@ -65,24 +55,15 @@ abstract class Targeting(
}

fun getTarget(): LivingEntity? = runSafe {
var best: LivingEntity? = null
var bestFactor = Double.MAX_VALUE

val comparator = { entity: LivingEntity, _: Int ->
val factor = priority.factor(this, entity)
if (factor < bestFactor) {
best = entity
bestFactor = factor
}
}

val predicate = { entity: LivingEntity ->
validate(player, entity)
}

getFastEntities<LivingEntity>(player.pos, targetingRange, null, comparator, predicate)

return@runSafe best
return@runSafe entitySearch<LivingEntity>(targetingRange) {
predicate(it)
}.minBy {
priority.factor(this, it)
}
}
}

Expand All @@ -97,4 +78,4 @@ abstract class Targeting(
HEALTH({ it.health.toDouble() }),
FOV({ player.rotation dist player.eyePos.rotationTo(it.pos) })
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.lambda.core.annotations

import kotlin.annotation.AnnotationTarget.*

@RequiresOptIn(
message = "Only use if you know what you are doing, no support will be provided whatsoever, use at your own risk",
)
@Target(CLASS, FUNCTION, PROPERTY, ANNOTATION_CLASS, CONSTRUCTOR, PROPERTY_SETTER, PROPERTY_GETTER, TYPEALIAS)
internal annotation class InternalApi
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import com.lambda.config.groups.InteractionSettings
import com.lambda.config.groups.RotationSettings
import com.lambda.event.events.TickEvent
import com.lambda.event.listener.SafeListener.Companion.concurrentListener
import com.lambda.event.listener.SafeListener.Companion.listener
import com.lambda.module.Module
import com.lambda.module.tag.ModuleTag
import com.lambda.util.world.WorldUtils.getClosestEntity
import net.minecraft.entity.LivingEntity
import net.minecraft.util.Hand

object CrystalAura : Module(
Expand Down Expand Up @@ -56,9 +53,5 @@ object CrystalAura : Module(
/*listener<RotationEvent.Pre> { event ->
event.lookAtEntity(rotation, interac, getClosestEntity<LivingEntity>(player.eyePos, placeRange) ?: return@listener)
}*/

listener<TickEvent.Pre> {
getClosestEntity<LivingEntity>(player.eyePos, 64.0)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.lambda.module.modules.debug

import com.lambda.event.events.RenderEvent
import com.lambda.event.listener.SafeListener.Companion.listener
import com.lambda.graphics.renderer.esp.builders.build
import com.lambda.module.Module
import com.lambda.module.tag.ModuleTag
import com.lambda.util.world.blockSearch
import net.minecraft.block.Blocks
import net.minecraft.util.math.Vec3i
import java.awt.Color

object BlockTest : Module(
name = "BlockTest",
description = "BlockTest",
defaultTags = setOf(ModuleTag.DEBUG),
) {
private val rangeX by setting("Range X", 5, 1..7, 1, "Range X")
private val rangeY by setting("Range Y", 5, 1..7, 1, "Range Y")
private val rangeZ by setting("Range Z", 5, 1..7, 1, "Range Z")
private val stepX by setting("Step X", 1, 1..7, 1, "Step X")
private val stepY by setting("Step Y", 1, 1..7, 1, "Step Y")
private val stepZ by setting("Step Z", 1, 1..7, 1, "Step Z")

private val range: Vec3i
get() = Vec3i(rangeX, rangeY, rangeZ)

private val step: Vec3i
get() = Vec3i(stepX, stepY, stepZ)

private val filledColor = Color(100, 150, 255, 128)
private val outlineColor = Color(100, 150, 255, 51)

init {
listener<RenderEvent.StaticESP> {
blockSearch(range, step) { _, state ->
state.isOf(Blocks.DIAMOND_BLOCK)
}.forEach { (pos, state) ->
state.getOutlineShape(world, pos).boundingBoxes.forEach { box ->
it.renderer.build(box.offset(pos), filledColor, outlineColor)
}
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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.world.WorldUtils.getClosestEntity
import com.lambda.util.world.entitySearch
import net.minecraft.entity.LivingEntity
import net.minecraft.util.math.Box
import java.awt.Color
Expand All @@ -29,12 +29,14 @@ object RenderTest : Module(

init {
listener<RenderEvent.DynamicESP> {
val entity = getClosestEntity<LivingEntity>(player.pos, 8.0) ?: return@listener
it.renderer.build(entity.dynamicBox, filledColor, outlineColor)
entitySearch<LivingEntity>(8.0)
.forEach { entity ->
it.renderer.build(entity.dynamicBox, filledColor, outlineColor)
}
}

listener<RenderEvent.StaticESP> {
it.renderer.build(Box.of(player.pos, 0.3, 0.3, 0.3), filledColor, outlineColor)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.lambda.event.events.TickEvent
import com.lambda.event.listener.SafeListener.Companion.listener
import com.lambda.module.Module
import com.lambda.module.tag.ModuleTag
import com.lambda.util.world.WorldUtils.getEntities
import com.lambda.util.world.entitySearch
import net.minecraft.entity.passive.AbstractHorseEntity
import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket

Expand All @@ -15,38 +15,23 @@ object EntityControl : Module(
description = "Control mountable entities",
defaultTags = setOf(ModuleTag.MOVEMENT)
) {
private val page by setting("Page", Page.GENERAL)

/* General */
private val forceMount by setting("Force Mount", true, description = "Attempts to force mount chested entities.", visibility = { page == Page.GENERAL }).apply {
private val forceMount by setting("Force Mount", true, description = "Attempts to force mount chested entities.").apply {
onValueChange { _, _ ->
horses.forEach { horse -> horse.updateSaddle() }
resetMounts()
}
}

/* Movement */
private val speed by setting("Entity Speed", 2.0, 0.1..10.0, 0.1, description = "Speed for entities.", visibility = { page == Page.MOVEMENT })

private enum class Page {
GENERAL, MOVEMENT
}

private val horses = mutableListOf<AbstractHorseEntity>()
private val modified = mutableSetOf<AbstractHorseEntity>()

init {
listener<TickEvent.Pre> {
if (forceMount) {
getEntities(player.pos, 8.0, horses, { horse, _ -> horse.setHorseFlag(4, true) })
}
}

/*listener<MovementEvent.Pre> {
if (!player.isRiding) return@listener
if (!forceMount) return@listener

// We can do this because the player movement depends on the entity movement
player.vehicle?.motionX = speed
player.vehicle?.motionZ = speed
}*/
entitySearch<AbstractHorseEntity>(8.0)
.forEach {
it.setHorseFlag(4, true)
modified.add(it)
}
}

listener<PacketEvent.Send.Pre> { event ->
if (!forceMount) return@listener
Expand All @@ -60,7 +45,11 @@ object EntityControl : Module(
}

onDisable {
horses.clear()
resetMounts()
}
}

private fun resetMounts() {
modified.forEach { it.updateSaddle() }
}
}
24 changes: 7 additions & 17 deletions common/src/main/kotlin/com/lambda/module/modules/movement/Speed.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@ import com.lambda.module.Module
import com.lambda.module.tag.ModuleTag
import com.lambda.util.Nameable
import com.lambda.util.player.MovementUtils.addSpeed
import com.lambda.util.player.MovementUtils.buildMovementInput
import com.lambda.util.player.MovementUtils.calcMoveYaw
import com.lambda.util.player.MovementUtils.handledByBaritone
import com.lambda.util.player.MovementUtils.isInputting
import com.lambda.util.player.MovementUtils.mergeFrom
import com.lambda.util.player.MovementUtils.motionY
import com.lambda.util.player.MovementUtils.moveDelta
import com.lambda.util.player.MovementUtils.newMovementInput
import com.lambda.util.player.MovementUtils.roundedForward
import com.lambda.util.player.MovementUtils.roundedStrafing
import com.lambda.util.player.MovementUtils.setSpeed
import com.lambda.util.extension.contains
import com.lambda.util.world.WorldUtils.getFastEntities
import com.lambda.util.world.entitySearch
import net.minecraft.entity.LivingEntity
import net.minecraft.entity.decoration.ArmorStandEntity
import net.minecraft.entity.vehicle.BoatEntity
Expand Down Expand Up @@ -134,22 +132,14 @@ object Speed : Module(

var boostAmount = 0.0

getFastEntities<LivingEntity>(
player.pos, 3.0,
predicate = { player.boundingBox.expand(1.0) in it.boundingBox && it !is ArmorStandEntity },
iterator = { e, _ ->
val colliding = player.boundingBox in e.boundingBox
val multiplier = if (colliding) grimCollideMultiplier else 1.0
boostAmount += 0.08 * grimEntityBoost * multiplier
}
)
boostAmount += entitySearch<LivingEntity>(3.0) {
player.boundingBox.expand(1.0) in it.boundingBox && it !is ArmorStandEntity
}.sumOf { 0.08 * grimEntityBoost }

if (grimBoatBoost > 0.0) {
getFastEntities<BoatEntity>(
player.pos, 4.0,
predicate = { player.boundingBox in it.boundingBox.expand(0.01) },
iterator = { _, _ -> boostAmount += grimBoatBoost }
)
boostAmount += entitySearch<BoatEntity>(4.0) {
player.boundingBox in it.boundingBox.expand(0.01)
}.sumOf { grimBoatBoost }
}

addSpeed(boostAmount)
Expand Down
51 changes: 42 additions & 9 deletions common/src/main/kotlin/com/lambda/util/collections/Extensions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.lambda.util.collections

import kotlin.reflect.KClass

/**
* Filters elements of the iterable by their runtime type and a predicate, and adds the matching elements to the specified mutable collection.
*
Expand All @@ -20,16 +22,47 @@ inline fun <reified R, C : MutableCollection<in R>> Iterable<*>.filterPointer(
predicate: (R) -> Boolean,
) {
var index = 0
for (element in this) {
when {
element is R && predicate(element) && destination != null -> {
iterator(element, index++)
destination.add(element)
}

element is R && predicate(element) && destination == null -> {
iterator(element, index++)
}
forEach { element ->
val fulfilled = predicate(element as R)

if (fulfilled && destination != null) {
destination.add(element)
iterator(element, index)
}

index++
}
}

/**
* Filters elements of the iterable by their runtime type and a predicate, and adds the matching elements to the specified mutable collection.
*
* This function allows filtering elements of an iterable based on their runtime type and a provided predicate function.
* The elements that match both the type constraint and the predicate are added to the destination mutable collection.
* Because we do not want additional overhead, this function acts as pointer receiver to a collection.
* The predicate function determines whether an element should be included based on its type and any additional criteria.
*
* @param R The target type to filter elements to.
* @param C The type of the destination mutable collection.
* @param destination The mutable collection to which the filtered elements will be added.
* @param iterator The iterator function that processes the filtered elements and their index.
* @param predicate The predicate function that determines whether an element should be included based on its type and other criteria.
*/
inline fun <R : Any, C : MutableCollection<in R>> Iterable<*>.filterPointer(
kClass: KClass<out R>,
destination: C?,
iterator: (R) -> Unit,
predicate: (R) -> Boolean,
) {
forEach { element ->
// Cannot be replaced with reified type due to type erasure
(element as? R) ?: return@forEach
val fulfilled = kClass.isInstance(element) && predicate(element)

if (fulfilled && destination != null) {
destination.add(element)
iterator(element)
}
}
}
Loading