@@ -2,10 +2,11 @@ package com.lambda.util.world
22
33import com.lambda.context.SafeContext
44import com.lambda.util.collections.filterPointer
5- import com.lambda.util.math.VecUtils.distSq
65import net.minecraft.block.Block
6+ import net.minecraft.block.BlockState
77import net.minecraft.entity.Entity
88import net.minecraft.fluid.Fluid
9+ import net.minecraft.fluid.FluidState
910import net.minecraft.util.math.BlockPos
1011import net.minecraft.util.math.ChunkSectionPos
1112import 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