Skip to content

Commit 1d99dc5

Browse files
committed
Added AutoTotem
1 parent 9642b08 commit 1d99dc5

File tree

1 file changed

+92
-0
lines changed
  • common/src/main/kotlin/com/lambda/module/modules/combat

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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.groups.InventorySettings
21+
import com.lambda.context.SafeContext
22+
import com.lambda.event.events.TickEvent
23+
import com.lambda.event.listener.SafeListener.Companion.listen
24+
import com.lambda.friend.FriendManager
25+
import com.lambda.interaction.material.StackSelection.Companion.select
26+
import com.lambda.interaction.material.container.ContainerManager.transfer
27+
import com.lambda.interaction.material.container.containers.OffHandContainer
28+
import com.lambda.module.Module
29+
import com.lambda.module.tag.ModuleTag
30+
import com.lambda.task.RootTask.run
31+
import com.lambda.util.Communication.info
32+
import com.lambda.util.combat.CombatUtils.hasDeadlyCrystal
33+
import com.lambda.util.combat.DamageUtils.isFallDeadly
34+
import com.lambda.util.extension.fullHealth
35+
import com.lambda.util.world.fastEntitySearch
36+
import net.minecraft.entity.mob.CreeperEntity
37+
import net.minecraft.entity.player.PlayerEntity
38+
import net.minecraft.item.Items
39+
40+
object AutoTotem : Module(
41+
name = "AutoTotem",
42+
description = "Swaps the your off-hand item to a totem",
43+
defaultTags = setOf(ModuleTag.COMBAT, ModuleTag.PLAYER),
44+
) {
45+
private val page by setting("Page", Page.General)
46+
47+
private val log by setting("Log Message", true) { page == Page.General }
48+
49+
private val minimumHealth by setting("Min Health", 10, 6..36, 1, "Set the minimum health threshold to swap", unit = " half-hearts") { page == Page.General }
50+
private val falls by setting("Falls", true, "Swap if the player will die of fall damage") { page == Page.General }
51+
private val fallDistance by setting("Falls Time", 10, 0..30, 1, "Number of blocks fallen before swapping", unit = " blocks") { page == Page.General && falls }
52+
private val crystals by setting("Crystals", true, "Swap if an End Crystal explosion would be lethal") { page == Page.General }
53+
private val creeper by setting("Creepers", true, "Swap when an ignited Creeper is nearby") { page == Page.General }
54+
private val players by setting("Players", false, "Swap if a nearby player is detected within the set distance") { page == Page.General }
55+
private val minPlayerDistance by setting("Player Distance", 64, 32..128, 4, "Set the distance to detect players to swap") { page == Page.General && players }
56+
private val friends by setting("Friends", false, "Exclude friends from triggering player-based swaps") { page == Page.General && players }
57+
58+
private val inventory = InventorySettings(this) { page == Page.Inventory }
59+
60+
init {
61+
listen<TickEvent.Pre> {
62+
if (Reason.entries.none { it.check(this) }) return@listen
63+
64+
if (!player.isHolding(Items.TOTEM_OF_UNDYING)) {
65+
Items.TOTEM_OF_UNDYING.select()
66+
.transfer(OffHandContainer, inventory)
67+
?.finally { if (log) info("Swapped the off-hand item with a totem") }
68+
?.run()
69+
}
70+
}
71+
}
72+
73+
enum class Reason(val check: SafeContext.() -> Boolean) {
74+
HEALTH({ player.fullHealth < minimumHealth }),
75+
CREEPER({ creeper && fastEntitySearch<CreeperEntity>(15.0).any {
76+
it.getClientFuseTime(mc.tickDelta) > 0.0
77+
&& it.pos.distanceTo(player.pos) <= 5.0
78+
} }),
79+
PLAYER({ players && fastEntitySearch<PlayerEntity>(minPlayerDistance.toDouble()).any { otherPlayer ->
80+
otherPlayer != player
81+
&& player.distanceTo(otherPlayer) <= minPlayerDistance
82+
&& (!friends || !FriendManager.isFriend(otherPlayer.uuid))
83+
} }),
84+
END_CRYSTAL({ crystals && hasDeadlyCrystal() }),
85+
FALL_DAMAGE({ falls && isFallDeadly() && player.fallDistance > fallDistance })
86+
}
87+
88+
enum class Page {
89+
General,
90+
Inventory,
91+
}
92+
}

0 commit comments

Comments
 (0)