Skip to content

Commit 0130d3d

Browse files
committed
surround module
1 parent cfadaf6 commit 0130d3d

File tree

2 files changed

+79
-4
lines changed

2 files changed

+79
-4
lines changed

src/main/kotlin/com/lambda/module/modules/combat/PlayerTrap.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,12 @@ object PlayerTrap : Module(
8484
getTrapPositions(targetPlayer).associateWith { TargetState.Block(block) }
8585
}.build(finishOnDone = false).run()
8686
}
87-
8887
onDisable { task?.cancel(); task = null }
8988
}
9089

9190
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)
91+
val min = player.boundingBox.minPos.flooredBlockPos.add(-1, -1, -1)
92+
val max = player.boundingBox.maxPos.flooredBlockPos.add(1, 1, 1)
9493

9594
return buildSet {
9695
(min.x + 1..<max.x).forEach { x ->
@@ -110,7 +109,7 @@ object PlayerTrap : Module(
110109
(min.x + 1..<max.x).forEach { x ->
111110
(min.z + 1..<max.z).forEach { z ->
112111
BlockPos(x, min.y, z).let { pos ->
113-
if (pos == player.supportingBlockPos.getOrNull() && blockState(pos).isReplaceable) add(pos)
112+
if (pos != player.supportingBlockPos.getOrNull() || blockState(pos).isReplaceable) add(pos)
114113
}
115114
add(BlockPos(x, max.y, z))
116115
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.interaction.construction.blueprint.TickingBlueprint.Companion.tickingBlueprint
23+
import com.lambda.interaction.construction.verify.TargetState
24+
import com.lambda.interaction.managers.interacting.InteractConfig
25+
import com.lambda.module.Module
26+
import com.lambda.module.modules.combat.PlayerTrap.getTrapPositions
27+
import com.lambda.module.tag.ModuleTag
28+
import com.lambda.task.RootTask.run
29+
import com.lambda.task.Task
30+
import com.lambda.task.tasks.BuildTask.Companion.build
31+
import com.lambda.util.item.ItemUtils.block
32+
import com.lambda.util.player.SlotUtils.hotbarAndStorage
33+
import net.minecraft.block.Blocks
34+
import net.minecraft.item.BlockItem
35+
36+
object Surround : Module(
37+
name = "Surround",
38+
description = "Surrounds your players feet with any given block",
39+
tag = ModuleTag.COMBAT
40+
) {
41+
private val blocks by setting("Blocks", setOf(Blocks.OBSIDIAN, Blocks.ENDER_CHEST, Blocks.CRYING_OBSIDIAN))
42+
43+
private var task: Task<*>? = null
44+
45+
init {
46+
setDefaultAutomationConfig {
47+
applyEdits {
48+
buildConfig.apply {
49+
editTyped(
50+
::pathing,
51+
::stayInRange,
52+
::spleefEntities,
53+
::collectDrops
54+
) { defaultValue(false); hide() }
55+
::checkSideVisibility.edit { defaultValue(false) }
56+
}
57+
interactConfig.apply {
58+
::airPlace.edit { defaultValue(InteractConfig.AirPlaceMode.Grim) }
59+
}
60+
hideGroup(eatConfig)
61+
}
62+
}
63+
64+
onEnable {
65+
task = tickingBlueprint {
66+
val block = player.hotbarAndStorage.firstOrNull {
67+
it.item is BlockItem && blocks.contains(it.item.block)
68+
}?.item?.block ?: return@tickingBlueprint emptyMap()
69+
getTrapPositions(player)
70+
.filter { it.y <= player.blockPos.y }
71+
.associateWith { TargetState.Block(block) }
72+
}.build(finishOnDone = false).run()
73+
}
74+
onDisable { task?.cancel(); task = null }
75+
}
76+
}

0 commit comments

Comments
 (0)