Skip to content

Commit 1fc3ad0

Browse files
committed
Reworked world utils
1 parent cfc64ec commit 1fc3ad0

File tree

5 files changed

+111
-262
lines changed

5 files changed

+111
-262
lines changed

common/src/main/kotlin/com/lambda/core/annotations/InternalApi.kt

Lines changed: 0 additions & 33 deletions
This file was deleted.

common/src/main/kotlin/com/lambda/util/extension/Collections.kt

Lines changed: 0 additions & 43 deletions
This file was deleted.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ internal const val MIN_Z = -(1L shl Z_BITS - 1)
5050
internal const val MAX_X = (1L shl X_BITS - 1) - 1L
5151
internal const val MAX_Z = (1L shl Z_BITS - 1) - 1L
5252

53+
/**
54+
* Serialized representation of (1, 1, 1)
55+
*/
56+
const val F_ONE = 274945015809L
57+
5358
/**
5459
* Creates a new position from the given coordinates.
5560
*/

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package com.lambda.util.world
1919

2020
import com.lambda.context.SafeContext
21-
import com.lambda.core.annotations.InternalApi
2221
import com.lambda.util.math.distSq
2322
import com.lambda.util.world.WorldUtils.internalGetBlockEntities
2423
import com.lambda.util.world.WorldUtils.internalGetEntities
@@ -57,7 +56,6 @@ annotation class BlockMarker
5756
*
5857
* @return A map of positions to block states
5958
*/
60-
@OptIn(InternalApi::class)
6159
@BlockMarker
6260
fun SafeContext.blockSearch(
6361
range: Vec3i,
@@ -118,7 +116,6 @@ annotation class BlockEntityMarker
118116
* @param pos The position to start the search from
119117
* @param filter The predicate to filter entities
120118
*/
121-
@OptIn(InternalApi::class)
122119
@BlockEntityMarker
123120
inline fun <reified T : BlockEntity> SafeContext.blockEntitySearch(
124121
range: Double = 64.0,
@@ -170,13 +167,12 @@ inline fun <reified T : Entity> SafeContext.closestEntity(
170167
*
171168
* @return A list of entity [T]
172169
*/
173-
@OptIn(InternalApi::class)
174170
@EntityMarker
175171
inline fun <reified T : Entity> SafeContext.entitySearch(
176172
range: Double,
177173
pos: BlockPos = player.blockPos,
178174
noinline filter: (T) -> Boolean = { true },
179-
) = internalGetEntities<T>(pos.toFastVec(), range, predicate = filter)
175+
) = internalGetEntities<T>(pos.toFastVec(), range, filter = filter)
180176

181177
/**
182178
* Initiates an optimized entity search operation in the world at the specified position
@@ -193,15 +189,14 @@ inline fun <reified T : Entity> SafeContext.entitySearch(
193189
* @param pos The position to start the search from
194190
* @param filter The predicate to filter entities
195191
*
196-
* @return A list of entity [T]
192+
* @return A sequence of [T]
197193
*/
198-
@OptIn(InternalApi::class)
199194
@EntityMarker
200195
inline fun <reified T : Entity> SafeContext.fastEntitySearch(
201196
range: Double,
202197
pos: BlockPos = player.blockPos,
203198
noinline filter: (T) -> Boolean = { true },
204-
) = internalGetFastEntities<T>(pos.toFastVec(), range, predicate = filter).toSet()
199+
) = internalGetFastEntities<T>(pos.toFastVec(), range, filter = filter)
205200

206201
@DslMarker
207202
annotation class FluidMarker
@@ -227,21 +222,19 @@ annotation class FluidMarker
227222
*
228223
* @return A map of positions to fluid states
229224
*/
230-
@OptIn(InternalApi::class)
231225
@FluidMarker
232226
inline fun <reified T : Fluid> SafeContext.fluidSearch(
233227
range: Vec3i,
234228
pos: BlockPos = player.blockPos,
235229
step: Vec3i = Vec3i(1, 1, 1),
236-
noinline filter: (BlockPos, FluidState) -> Boolean,
230+
noinline filter: (BlockPos, FluidState) -> Boolean = { _, _ -> true },
237231
) =
238232
internalSearchFluids<T>(
239233
pos.toFastVec(),
240234
range.toFastVec(),
241235
step.toFastVec()
242-
) { fastPos, state ->
243-
filter(fastPos.toBlockPos(), state)
244-
}.mapKeys { it.key.toBlockPos() }
236+
) { pos, state -> filter(pos.toBlockPos(), state) }
237+
.mapKeys { it.key.toBlockPos() }
245238

246239
/**
247240
* Searches for fluids in the world

0 commit comments

Comments
 (0)