Skip to content

Commit 5a46861

Browse files
committed
Nuker
1 parent 5fb2d76 commit 5a46861

File tree

2 files changed

+48
-12
lines changed

2 files changed

+48
-12
lines changed

common/src/main/kotlin/com/lambda/interaction/visibilty/VisibilityChecker.kt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ object VisibilityChecker {
8383
check: (Vec3d) -> Unit,
8484
) {
8585
val shrunk = box.expand(-0.005)
86-
getVisibleSurfaces(box)
86+
box.getVisibleSurfaces(player.eyePos)
8787
.forEach { side ->
8888
if (sides.isNotEmpty() && side !in sides) {
8989
return@forEach
@@ -118,17 +118,11 @@ object VisibilityChecker {
118118
Direction.EAST -> doubleArrayOf(maxX, minY, minZ, maxX, maxY, maxZ)
119119
}
120120

121-
private fun SafeContext.getVisibleSurfaces(box: Box): Set<Direction> {
122-
val visibleSides = EnumSet.noneOf(Direction::class.java)
123-
124-
val eyePos = player.eyePos
125-
val center = box.center
126-
127-
return visibleSides
128-
.checkAxis(eyePos.x - center.x, box.lengthX / 2, Direction.WEST, Direction.EAST)
129-
.checkAxis(eyePos.y - center.y, box.lengthY / 2, Direction.DOWN, Direction.UP)
130-
.checkAxis(eyePos.z - center.z, box.lengthZ / 2, Direction.NORTH, Direction.SOUTH)
131-
}
121+
fun Box.getVisibleSurfaces(eyes: Vec3d) =
122+
EnumSet.noneOf(Direction::class.java)
123+
.checkAxis(eyes.x - center.x, lengthX / 2, Direction.WEST, Direction.EAST)
124+
.checkAxis(eyes.y - center.y, lengthY / 2, Direction.DOWN, Direction.UP)
125+
.checkAxis(eyes.z - center.z, lengthZ / 2, Direction.NORTH, Direction.SOUTH)
132126

133127
private fun EnumSet<Direction>.checkAxis(
134128
diff: Double,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.lambda.module.modules.player
2+
3+
import com.lambda.event.events.TickEvent
4+
import com.lambda.event.listener.SafeListener.Companion.listener
5+
import com.lambda.interaction.visibilty.VisibilityChecker.getVisibleSurfaces
6+
import com.lambda.module.Module
7+
import com.lambda.util.Communication.info
8+
import com.lambda.util.KeyCode
9+
import com.lambda.util.math.VecUtils.dist
10+
import net.minecraft.util.math.BlockPos
11+
12+
object Nuker : Module(
13+
name = "Nuker",
14+
description = "Breaks blocks around you",
15+
defaultKeybind = KeyCode.Comma
16+
) {
17+
private val flatten by setting("Flatten", true)
18+
19+
init {
20+
listener<TickEvent.Pre> {
21+
BlockPos.iterateOutwards(player.blockPos, 4, 4, 4).map {
22+
it.toImmutable()
23+
}.filter {
24+
val state = world.getBlockState(it)
25+
state.isSolidBlock(world, it)
26+
&& !state.isAir
27+
&& (!flatten || it.y >= player.y)
28+
&& /*state.getHardness(world, it) <= 1.0f &&*/ state.getHardness(world, it) > 0.0f
29+
&& player.eyePos dist it.toCenterPos() <= interaction.reachDistance - 1
30+
}.sortedBy {
31+
player.eyePos dist it.toCenterPos()
32+
}.forEach { pos ->
33+
val state = world.getBlockState(pos)
34+
state.getCollisionShape(world, pos).boundingBox
35+
.getVisibleSurfaces(player.eyePos).firstOrNull()?.let {
36+
interaction.updateBlockBreakingProgress(pos, it)
37+
}
38+
this@Nuker.info("Breaking ${state.block.name.string} at $pos with hardness ${state.getHardness(world, pos)}")
39+
}
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)