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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think a logResponse parameter is required here. The button has the tooltip to explain what it does and the built-in log functionality offers an option to revert to the old value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it this way because the default response in chat shows coordinates of the setting you changed

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 @@ -26,7 +26,10 @@ 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

Expand All @@ -38,21 +41,31 @@ 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() {
button("Set") {
MinecraftClient.getInstance().crosshairTarget?.blockResult?.blockPos?.let {
setting.trySetValue(it, logResponse = false)
setting.info("Coordinates updated")
} ?: info("No block under crosshair")
}
lambdaTooltip("Set the coordinates to the block you are currently looking at")
sameLine()
treeNode(setting.name, id = setting.name) {
inputVec3i("##${setting.name}", value) { value = it.blockPos }
}
lambdaTooltip(setting.description)
}

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()))
}
}
}
}
}
}