From 011fecf34294de9ad14c899ee37d8cfb772ebc58 Mon Sep 17 00:00:00 2001 From: Ic3Tank <61137113+IceTank@users.noreply.github.com> Date: Sun, 8 Mar 2026 21:43:29 +0100 Subject: [PATCH 1/2] Add button to BlockPosSetting to set coordinates to the current block under the cursor --- src/main/kotlin/com/lambda/config/Setting.kt | 6 +-- .../settings/complex/BlockPosSetting.kt | 49 +++++++++++++------ 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/com/lambda/config/Setting.kt b/src/main/kotlin/com/lambda/config/Setting.kt index eef00628e..03a2dfa93 100644 --- a/src/main/kotlin/com/lambda/config/Setting.kt +++ b/src/main/kotlin/com/lambda/config/Setting.kt @@ -230,13 +230,13 @@ class Setting, 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)) } } diff --git a/src/main/kotlin/com/lambda/config/settings/complex/BlockPosSetting.kt b/src/main/kotlin/com/lambda/config/settings/complex/BlockPosSetting.kt index 907b74d96..9b41661d5 100644 --- a/src/main/kotlin/com/lambda/config/settings/complex/BlockPosSetting.kt +++ b/src/main/kotlin/com/lambda/config/settings/complex/BlockPosSetting.kt @@ -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 @@ -38,21 +42,36 @@ class BlockPosSetting(defaultValue: BlockPos) : SettingCore( 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())) + } + } + } + } + } } From 3881d2b4c54880ef76b5a3a3be91d19e05e978a0 Mon Sep 17 00:00:00 2001 From: Ic3Tank <61137113+IceTank@users.noreply.github.com> Date: Wed, 11 Mar 2026 21:33:07 +0100 Subject: [PATCH 2/2] Code cleanup --- .../config/settings/complex/BlockPosSetting.kt | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/com/lambda/config/settings/complex/BlockPosSetting.kt b/src/main/kotlin/com/lambda/config/settings/complex/BlockPosSetting.kt index 9b41661d5..28bb66f7e 100644 --- a/src/main/kotlin/com/lambda/config/settings/complex/BlockPosSetting.kt +++ b/src/main/kotlin/com/lambda/config/settings/complex/BlockPosSetting.kt @@ -26,11 +26,11 @@ 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.client.MinecraftClient import net.minecraft.command.CommandRegistryAccess import net.minecraft.util.math.BlockPos @@ -43,21 +43,16 @@ class BlockPosSetting(defaultValue: BlockPos) : SettingCore( ) { context(setting: Setting<*, BlockPos>) override fun ImGuiBuilder.buildLayout() { - treeNode("Coordinates", id = setting.name) { + treeNode(setting.name, 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 - } - } + MinecraftClient.getInstance().crosshairTarget?.blockResult?.blockPos?.let { + setting.trySetValue(it, logResponse = false) + ConfigCommand.info("Coordinates updated") + } ?: info("No block under crosshair") } lambdaTooltip("Set the coordinates to the block you are currently looking at") }