Skip to content

Commit d916158

Browse files
committed
Use world utils for nuker poc
1 parent 912ea11 commit d916158

File tree

2 files changed

+39
-38
lines changed

2 files changed

+39
-38
lines changed

common/src/main/kotlin/com/lambda/module/modules/player/Nuker.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import com.lambda.module.Module
77
import com.lambda.util.Communication.info
88
import com.lambda.util.KeyCode
99
import com.lambda.util.math.VecUtils.dist
10-
import net.minecraft.util.math.BlockPos
10+
import com.lambda.util.world.WorldUtils.searchBlocks
11+
import net.minecraft.util.math.Vec3i
1112

1213
object Nuker : Module(
1314
name = "Nuker",
@@ -16,27 +17,26 @@ object Nuker : Module(
1617
) {
1718
private val flatten by setting("Flatten", true)
1819

20+
private val range = Vec3i(4, 4, 4) // TODO: Customizable
21+
1922
init {
2023
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)
24+
searchBlocks(player.blockPos, range, null,
25+
iterator = { state, pos, _ ->
26+
state.getCollisionShape(world, pos).boundingBox
27+
.getVisibleSurfaces(player.eyePos).firstOrNull()?.let {
28+
interaction.updateBlockBreakingProgress(pos, it)
29+
}
30+
this@Nuker.info("Breaking ${state.block.name.string} at $pos with hardness ${state.getHardness(world, pos)}")
31+
},
32+
) { state, pos ->
33+
state.isSolidBlock(world, pos)
2634
&& !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)}")
35+
&& (!flatten || pos.y >= player.y)
36+
//&& state.getHardness(world, pos) <= 1.0f
37+
&& state.getHardness(world, pos) > 0.0f
38+
&& player.eyePos dist pos.toCenterPos() <= interaction.reachDistance - 1
3939
}
4040
}
4141
}
42-
}
42+
}

common/src/main/kotlin/com/lambda/util/world/WorldUtils.kt

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package com.lambda.util.world
22

33
import com.lambda.context.SafeContext
44
import com.lambda.util.collections.filterPointer
5-
import com.lambda.util.math.VecUtils.distSq
65
import net.minecraft.block.Block
6+
import net.minecraft.block.BlockState
77
import net.minecraft.entity.Entity
88
import net.minecraft.fluid.Fluid
9+
import net.minecraft.fluid.FluidState
910
import net.minecraft.util.math.BlockPos
1011
import net.minecraft.util.math.ChunkSectionPos
1112
import net.minecraft.util.math.Vec3d
@@ -165,15 +166,15 @@ object WorldUtils {
165166
* @param iterator Iterator to perform operations on each block.
166167
* @param predicate Predicate to filter the blocks.
167168
*/
168-
inline fun SafeContext.searchBlock(
169+
inline fun SafeContext.searchBlocks(
169170
pos: Vec3i,
170171
rangeX: Int,
171172
rangeY: Int,
172173
rangeZ: Int,
173174
pointer: MutableList<Block>? = null,
174-
iterator: (Block, Int) -> Unit = { _, _ -> },
175-
predicate: (Block) -> Boolean = { true },
176-
) = searchBlock(pos, Vec3i(rangeX, rangeY, rangeZ), pointer, iterator, predicate)
175+
iterator: (BlockState, BlockPos, Int) -> Unit = { _, _, _ -> },
176+
predicate: (BlockState, BlockPos) -> Boolean = { _, _ -> true },
177+
) = searchBlocks(pos, Vec3i(rangeX, rangeY, rangeZ), pointer, iterator, predicate)
177178

178179
/**
179180
* Returns all the position within the range where the predicate is true.
@@ -184,18 +185,18 @@ object WorldUtils {
184185
* @param iterator Iterator to perform operations on each block.
185186
* @param predicate Predicate to filter the blocks.
186187
*/
187-
inline fun SafeContext.searchBlock(
188+
inline fun SafeContext.searchBlocks(
188189
pos: Vec3i,
189190
range: Vec3i,
190191
pointer: MutableList<Block>? = null,
191-
iterator: (Block, Int) -> Unit = { _, _ -> },
192-
predicate: (Block) -> Boolean = { true },
192+
iterator: (BlockState, BlockPos, Int) -> Unit = { _, _, _ -> },
193+
predicate: (BlockState, BlockPos) -> Boolean = { _, _ -> true },
193194
) {
194195
iteratePositions(pos, range) { blockPos, index ->
195-
val block = world.getBlockState(blockPos).block
196-
if (predicate(block)) {
197-
pointer?.add(block)
198-
iterator(block, index)
196+
val state = world.getBlockState(blockPos)
197+
if (predicate(state, blockPos)) {
198+
pointer?.add(state.block)
199+
iterator(state, blockPos, index)
199200
}
200201
}
201202
}
@@ -209,18 +210,18 @@ object WorldUtils {
209210
* @param iterator Iterator to perform operations on each fluid.
210211
* @param predicate Predicate to filter the fluids.
211212
*/
212-
inline fun <reified T : Fluid> SafeContext.searchFluid(
213+
inline fun <reified T : Fluid> SafeContext.searchFluids(
213214
pos: Vec3i,
214215
range: Vec3i,
215216
pointer: MutableList<T>? = null,
216-
iterator: (T, Int) -> Unit = { _, _ -> },
217-
predicate: (T) -> Boolean = { true },
217+
iterator: (FluidState, BlockPos, Int) -> Unit = { _, _, _ -> },
218+
predicate: (FluidState, BlockPos) -> Boolean = { _, _ -> true },
218219
) {
219220
iteratePositions(pos, range) { blockPos, index ->
220-
val fluid = world.getFluidState(blockPos).fluid as? T ?: return@iteratePositions
221-
if (predicate(fluid)) {
222-
pointer?.add(fluid)
223-
iterator(fluid, index)
221+
val state = world.getFluidState(blockPos)
222+
if (predicate(state, blockPos)) {
223+
pointer?.add(state.fluid as? T ?: return@iteratePositions)
224+
iterator(state, blockPos, index)
224225
}
225226
}
226227
}

0 commit comments

Comments
 (0)