Skip to content

Commit e713622

Browse files
committed
Reformat utils
1 parent 32b691e commit e713622

File tree

10 files changed

+51
-49
lines changed

10 files changed

+51
-49
lines changed

common/src/main/kotlin/com/lambda/util/FolderRegister.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ package com.lambda.util
1919

2020
import com.lambda.Lambda.mc
2121
import com.lambda.core.Loadable
22+
import com.lambda.util.FolderRegister.config
23+
import com.lambda.util.FolderRegister.lambda
24+
import com.lambda.util.FolderRegister.minecraft
25+
import com.lambda.util.FolderRegister.packetLogs
26+
import com.lambda.util.FolderRegister.replay
2227
import com.lambda.util.StringUtils.sanitizeForFilename
2328
import java.io.File
2429
import java.net.InetSocketAddress
2530
import java.nio.file.Path
26-
import kotlin.io.path.*
27-
import kotlin.math.min
31+
import kotlin.io.path.createDirectories
32+
import kotlin.io.path.notExists
2833

2934
/**
3035
* The [FolderRegister] object is responsible for managing the directory structure of the application.

common/src/main/kotlin/com/lambda/util/Mouse.kt

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

2020
import org.lwjgl.glfw.GLFW
21-
import kotlin.jvm.Throws
2221

2322
class Mouse {
2423
enum class Button(val key: Int) {

common/src/main/kotlin/com/lambda/util/VarIntIterator.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717

1818
package com.lambda.util
1919

20-
import java.util.NoSuchElementException
21-
2220
class VarIntIterator(
2321
private val bytes: ByteArray,
2422
private val bitsPerEntry: Int = 7,
25-
private val maxGroups: Int = 5
23+
private val maxGroups: Int = 5,
2624
) : Iterator<Int> {
2725
private var index: Int = 0
2826

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fun StructureTemplate.readSpongeOrException(
8383
fun StructureTemplate.readSchematicOrException(
8484
lookup: RegistryEntryLookup<Block>,
8585
nbt: NbtCompound,
86-
): Throwable? = when (nbt.getString("Materials")) {
86+
): Throwable = when (nbt.getString("Materials")) {
8787
"Alpha" -> IllegalStateException("Not implemented, you can help us by contributing to the project")
8888
"Classic" -> IllegalStateException("Method not implemented, you can help us by contributing to the Minecraft Wiki (https://minecraft.wiki/w/Data_values_(Classic))")
8989
"Pocket" -> IllegalStateException("Pocket Edition schematics are not supported")
@@ -121,24 +121,24 @@ private fun StructureTemplate.readSpongeV1OrException(
121121
palette.keys
122122
.sortedBy { palette.getInt(it) }
123123
.forEach { key ->
124-
val resource = key.substringBefore('[')
125-
val blockState = NbtCompound()
126-
127-
// Why ?
128-
// I know it's supposed to be SNBT, but it cannot be parsed back
129-
key.substringAfter('[')
130-
.substringBefore(']')
131-
.takeIf { it != resource }
132-
?.split(',')
133-
?.associate { it.substringBefore('=') to it.substringAfter('=') }
134-
?.forEach { (key, value) -> blockState.putString(key, value) }
135-
136-
// Populate the list using the correct indices
137-
newPalette.add(NbtCompound().apply {
138-
putString("Name", resource)
139-
put("Properties", blockState)
140-
})
141-
}
124+
val resource = key.substringBefore('[')
125+
val blockState = NbtCompound()
126+
127+
// Why ?
128+
// I know it's supposed to be SNBT, but it cannot be parsed back
129+
key.substringAfter('[')
130+
.substringBefore(']')
131+
.takeIf { it != resource }
132+
?.split(',')
133+
?.associate { it.substringBefore('=') to it.substringAfter('=') }
134+
?.forEach { (key, value) -> blockState.putString(key, value) }
135+
136+
// Populate the list using the correct indices
137+
newPalette.add(NbtCompound().apply {
138+
putString("Name", resource)
139+
put("Properties", blockState)
140+
})
141+
}
142142

143143
val newBlocks = NbtList()
144144
var blockIndex = 0
@@ -181,6 +181,6 @@ private fun StructureTemplate.readSpongeV3OrException(
181181
fun StructureTemplate.readLitematicaOrException(
182182
lookup: RegistryEntryLookup<Block>,
183183
nbt: NbtCompound,
184-
): Throwable? {
184+
): Throwable {
185185
return IllegalStateException("Litematica parsing is not implemented")
186186
}

common/src/main/kotlin/com/lambda/util/math/VecUtils.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ package com.lambda.util.math
1919

2020
import com.lambda.util.math.MathUtils.sq
2121
import net.minecraft.entity.Entity
22-
import net.minecraft.util.math.BlockPos
23-
import net.minecraft.util.math.Direction
24-
import net.minecraft.util.math.EightWayDirection
25-
import net.minecraft.util.math.Vec3d
26-
import net.minecraft.util.math.Vec3i
22+
import net.minecraft.util.math.*
2723
import kotlin.math.pow
2824
import kotlin.math.roundToInt
2925
import kotlin.math.sqrt
@@ -44,11 +40,15 @@ object VecUtils {
4440
fun EightWayDirection.rotateClockwise(steps: Int) =
4541
EightWayDirection.entries[(ordinal + steps) % 8]
4642

47-
fun Vec3d.approximate(other: Vec3d, precision: Double = 2.0E-4): Boolean = (subtract(other) distSq Vec3d.ZERO) > precision.pow(2)
43+
fun Vec3d.approximate(other: Vec3d, precision: Double = 2.0E-4): Boolean =
44+
(subtract(other) distSq Vec3d.ZERO) > precision.pow(2)
45+
4846
infix fun Vec3d.dist(other: Vec3d): Double = sqrt(this distSq other)
4947
infix fun Vec3d.dist(other: Vec3i): Double = sqrt(this distSq other)
5048
infix fun Vec3d.distSq(other: Vec3d): Double = this.squaredDistanceTo(other)
51-
infix fun Vec3d.distSq(other: Vec3i): Double = this.squaredDistanceTo(other.x.toDouble(), other.y.toDouble(), other.z.toDouble())
49+
infix fun Vec3d.distSq(other: Vec3i): Double =
50+
this.squaredDistanceTo(other.x.toDouble(), other.y.toDouble(), other.z.toDouble())
51+
5252
infix operator fun Vec3d.plus(other: Vec3d): Vec3d = this.add(other)
5353
infix operator fun Vec3d.minus(other: Vec3d): Vec3d = this.subtract(other)
5454
infix operator fun Vec3d.times(other: Vec3d): Vec3d = this.multiply(other)

common/src/main/kotlin/com/lambda/util/player/MovementUtils.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ object MovementUtils {
4343

4444
fun SafeContext.newMovementInput(
4545
assumeBaritoneUsage: Boolean = true,
46-
slowDownCheck: Boolean = true
46+
slowDownCheck: Boolean = true,
4747
): Input = if (assumeBaritoneUsage && player.input.handledByBaritone) {
4848
player.input
4949
} else {
@@ -61,7 +61,7 @@ object MovementUtils {
6161
forward: Double,
6262
strafe: Double,
6363
jump: Boolean = false,
64-
sneak: Boolean = false
64+
sneak: Boolean = false,
6565
) = Input().apply {
6666
movementForward = forward.toFloat()
6767
movementSideways = strafe.toFloat()
@@ -109,26 +109,26 @@ object MovementUtils {
109109

110110
private fun inputMoveOffset(
111111
moveForward: Double,
112-
moveStrafe: Double
112+
moveStrafe: Double,
113113
) = atan2(-moveStrafe, moveForward)
114114

115115
fun SafeContext.calcMoveYaw(
116116
yawIn: Float = player.moveYaw,
117117
moveForward: Double = player.input.roundedForward,
118-
moveStrafe: Double = player.input.roundedStrafing
118+
moveStrafe: Double = player.input.roundedStrafing,
119119
) = yawIn + inputMoveOffset(moveForward, moveStrafe).toDegree()
120120

121121
fun SafeContext.calcMoveRad(
122122
yawIn: Float = player.moveYaw,
123123
moveForward: Double = player.input.roundedForward,
124-
moveStrafe: Double = player.input.roundedStrafing
124+
moveStrafe: Double = player.input.roundedStrafing,
125125
) = yawIn.toRadian() + inputMoveOffset(moveForward, moveStrafe)
126126

127127
fun SafeContext.movementVector(radDir: Double = calcMoveRad(), y: Double = 0.0) =
128128
Vec3d(-sin(radDir), y, cos(radDir))
129129

130130
var Entity.motion
131-
get() = velocity;
131+
get() = velocity
132132
set(value) {
133133
velocity = value
134134
}

common/src/main/kotlin/com/lambda/util/player/prediction/PredictionTick.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ data class PredictionTick(
4040
val eyePos: Vec3d,
4141
val onGround: Boolean,
4242
val isJumping: Boolean,
43-
val predictionEntity: PredictionEntity
43+
val predictionEntity: PredictionEntity,
4444
) {
4545
fun next() = skipTicks(1)
4646

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class BlockDsl(
5656
pos: BlockPos,
5757
private val range: Vec3i,
5858
private val step: Vec3i,
59-
private val predicate: (BlockPos, BlockState) -> Boolean
59+
private val predicate: (BlockPos, BlockState) -> Boolean,
6060
) {
6161
private val fastVector = pos.toFastVec()
6262
private val receiver: MutableMap<FastVector, BlockState> = mutableMapOf()
@@ -87,7 +87,7 @@ fun SafeContext.blockSearch(
8787
range: Vec3i,
8888
step: Vec3i = Vec3i(1, 1, 1),
8989
pos: BlockPos = player.blockPos,
90-
predicate: (BlockPos, BlockState) -> Boolean = { _, _ -> true }
90+
predicate: (BlockPos, BlockState) -> Boolean = { _, _ -> true },
9191
): Map<BlockPos, BlockState> =
9292
BlockDsl(this, pos, range, step, predicate).build()
9393

@@ -104,6 +104,6 @@ fun SafeContext.blockSearch(
104104
range: Int,
105105
step: Int = 1,
106106
pos: BlockPos = player.blockPos,
107-
predicate: (BlockPos, BlockState) -> Boolean = { _, _ -> true }
107+
predicate: (BlockPos, BlockState) -> Boolean = { _, _ -> true },
108108
): Map<BlockPos, BlockState> =
109109
blockSearch(Vec3i(range, range, range), Vec3i(step, step, step), pos, predicate)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class EntityDsl<T : Entity>(
5959
private val kClass: KClass<out T>,
6060
pos: BlockPos,
6161
private val range: Double,
62-
private val predicate: (T) -> Boolean
62+
private val predicate: (T) -> Boolean,
6363
) {
6464
private val fastVector = pos.toFastVec()
6565
private val receiver: MutableList<T> = mutableListOf()
@@ -97,7 +97,7 @@ class EntityDsl<T : Entity>(
9797
inline fun <reified T : Entity> SafeContext.entitySearch(
9898
range: Double,
9999
pos: BlockPos = player.blockPos,
100-
noinline predicate: (T) -> Boolean = { true }
100+
noinline predicate: (T) -> Boolean = { true },
101101
): List<T> = EntityDsl(this, T::class, pos, range, predicate).build()
102102

103103
/**
@@ -112,5 +112,5 @@ inline fun <reified T : Entity> SafeContext.entitySearch(
112112
inline fun <reified T : Entity> SafeContext.fastEntitySearch(
113113
range: Double,
114114
pos: BlockPos = player.blockPos,
115-
noinline predicate: (T) -> Boolean = { true }
115+
noinline predicate: (T) -> Boolean = { true },
116116
): List<T> = EntityDsl(this, T::class, pos, range, predicate).buildFast()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class FluidDsl<T : Fluid>(
6363
pos: BlockPos,
6464
private val range: Vec3i,
6565
private val step: Vec3i,
66-
private val predicate: (BlockPos, FluidState) -> Boolean
66+
private val predicate: (BlockPos, FluidState) -> Boolean,
6767
) {
6868
private val fastVector = pos.toFastVec()
6969
private val receiver: MutableMap<FastVector, T> = mutableMapOf()
@@ -95,7 +95,7 @@ inline fun <reified T : Fluid> SafeContext.fluidSearch(
9595
range: Vec3i,
9696
step: Vec3i,
9797
pos: BlockPos = player.blockPos,
98-
noinline predicate: (BlockPos, FluidState) -> Boolean
98+
noinline predicate: (BlockPos, FluidState) -> Boolean,
9999
): Map<BlockPos, T> = FluidDsl(this, T::class, pos, range, step, predicate).build()
100100

101101
/**
@@ -111,5 +111,5 @@ inline fun <reified T : Fluid> SafeContext.fluidSearch(
111111
range: Int,
112112
step: Int,
113113
pos: BlockPos = player.blockPos,
114-
noinline predicate: (BlockPos, FluidState) -> Boolean
114+
noinline predicate: (BlockPos, FluidState) -> Boolean,
115115
): Map<BlockPos, T> = fluidSearch(Vec3i(range, range, range), Vec3i(step, step, step), pos, predicate)

0 commit comments

Comments
 (0)