Skip to content

Commit eb5e2f7

Browse files
committed
Merge branch 'master' into feature/packetmine-rewrite
# Conflicts: # common/src/main/kotlin/com/lambda/module/modules/combat/KillAura.kt # common/src/main/kotlin/com/lambda/util/BlockUtils.kt
2 parents ef54193 + 2d3ed02 commit eb5e2f7

File tree

14 files changed

+388
-231
lines changed

14 files changed

+388
-231
lines changed

common/src/main/kotlin/com/lambda/config/Configuration.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,26 @@ abstract class Configuration : Jsonable {
6262
get() = File("${primary.parent}/${primary.nameWithoutExtension}-backup.${primary.extension}")
6363

6464
init {
65-
tryLoad() // ToDo: This will do at the moment but i'd like to run this at the first first loadable stage
65+
// We need to implement a dependency graph of loadables and add functions to run before
66+
// and/or after a given Loadable children class is initialized
67+
//
68+
// class Load1(
69+
// override val priority = 1000,
70+
// override val before = Load2,
71+
// ) : Loadable {}
72+
//
73+
// class Load2(
74+
// override val priority = 1000,
75+
// ) : Loadable {}
76+
//
77+
// class Load3(
78+
// override val priority = 1000,
79+
// override val after = Load2,
80+
// ) : Loadable {}
81+
//
82+
// clientLifecycle<Load2>(shift = Pre) { event -> } // Will run before Load2
83+
// clientLifecycle<Load2>(shift = Post) { event -> } // Will run after Load2
84+
listenUnsafe<ClientEvent.Startup> { tryLoad() }
6685
listenUnsafe<ClientEvent.Shutdown>(Int.MIN_VALUE) { trySave() }
6786

6887
register()

common/src/main/kotlin/com/lambda/module/modules/combat/AutoDisconnect.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ import com.lambda.sound.SoundManager.playSound
2828
import com.lambda.util.Communication
2929
import com.lambda.util.Communication.prefix
3030
import com.lambda.util.Formatting.string
31-
import com.lambda.util.combat.CombatUtils.explosionDamage
3231
import com.lambda.util.combat.CombatUtils.hasDeadlyCrystal
32+
import com.lambda.util.combat.DamageUtils.isFallDeadly
3333
import com.lambda.util.player.SlotUtils.combined
3434
import com.lambda.util.text.*
3535
import com.lambda.util.world.fastEntitySearch
3636
import net.minecraft.entity.damage.DamageSource
3737
import net.minecraft.entity.damage.DamageTypes
38-
import net.minecraft.entity.decoration.EndCrystalEntity
3938
import net.minecraft.entity.mob.CreeperEntity
4039
import net.minecraft.entity.player.PlayerEntity
4140
import net.minecraft.item.Items
@@ -49,7 +48,9 @@ object AutoDisconnect : Module(
4948
defaultTags = setOf(ModuleTag.COMBAT)
5049
) {
5150
private val health by setting("Health", true, "Disconnect from the server when health is below the set limit.")
52-
private val minimumHealth by setting("Min Health", 10, 6..36, 1, description = "Set the minimum health threshold for disconnection.", unit = " hearts") { health }
51+
private val minimumHealth by setting("Min Health", 10, 6..36, 1, "Set the minimum health threshold for disconnection.", unit = " half-hearts") { health }
52+
private val falls by setting("Falls", false, "Disconnect if the player will die of fall damage")
53+
private val fallDistance by setting("Falls Time", 10, 0..30, 1, "Number of blocks fallen before disconnecting for fall damage.", unit = " blocks") { falls }
5354
private val crystals by setting("Crystals", false, "Disconnect if an End Crystal explosion would be lethal.")
5455
private val creeper by setting("Creepers", true, "Disconnect when an ignited Creeper is nearby.")
5556
private val totem by setting("Totem", false, "Disconnect if the number of Totems of Undying is below the required amount.")
@@ -233,11 +234,18 @@ object AutoDisconnect : Module(
233234
}
234235
}),
235236
END_CRYSTAL({ crystals }, {
236-
if (hasDeadlyCrystal(1.0))
237+
if (hasDeadlyCrystal())
237238
buildText {
238239
literal("There was an end crystal close to you that would've killed you")
239240
}
240241
else null
241-
});
242+
}),
243+
FALL_DAMAGE({ falls }, {
244+
if (isFallDeadly() && player.fallDistance > fallDistance)
245+
buildText {
246+
literal("You were about to fall and die")
247+
}
248+
else null
249+
})
242250
}
243251
}
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)