Skip to content

Commit 4fd271d

Browse files
committed
Merge remote-tracking branch 'origin/refactor/ui' into refactor/ui
2 parents bb50509 + 0d3e346 commit 4fd271d

File tree

5 files changed

+100
-1
lines changed

5 files changed

+100
-1
lines changed

common/src/main/kotlin/com/lambda/config/Configurable.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import com.lambda.util.KeyCode
3737
import com.lambda.util.Nameable
3838
import net.minecraft.block.Block
3939
import net.minecraft.util.math.BlockPos
40+
import net.minecraft.util.math.Vec3d
4041
import java.awt.Color
4142

4243
/**
@@ -387,6 +388,40 @@ abstract class Configurable(
387388
visibility: () -> Boolean = { true },
388389
) = ColorSetting(name, defaultValue, description, visibility).register()
389390

391+
/**
392+
* Creates a [Vec3dSetting] with the provided parameters and adds it to the [settings].
393+
*
394+
* @param name The unique identifier for the setting.
395+
* @param defaultValue The default [Vec3d] value of the setting.
396+
* @param description A brief explanation of the setting's purpose and behavior.
397+
* @param visibility A lambda expression that determines the visibility status of the setting.
398+
*
399+
* @return The created [Vec3dSetting].
400+
*/
401+
fun setting(
402+
name: String,
403+
defaultValue: Vec3d,
404+
description: String = "",
405+
visibility: () -> Boolean = { true },
406+
) = Vec3dSetting(name, defaultValue, description, visibility).register()
407+
408+
/**
409+
* Creates a [BlockPosSetting] with the provided parameters and adds it to the [settings].
410+
*
411+
* @param name The unique identifier for the setting.
412+
* @param defaultValue The default [BlockPos.Mutable] value of the setting.
413+
* @param description A brief explanation of the setting's purpose and behavior.
414+
* @param visibility A lambda expression that determines the visibility status of the setting.
415+
*
416+
* @return The created [BlockPosSetting].
417+
*/
418+
fun setting(
419+
name: String,
420+
defaultValue: BlockPos.Mutable,
421+
description: String = "",
422+
visibility: () -> Boolean = { true },
423+
) = BlockPosSetting(name, defaultValue, description, visibility).register()
424+
390425
/**
391426
* Creates a [BlockPosSetting] with the provided parameters and adds it to the [settings].
392427
*
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.config.settings.complex
19+
20+
import com.google.gson.reflect.TypeToken
21+
import com.lambda.brigadier.argument.double
22+
import com.lambda.brigadier.argument.integer
23+
import com.lambda.brigadier.argument.value
24+
import com.lambda.brigadier.execute
25+
import com.lambda.brigadier.required
26+
import com.lambda.config.AbstractSetting
27+
import com.lambda.util.extension.CommandBuilder
28+
import net.minecraft.command.CommandRegistryAccess
29+
import net.minecraft.util.math.BlockPos
30+
import net.minecraft.util.math.Vec3d
31+
32+
class Vec3dSetting(
33+
override val name: String,
34+
defaultValue: Vec3d,
35+
description: String,
36+
visibility: () -> Boolean,
37+
) : AbstractSetting<Vec3d>(
38+
defaultValue,
39+
TypeToken.get(Vec3d::class.java).type,
40+
description,
41+
visibility
42+
) {
43+
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {
44+
required(double("X", -30000000.0, 30000000.0)) { x ->
45+
required(double("Y", -64.0, 255.0)) { y ->
46+
required(double("Z", -30000000.0, 30000000.0)) { z ->
47+
execute {
48+
trySetValue(Vec3d(x().value(), y().value(), z().value()))
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}

common/src/main/kotlin/com/lambda/module/Module.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ abstract class Module(
115115
enabledByDefault: Boolean = false,
116116
defaultKeybind: KeyCode = KeyCode.UNBOUND,
117117
) : Nameable, Muteable, Configurable(ModuleConfig) {
118-
private val isEnabledSetting = setting("Enabled", enabledByDefault, visibility = { false })
118+
private val isEnabledSetting = setting("Enabled", enabledByDefault) { false }
119119
private val keybindSetting = setting("Keybind", defaultKeybind)
120120
val isVisible = setting("Visible", true) { ModuleList.isEnabled }
121121
val reset by setting("Reset", { settings.forEach { it.reset() }; this@Module.info("Settings set to default") })

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.lambda.util
1919

20+
import net.minecraft.util.math.BlockPos
2021
import net.minecraft.util.math.Vec3d
2122
import java.time.LocalDateTime
2223
import java.time.ZoneId
@@ -39,6 +40,8 @@ object Formatting {
3940
return "(${format.format(Locale.US, x)}, ${format.format(Locale.US, y)}, ${format.format(Locale.US, z)})"
4041
}
4142

43+
fun BlockPos.asString() = "($x, $y, $z)"
44+
4245
fun getTime(formatter: DateTimeFormatter = DateTimeFormatter.RFC_1123_DATE_TIME): String {
4346
val localDateTime = LocalDateTime.now()
4447
val zoneId = ZoneId.systemDefault()

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ infix operator fun Vec3d.div(other: Double): Vec3d = times(1 / other)
8888
infix operator fun Vec3d.div(other: Float): Vec3d = times(1 / other)
8989
infix operator fun Vec3d.div(other: Int): Vec3d = times(1 / other)
9090

91+
infix operator fun ClosedRange<Double>.rangeTo(other: Double) = Vec3d(start, endInclusive, other)
92+
infix operator fun ClosedRange<Float>.rangeTo(other: Float) = Vec3d(start.toDouble(), endInclusive.toDouble(), other.toDouble())
93+
infix operator fun ClosedRange<Int>.rangeTo(other: Int) = Vec3d(start.toDouble(), endInclusive.toDouble(), other.toDouble())
94+
infix operator fun OpenEndRange<Double>.rangeTo(other: Double) = Vec3d(start, endExclusive, other)
95+
infix operator fun OpenEndRange<Float>.rangeTo(other: Float) = Vec3d(start.toDouble(), endExclusive.toDouble(), other.toDouble())
96+
infix operator fun OpenEndRange<Int>.rangeTo(other: Int) = BlockPos.Mutable(start, endExclusive, other)
97+
9198
/* Vec3i */
9299
val Vec3i.vec3d get() =
93100
Vec3d(x.toDouble(), y.toDouble(), z.toDouble())

0 commit comments

Comments
 (0)