Skip to content

Commit 5698a05

Browse files
committed
Fixed cconfig
1 parent 911b425 commit 5698a05

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

src/main/java/dev/xpple/seedmapper/command/commands/EspConfigCommand.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,19 @@ private EspConfigCommand() {
5858
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
5959
CommandNode<FabricClientCommandSource> cconfigRoot = dispatcher.getRoot().getChild("cconfig");
6060
if (cconfigRoot == null) {
61-
// If the BetterConfig client command isn't present, register a direct sm:config fallback
61+
// BetterConfig client command not present: register direct fallback.
6262
registerDirectSmConfig(dispatcher);
6363
return;
6464
}
65+
6566
CommandNode<FabricClientCommandSource> modRoot = cconfigRoot.getChild(SeedMapper.MOD_ID);
6667
if (modRoot == null) {
67-
// fallback to direct registration if mod-specific cconfig node missing
68+
// Mod-specific cconfig node missing: register direct fallback.
6869
registerDirectSmConfig(dispatcher);
6970
return;
7071
}
7172

72-
// Use a single target argument that accepts any case but suggests TitleCase names
73+
// Attach ESP-specific settings to existing sm:config/cconfig tree.
7374
com.mojang.brigadier.builder.RequiredArgumentBuilder<FabricClientCommandSource, String> targetArgNode = argument("target", StringArgumentType.word())
7475
.suggests(EspConfigCommand::suggestTargets);
7576
targetArgNode.then(literal("get")
@@ -82,8 +83,10 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
8283
.executes(ctx -> executeSet(ctx, getTargetArgument(ctx, "target")))));
8384
targetArgNode.then(literal("reset")
8485
.executes(ctx -> executeReset(ctx, getTargetArgument(ctx, "target"))));
86+
8587
modRoot.addChild(targetArgNode.build());
8688
modRoot.addChild(buildZoomLiteral("Zoom").build());
89+
modRoot.addChild(buildEspTimeoutLiteral().build());
8790
}
8891

8992
private static void registerDirectSmConfig(CommandDispatcher<FabricClientCommandSource> dispatcher) {
@@ -103,12 +106,16 @@ private static void registerDirectSmConfig(CommandDispatcher<FabricClientCommand
103106
.executes(ctx -> executeReset(ctx, getTargetArgument(ctx, "target"))));
104107
smRoot.then(targetArgNode);
105108
smRoot.then(buildZoomLiteral("Zoom"));
106-
// esptimeout top-level alias
107-
smRoot.then(literal("esptimeout")
109+
smRoot.then(buildEspTimeoutLiteral());
110+
dispatcher.register(smRoot);
111+
}
112+
113+
private static LiteralArgumentBuilder<FabricClientCommandSource> buildEspTimeoutLiteral() {
114+
return literal("esptimeout")
108115
.executes(ctx -> {
109116
CustomClientCommandSource source = CustomClientCommandSource.of(ctx.getSource());
110117
source.sendFeedback(Component.literal("EspTimeoutMinutes = " + Configs.EspTimeoutMinutes));
111-
return 1;
118+
return Command.SINGLE_SUCCESS;
112119
})
113120
.then(argument("minutes", DoubleArgumentType.doubleArg(0.0))
114121
.executes(ctx -> {
@@ -117,9 +124,8 @@ private static void registerDirectSmConfig(CommandDispatcher<FabricClientCommand
117124
Configs.save();
118125
RenderManager.setHighlightTimeout(Configs.EspTimeoutMinutes);
119126
CustomClientCommandSource.of(ctx.getSource()).sendFeedback(Component.literal("Updated EspTimeoutMinutes = " + minutes));
120-
return 1;
121-
})));
122-
dispatcher.register(smRoot);
127+
return Command.SINGLE_SUCCESS;
128+
}));
123129
}
124130

125131
private static LiteralArgumentBuilder<FabricClientCommandSource> buildZoomLiteral(String literalName) {

src/main/java/dev/xpple/seedmapper/mixin/betterconfig/ConfigCommandClientMixin.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@
1111
import org.spongepowered.asm.mixin.injection.Inject;
1212
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1313

14-
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.*;
14+
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
1515

1616
@Mixin(ConfigCommandClient.class)
1717
public class ConfigCommandClientMixin {
1818
@Inject(method = "register", at = @At("TAIL"))
1919
private static void registerConfigCommand(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandBuildContext buildContext, CallbackInfo ci) {
20-
CommandNode<FabricClientCommandSource> configRoot = dispatcher.getRoot().getChild("cconfig").getChild(SeedMapper.MOD_ID);
20+
CommandNode<FabricClientCommandSource> cconfigRoot = dispatcher.getRoot().getChild("cconfig");
21+
if (cconfigRoot == null) {
22+
return;
23+
}
24+
CommandNode<FabricClientCommandSource> configRoot = cconfigRoot.getChild(SeedMapper.MOD_ID);
25+
if (configRoot == null) {
26+
return;
27+
}
2128
dispatcher.register(literal("sm:config").redirect(configRoot));
2229
}
2330
}

0 commit comments

Comments
 (0)