Skip to content

Commit 500139c

Browse files
committed
first test for crystal aura
1 parent 25c7d85 commit 500139c

File tree

1 file changed

+81
-28
lines changed

1 file changed

+81
-28
lines changed

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

Lines changed: 81 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,56 +19,109 @@ package com.lambda.module.modules.combat
1919

2020
import com.lambda.config.groups.InteractionSettings
2121
import com.lambda.config.groups.RotationSettings
22+
import com.lambda.config.groups.Targeting
2223
import com.lambda.event.events.TickEvent
23-
import com.lambda.event.listener.SafeListener.Companion.concurrentListener
24+
import com.lambda.event.listener.SafeListener.Companion.listener
25+
import com.lambda.interaction.RotationManager.requestRotation
26+
import com.lambda.interaction.visibilty.VisibilityChecker.lookAtBlock
2427
import com.lambda.module.Module
2528
import com.lambda.module.tag.ModuleTag
29+
import com.lambda.task.tasks.BreakBlock
30+
import com.lambda.util.combat.Explosion.explosionDamage
31+
import com.lambda.util.math.VecUtils.dist
32+
import com.lambda.util.world.blockSearch
33+
import net.minecraft.block.Blocks
34+
import net.minecraft.block.SideShapeType
35+
import net.minecraft.entity.LivingEntity
2636
import net.minecraft.util.Hand
37+
import net.minecraft.util.math.BlockPos
38+
import net.minecraft.util.math.Direction
2739

2840
object CrystalAura : Module(
2941
name = "CrystalAura",
3042
description = "Automatically attacks entities with crystals",
3143
defaultTags = setOf(ModuleTag.COMBAT),
3244
) {
33-
private val page by setting("Page", Page.General)
45+
private val page by setting("Page", Page.Targeting)
46+
47+
/* Targeting */
48+
private val targeting = Targeting.Combat(this) { page == Page.Targeting }
3449

3550
/* Rotation */
36-
private val rotation = RotationSettings(this) { page == Page.Targeting }
51+
private val rotate by setting("Rotate", true) { page == Page.Rotation }
52+
private val rotation = RotationSettings(this) { page == Page.Rotation && rotate }
3753

3854
/* Placing */
39-
private val swap by setting("Swap", Hand.MAIN_HAND, "Automatically swap to crystals") { page == Page.Placing }
40-
private val multiPlace by setting("Multi Place", true, "Place multiple crystals") { page == Page.Placing }
41-
private val placeDelay by setting("Place Delay", 0, 0..20, 1, "Delay between crystal placements", unit = "ticks", visibility = { page == Page.Placing })
42-
private val placeRange by setting("Place Range", 5.0, 0.1..7.0, 0.1, "Range to place crystals from the player eyes", visibility = { page == Page.Placing })
43-
private val placeRangeWalls by setting("Place Range Walls", 3.5, 0.1..7.0, 0.1, "Range to place crystals through walls", visibility = { page == Page.Placing })
44-
private val placeMinHealth by setting("Place Min Health", 10.0, 0.0..20.0, 0.5, "Minimum health to place a crystal", visibility = { page == Page.Placing })
45-
private val placeMaxSelfDamage by setting("Place Max Self Damage", 8.0, 0.0..20.0, 0.5, "Maximum self damage to place a crystal", visibility = { page == Page.Placing })
46-
private val placeMinDamage by setting("Place Min Damage", 6.0, 0.0..20.0, 0.5, "Minimum damage to place a crystal", visibility = { page == Page.Placing })
55+
private val doPlace by setting("Do Place", true) { page == Page.Placing }
56+
private val placing = InteractionSettings(this) { page == Page.Placing }
57+
private val swap by setting("Swap", Hand.MAIN_HAND, description = "Automatically swap to place crystals") { page == Page.Placing }
58+
59+
//private val multiPlace by setting("Multi Place", true, description = "Place crystals") { page == Page.Placing }
60+
private val minSeparation by setting("Minimum Crystal Separation", 2, 1..3, 1, description = "The minimum space between crystals", unit = "blocks") { page == Page.Placing }
61+
62+
63+
private val placeDelay by setting("Place Delay", 0, 0..20, 1, description = "Delay between crystal placements", unit = "ticks") { page == Page.Placing }
64+
private val placeMinHealth by setting("Place Min Health", 10.0, 0.0..20.0, 0.5, description = "Minimum health to place a crystal") { page == Page.Placing }
65+
private val placeMaxSelfDamage by setting("Place Max Self Damage", 8.0, 0.0..20.0, 0.5, description = "Maximum self damage to place a crystal") { page == Page.Placing }
66+
private val placeMinDamage by setting("Place Min Damage", 6.0, 0.0..20.0, 0.5, description = "Minimum damage to place a crystal") { page == Page.Placing }
4767

4868
/* Exploding */
49-
private val explode by setting("Explode", true, "Explode crystals") { page == Page.Exploding }
50-
private val explodeDelay by setting("Explode Delay", 0, 0..20, 1, "Delay between crystal explosions", unit = "ticks", visibility = { page == Page.Exploding })
51-
private val explodeRange by setting("Explode Range", 5.0, 0.1..7.0, 0.1, "Range to explode crystals", visibility = { page == Page.Exploding })
52-
private val explodeRangeWalls by setting("Explode Range Walls", 3.5, 0.1..7.0, 0.1, "Range to explode crystals through walls", visibility = { page == Page.Exploding })
53-
private val preventDeath by setting("Prevent Death", true, "Prevent death from crystal explosions", visibility = { page == Page.Exploding })
54-
private val explodeMinDamage by setting("Explode Min Damage", 6.0, 0.0..20.0, 0.5, "Minimum damage to explode a crystal", visibility = { page == Page.Exploding })
55-
private val noWeakness by setting("No Weakness", true, "Switch to a weapon when you have a weakness effect", visibility = { page == Page.Exploding })
69+
private val doExplode by setting("Do Explode", true) { page == Page.Exploding }
70+
private val explodeDelay by setting("Explode Delay", 0, 0..20, 1, description = "Delay between crystal explosions", unit = "ticks") { page == Page.Exploding }
71+
private val explodeRange by setting("Explode Range", 5.0, 0.1..7.0, 0.1, description = "Range to explode crystals") { page == Page.Exploding }
72+
private val preventDeath by setting("Prevent Death", true, description = "Prevent death from crystal explosions") { page == Page.Exploding }
73+
private val explodeMinDamage by setting("Explode Min Damage", 6.0, 0.0..20.0, 0.5, description = "Minimum damage to explode a crystal") { page == Page.Exploding }
74+
private val noWeakness by setting("No Weakness", true, description = "Switch to a weapon when you have a weakness effect") { page == Page.Exploding }
5675

5776
/* Rendering */
77+
private val rendering = Targeting.ESP(this) { page == Page.Rendering }
78+
79+
val targetEntity: LivingEntity? get() = targeting.target()
80+
val validPositions = mutableListOf<BlockPos>()
5881

82+
init {
83+
BreakBlock
84+
requestRotation(
85+
onUpdate = {
86+
val blockpos =
87+
validPositions.removeFirstOrNull() ?: return@requestRotation null
88+
if (!rotate) return@requestRotation null
5989

60-
/* Interaction */
61-
private val interac = InteractionSettings(this) // Canadian interbank meme
90+
lookAtBlock(blockpos, rotation, placing)
91+
},
92+
)
6293

63-
private enum class Page {
64-
General, Targeting, Placing, Exploding, Rendering
94+
listener<TickEvent.Pre> {
95+
targetEntity?.let { target ->
96+
// TODO: If we could provide our own selector to [PlaceFinder] we could use it instead of this
97+
// Or maybe not since we want a fast way of finding the best positions
98+
validPositions.clear() // not good
99+
validPositions.addAll(
100+
blockSearch(
101+
range = placing.reach.toInt(),
102+
step = minSeparation,
103+
pos = target.blockPos, // Search around the target and not the player
104+
) { pos, state ->
105+
!state.isSideSolid(world, pos, Direction.UP, SideShapeType.FULL) &&
106+
(state.isOf(Blocks.OBSIDIAN) || state.isOf(Blocks.BEDROCK)) &&
107+
// If the distance between the player and the place position for the
108+
// target is greater than the explosion range, we cannot use said
109+
// position as it is impossible to reach
110+
player dist pos <= explodeRange
111+
}.keys
112+
.asSequence()
113+
// https://minecraft.wiki/w/Explosion#Damage
114+
.sortedByDescending { explosionDamage(it, target, 6.0) }
115+
)
116+
}
117+
}
65118
}
66119

67-
init {
68-
concurrentListener<TickEvent.Pre> {}
69-
70-
/*listener<RotationEvent.Pre> { event ->
71-
event.lookAtEntity(rotation, interac, getClosestEntity<LivingEntity>(player.eyePos, placeRange) ?: return@listener)
72-
}*/
120+
private enum class Page {
121+
Targeting,
122+
Rotation,
123+
Placing,
124+
Exploding,
125+
Rendering
73126
}
74127
}

0 commit comments

Comments
 (0)