Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/kotlin/com/lambda/config/Setting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@ class Setting<T : SettingCore<R>, R>(
buttonMenu = menu
}

fun trySetValue(newValue: R) {
fun trySetValue(newValue: R, logResponse: Boolean = true) {
if (newValue == value) {
ConfigCommand.info(notChangedMessage())
if (logResponse) ConfigCommand.info(notChangedMessage())
} else {
val previous = value
value = newValue
ConfigCommand.info(setMessage(previous, newValue))
if (logResponse) ConfigCommand.info(setMessage(previous, newValue))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ import com.lambda.brigadier.argument.integer
import com.lambda.brigadier.argument.value
import com.lambda.brigadier.execute
import com.lambda.brigadier.required
import com.lambda.command.commands.ConfigCommand
import com.lambda.config.Setting
import com.lambda.config.SettingCore
import com.lambda.gui.dsl.ImGuiBuilder
import com.lambda.threading.runSafe
import com.lambda.util.BlockUtils.blockPos
import com.lambda.util.Communication.info
import com.lambda.util.extension.CommandBuilder
import com.lambda.util.world.raycast.RayCastUtils.blockResult
import net.minecraft.command.CommandRegistryAccess
import net.minecraft.util.math.BlockPos

Expand All @@ -38,21 +42,36 @@ class BlockPosSetting(defaultValue: BlockPos) : SettingCore<BlockPos>(
TypeToken.get(BlockPos::class.java).type
) {
context(setting: Setting<*, BlockPos>)
override fun ImGuiBuilder.buildLayout() {
inputVec3i(setting.name, value) { value = it.blockPos }
lambdaTooltip(setting.description)
}
override fun ImGuiBuilder.buildLayout() {
treeNode("Coordinates", id = setting.name) {
inputVec3i(setting.name, value) { value = it.blockPos }
}
lambdaTooltip(setting.description)
sameLine()
button("Set") {
runSafe {
mc.crosshairTarget?.blockResult?.blockPos?.let {
setting.trySetValue(it, logResponse = false)
ConfigCommand.info("Coordinates updated")
} ?: let {
info("No block under cursor")
return@runSafe
}
}
}
lambdaTooltip("Set the coordinates to the block you are currently looking at")
}

context(setting: Setting<*, BlockPos>)
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {
required(integer("X", -30000000, 30000000)) { x ->
required(integer("Y", -64, 255)) { y ->
required(integer("Z", -30000000, 30000000)) { z ->
execute {
setting.trySetValue(BlockPos(x().value(), y().value(), z().value()))
}
}
}
}
}
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {
required(integer("X", -30000000, 30000000)) { x ->
required(integer("Y", -64, 255)) { y ->
required(integer("Z", -30000000, 30000000)) { z ->
execute {
setting.trySetValue(BlockPos(x().value(), y().value(), z().value()))
}
}
}
}
}
}