Skip to content

Commit 7a48550

Browse files
committed
Feature: Horse utils
1 parent 51c5c3c commit 7a48550

File tree

3 files changed

+66
-7
lines changed

3 files changed

+66
-7
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.lambda.module.modules.movement
2+
3+
import com.lambda.event.events.PacketEvent
4+
import com.lambda.event.events.TickEvent
5+
import com.lambda.event.listener.SafeListener.Companion.listener
6+
import com.lambda.module.Module
7+
import com.lambda.module.tag.ModuleTag
8+
import com.lambda.util.world.EntityUtils.getEntities
9+
import net.minecraft.entity.passive.AbstractHorseEntity
10+
import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket
11+
12+
object HorseUtils : Module(
13+
name = "HorseUtils",
14+
description = "Various utilities for horses.",
15+
defaultTags = setOf(ModuleTag.MOVEMENT, ModuleTag.BYPASS)
16+
) {
17+
private val page by setting("Page", Page.General)
18+
19+
/* General */
20+
private val forceMount by setting("Force Mount", true, description = "Attempts to force mount chested entities.", visibility = { page == Page.General })
21+
private val tameHorses by setting("Tame Horses", true, description = "Automatically tames horses (client-side only).", visibility = { page == Page.General })
22+
23+
/* Rendering */
24+
private val showInfo by setting("Show Info", true, description = "Renders information about entities.", visibility = { page == Page.Rendering })
25+
26+
private val theHonses = mutableListOf<AbstractHorseEntity>() // Petah, the honse is here
27+
private val tame: (AbstractHorseEntity) -> Unit = { horse -> if (tameHorses) horse.setHorseFlag(4, true) }
28+
29+
private enum class Page {
30+
General, Rendering
31+
}
32+
33+
init {
34+
listener<TickEvent.Pre> {
35+
getEntities(theHonses, iterator = tame)
36+
}
37+
38+
listener<PacketEvent.Send.Pre> { event ->
39+
if (!forceMount) return@listener
40+
if (event.packet !is PlayerInteractEntityC2SPacket) return@listener
41+
if (event.packet.type !is PlayerInteractEntityC2SPacket.InteractAtHandler) return@listener
42+
43+
val entity = world.getEntityById(event.packet.entityId) ?: return@listener
44+
if (entity !is AbstractHorseEntity) return@listener
45+
46+
event.cancel()
47+
}
48+
}
49+
}

common/src/main/kotlin/com/lambda/util/world/EntityUtils.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import net.minecraft.util.math.ChunkSectionPos
77
import net.minecraft.util.math.Vec3d
88
import kotlin.math.ceil
99

10+
val nullptr = null
1011

1112
object EntityUtils {
1213
/**
@@ -34,9 +35,8 @@ object EntityUtils {
3435
}
3536

3637
// Speculative execution trolling
37-
val entities = ArrayList<T>()
38-
if (range > 64) getEntities(entities, predicate, iterator)
39-
else getFastEntities(pos, range, entities, predicate, iterator)
38+
if (range > 64) getEntities(nullptr, predicate, iterator)
39+
else getFastEntities(pos, range, nullptr, predicate, iterator)
4040

4141
return closest
4242
}
@@ -65,14 +65,16 @@ object EntityUtils {
6565
*
6666
* @param pos The position to search from.
6767
* @param distance The maximum distance to search for entities.
68+
* @param pointer The mutable list to store the entities in.
6869
* @param predicate Optional predicate to filter entities. It allows custom filtering based on entity properties.
70+
* @param iterator Optional iterator to perform operations on each entity.
6971
* @return A list of entities of type [T] within the specified distance from the position, excluding the player.
7072
*
7173
*/
7274
inline fun <reified T : Entity> SafeContext.getFastEntities(
7375
pos: Vec3d,
7476
distance: Double,
75-
pointer: MutableList<T>? = null,
77+
pointer: MutableList<T>? = nullptr,
7678
noinline predicate: (T) -> Boolean = { true },
7779
noinline iterator: (T) -> Unit = { },
7880
) {
@@ -103,11 +105,12 @@ object EntityUtils {
103105
* This function retrieves entities of type [T] within a specified distance from a given position. Unlike
104106
* [getFastEntities], it traverses all entities in the world to find matches, while also excluding the player entity.
105107
*
106-
* @param predicate Optional predicate to filter entities.
107-
* @return A list of entities of type [T] within the specified distance from the position without the player.
108+
* @param pointer The mutable list to store the entities in.
109+
* @param predicate Optional predicate to filter entities. It allows custom filtering based on entity properties.
110+
* @param iterator Optional iterator to perform operations on each entity.
108111
*/
109112
inline fun <reified T : Entity> SafeContext.getEntities(
110-
pointer: MutableList<T>? = null,
113+
pointer: MutableList<T>? = nullptr,
111114
noinline predicate: (T) -> Boolean = { true },
112115
noinline iterator: (T) -> Unit = { },
113116
) {

common/src/main/resources/lambda.accesswidener

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ accessible field net/minecraft/client/world/ClientWorld entityManager Lnet/minec
1111
# Entity
1212
accessible field net/minecraft/entity/projectile/FireworkRocketEntity shooter Lnet/minecraft/entity/LivingEntity;
1313
accessible method net/minecraft/entity/Entity movementInputToVelocity (Lnet/minecraft/util/math/Vec3d;FF)Lnet/minecraft/util/math/Vec3d;
14+
accessible method net/minecraft/entity/passive/AbstractHorseEntity setHorseFlag (IZ)V
1415

1516
# Camera
1617
accessible method net/minecraft/client/render/Camera setPos (DDD)V
@@ -34,6 +35,12 @@ accessible field net/minecraft/text/Style insertion Ljava/lang/String;
3435
accessible field net/minecraft/text/Style font Lnet/minecraft/util/Identifier;
3536
accessible method net/minecraft/text/Style <init> (Lnet/minecraft/text/TextColor;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Lnet/minecraft/text/ClickEvent;Lnet/minecraft/text/HoverEvent;Ljava/lang/String;Lnet/minecraft/util/Identifier;)V
3637

38+
# Packet
39+
accessible field net/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket entityId I
40+
accessible field net/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket type Lnet/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket$InteractTypeHandler;
41+
accessible class net/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket$InteractTypeHandler
42+
accessible class net/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket$InteractAtHandler
43+
3744
# Other
3845
accessible field net/minecraft/client/world/ClientEntityManager cache Lnet/minecraft/world/entity/SectionedEntityCache;
3946
accessible field net/minecraft/world/entity/EntityTrackingSection collection Lnet/minecraft/util/collection/TypeFilterableList;

0 commit comments

Comments
 (0)