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..28bb66f7e 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.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 @@ -38,21 +42,31 @@ 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(setting.name, id = setting.name) { + inputVec3i(setting.name, value) { value = it.blockPos } + } + lambdaTooltip(setting.description) + sameLine() + button("Set") { + 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") + } 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())) + } + } + } + } + } }