-
Notifications
You must be signed in to change notification settings - Fork 22
feat(BlockPosSetting): Add button to set coordinates #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.21.11
Are you sure you want to change the base?
Changes from all commits
011fecf
3881d2b
af6703f
c814a7d
82e461b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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") { | ||
IceTank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| MinecraftClient.getInstance().crosshairTarget?.blockResult?.blockPos?.let { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mc from Lambda.kt over MinecraftClient.getInstance() |
||
| setting.trySetValue(it, logResponse = false) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not set the settings value as it does below? value = it. That would avoid the whole overriding the command print thing in chat |
||
| 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, 319)) { 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, 319)) { y -> | ||
| required(integer("Z", -30000000, 30000000)) { z -> | ||
| execute { | ||
| setting.trySetValue(BlockPos(x().value(), y().value(), z().value())) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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