Skip to content

Commit cfadaf6

Browse files
committed
player trap module
1 parent abe41e2 commit cfadaf6

File tree

4 files changed

+128
-8
lines changed

4 files changed

+128
-8
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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.module.modules.combat
19+
20+
import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
21+
import com.lambda.config.applyEdits
22+
import com.lambda.context.SafeContext
23+
import com.lambda.friend.FriendManager.isFriend
24+
import com.lambda.interaction.construction.blueprint.TickingBlueprint.Companion.tickingBlueprint
25+
import com.lambda.interaction.construction.verify.TargetState
26+
import com.lambda.interaction.managers.interacting.InteractConfig
27+
import com.lambda.module.Module
28+
import com.lambda.module.tag.ModuleTag
29+
import com.lambda.task.RootTask.run
30+
import com.lambda.task.Task
31+
import com.lambda.task.tasks.BuildTask.Companion.build
32+
import com.lambda.util.BlockUtils.blockState
33+
import com.lambda.util.item.ItemUtils.block
34+
import com.lambda.util.math.flooredBlockPos
35+
import com.lambda.util.player.SlotUtils.hotbarAndStorage
36+
import com.lambda.util.world.entitySearch
37+
import net.minecraft.block.Blocks
38+
import net.minecraft.client.network.OtherClientPlayerEntity
39+
import net.minecraft.entity.player.PlayerEntity
40+
import net.minecraft.item.BlockItem
41+
import net.minecraft.util.math.BlockPos
42+
import kotlin.jvm.optionals.getOrNull
43+
44+
object PlayerTrap : Module(
45+
name = "PlayerTrap",
46+
description = "Surrounds players with any given block",
47+
tag = ModuleTag.COMBAT
48+
) {
49+
private val blocks by setting("Blocks", setOf(Blocks.OBSIDIAN, Blocks.ENDER_CHEST, Blocks.CRYING_OBSIDIAN))
50+
private val friends by setting("Friends", false)
51+
private val self by setting("Self", false)
52+
53+
private var task: Task<*>? = null
54+
55+
init {
56+
setDefaultAutomationConfig {
57+
applyEdits {
58+
buildConfig.apply {
59+
editTyped(
60+
::pathing,
61+
::stayInRange,
62+
::spleefEntities,
63+
::collectDrops
64+
) { defaultValue(false); hide() }
65+
::checkSideVisibility.edit { defaultValue(false) }
66+
}
67+
interactConfig.apply {
68+
::airPlace.edit { defaultValue(InteractConfig.AirPlaceMode.Grim) }
69+
}
70+
hideGroup(eatConfig)
71+
}
72+
}
73+
74+
onEnable {
75+
task = tickingBlueprint {
76+
val block = player.hotbarAndStorage.firstOrNull {
77+
it.item is BlockItem && blocks.contains(it.item.block)
78+
}?.item?.block ?: return@tickingBlueprint emptyMap()
79+
val targetPlayer = if (self) player
80+
else entitySearch<OtherClientPlayerEntity>(
81+
buildConfig.interactReach,
82+
player.eyePos.flooredBlockPos
83+
).firstOrNull { friends || !isFriend(it.gameProfile) } ?: return@tickingBlueprint emptyMap()
84+
getTrapPositions(targetPlayer).associateWith { TargetState.Block(block) }
85+
}.build(finishOnDone = false).run()
86+
}
87+
88+
onDisable { task?.cancel(); task = null }
89+
}
90+
91+
fun SafeContext.getTrapPositions(player: PlayerEntity): Set<BlockPos> {
92+
val min = player.boundingBox.minPos.add(0.001, 0.001, 0.001).flooredBlockPos.add(-1, -1, -1)
93+
val max = player.boundingBox.maxPos.add(-0.001, -0.001, -0.001).flooredBlockPos.add(1, 1, 1)
94+
95+
return buildSet {
96+
(min.x + 1..<max.x).forEach { x ->
97+
(min.y + 1..<max.y).forEach { y ->
98+
add(BlockPos(x, y, min.z))
99+
add(BlockPos(x, y, max.z))
100+
}
101+
}
102+
103+
(min.z + 1..<max.z).forEach { z ->
104+
(min.y + 1..<max.y).forEach { y ->
105+
add(BlockPos(min.x, y, z))
106+
add(BlockPos(max.x, y, z))
107+
}
108+
}
109+
110+
(min.x + 1..<max.x).forEach { x ->
111+
(min.z + 1..<max.z).forEach { z ->
112+
BlockPos(x, min.y, z).let { pos ->
113+
if (pos == player.supportingBlockPos.getOrNull() && blockState(pos).isReplaceable) add(pos)
114+
}
115+
add(BlockPos(x, max.y, z))
116+
}
117+
}
118+
}
119+
}
120+
}

src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ object FastBreak : Module(
3434
description = "Break blocks faster.",
3535
tag = ModuleTag.PLAYER,
3636
) {
37-
private val pendingInteractions = ConcurrentLinkedQueue<BuildContext>()
37+
private val pendingActions = ConcurrentLinkedQueue<BuildContext>()
3838

3939
init {
4040
setDefaultAutomationConfig {
@@ -80,7 +80,7 @@ object FastBreak : Module(
8080
listen<PlayerEvent.Breaking.Update> { event ->
8181
event.cancel()
8282
runSafeAutomated {
83-
breakRequest(listOf(event.pos), pendingInteractions)?.submit()
83+
breakRequest(listOf(event.pos), pendingActions)?.submit()
8484
}
8585
}
8686
}

src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ object PacketMine : Module(
7272
private val startColor by setting("Start Color", Color(255, 255, 0, 60), "The color of the start (closest to breaking) of the queue") { renderQueue && dynamicColor }.group(Group.Renders)
7373
private val endColor by setting("End Color", Color(255, 0, 0, 60), "The color of the end (farthest from breaking) of the queue") { renderQueue && dynamicColor }.group(Group.Renders)
7474

75-
private val pendingInteractions = ConcurrentLinkedQueue<BuildContext>()
75+
private val pendingActions = ConcurrentLinkedQueue<BuildContext>()
7676

7777
private var breaks = 0
7878
private var itemDrops = 0
@@ -219,7 +219,7 @@ object PacketMine : Module(
219219
if (!reBreaking) {
220220
queuePositions.retainAllPositions(breakContexts)
221221
}
222-
breakRequest(breakContexts, pendingInteractions) {
222+
breakRequest(breakContexts, pendingActions) {
223223
onStart { onProgress(it) }
224224
onUpdate { onProgress(it) }
225225
onStop { removeBreak(it); breaks++ }

src/main/kotlin/com/lambda/module/modules/player/Scaffold.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ object Scaffold : Module(
4747
private val descend by setting("Descend", KeyCode.Unbound, "Lower the place position by one to allow the player to lower y level")
4848
private val descendAmount by setting("Descend Amount", 1, 1..5, 1, "The amount to lower the place position by when descending", unit = " blocks") { descend != Bind.EMPTY }
4949

50-
private val pendingInteractions = ConcurrentLinkedQueue<BuildContext>()
50+
private val pendingActions = ConcurrentLinkedQueue<BuildContext>()
5151

5252
init {
5353
setDefaultAutomationConfig {
5454
applyEdits {
5555
buildConfig.apply {
56-
editTyped(::pathing, ::stayInRange, ::collectDrops) {
56+
editTyped(::pathing, ::stayInRange, ::collectDrops, ::spleefEntities) {
5757
defaultValue(false)
5858
hide()
5959
}
@@ -77,7 +77,7 @@ object Scaffold : Module(
7777
::accessStashes
7878
)
7979
}
80-
hideAllGroupsExcept(interactConfig, rotationConfig, hotbarConfig, inventoryConfig)
80+
hideAllGroupsExcept(buildConfig, interactConfig, rotationConfig, hotbarConfig, inventoryConfig)
8181
}
8282
}
8383

@@ -91,7 +91,7 @@ object Scaffold : Module(
9191
scaffoldPositions(beneath)
9292
.associateWith { TargetState.Solid(emptySet()) }
9393
.simulate()
94-
.interactRequest(pendingInteractions)
94+
.interactRequest(pendingActions)
9595
?.submit()
9696
}
9797
}

0 commit comments

Comments
 (0)