Skip to content

Commit 0355ef7

Browse files
authored
Merge pull request #118 from DFOnline/feat/config-changes
feat: config-related changes
2 parents 113a459 + edd7828 commit 0355ef7

File tree

5 files changed

+42
-38
lines changed

5 files changed

+42
-38
lines changed

src/main/java/dev/dfonline/codeclient/command/impl/CommandCCConfig.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,24 @@ public LiteralArgumentBuilder<FabricClientCommandSource> create(LiteralArgumentB
8181
for (Object member : field.getType().getEnumConstants()) {
8282
if (((Enum<?>) member).name().equalsIgnoreCase(value)) {
8383
field.set(Config.getConfig(), member);
84-
Utility.sendMessage(Text.translatable("codeclient.config.command.enum", Text.literal(option).formatted(Formatting.AQUA), Text.literal(value).formatted(Formatting.AQUA)), ChatType.SUCCESS);
84+
Utility.sendMessage(Text.translatable("codeclient.config.command.set", Text.literal(option).formatted(Formatting.AQUA), Text.literal(value).formatted(Formatting.AQUA)), ChatType.SUCCESS);
8585
Config.getConfig().save();
8686
return 0;
8787
}
8888
}
89-
Utility.sendMessage(Text.translatable("codeclient.config.command.enum.fail", Text.literal(option).formatted(Formatting.YELLOW), Text.literal(value).formatted(Formatting.YELLOW)), ChatType.FAIL);
89+
Utility.sendMessage(Text.translatable("codeclient.config.command.set.fail", Text.literal(option).formatted(Formatting.YELLOW), Text.literal(value).formatted(Formatting.YELLOW)), ChatType.FAIL);
9090
return -1;
91+
} else if (field.getType().equals(int.class)) {
92+
try {
93+
var number = Integer.parseInt(value);
94+
field.set(Config.getConfig(), number);
95+
Utility.sendMessage(Text.translatable("codeclient.config.command.set", Text.literal(option).formatted(Formatting.AQUA), Text.literal(String.valueOf(number)).formatted(Formatting.AQUA)), ChatType.SUCCESS);
96+
Config.getConfig().save();
97+
return 0;
98+
} catch (NumberFormatException e) {
99+
Utility.sendMessage(Text.translatable("codeclient.config.command.set.fail", Text.literal(option).formatted(Formatting.YELLOW), Text.literal(value).formatted(Formatting.YELLOW)), ChatType.FAIL);
100+
return -1;
101+
}
91102
}
92103
Utility.sendMessage(Text.translatable("codeclient.config.command.fail"), ChatType.FAIL);
93104
} catch (Exception ignored) {

src/main/java/dev/dfonline/codeclient/config/Config.java

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
public class Config {
2323
private static Config instance;
24-
public boolean NoClipEnabled = true;
24+
public boolean NoClipEnabled = false;
2525
public boolean PlaceOnAir = false;
2626
public int AirSpeed = 10;
2727
public boolean CodeClientAPI = false;
@@ -37,7 +37,6 @@ public class Config {
3737
public float ReachDistance = 5;
3838
public boolean AutoFly = false;
3939
public LayerInteractionMode CodeLayerInteractionMode = LayerInteractionMode.AUTO;
40-
public boolean AirControl = false;
4140
public boolean FocusSearch = false;
4241
public CharSetOption SaveCharSet = CharSetOption.UTF_8;
4342
public boolean RecentChestInsert = true;
@@ -78,7 +77,7 @@ public class Config {
7877
public boolean DevNodes = false;
7978
public boolean GiveUuidNameStrings = true;
8079
public boolean CPUDisplay = true;
81-
public CPUDisplayCorner CPUDisplayCornerOption = CPUDisplayCorner.TOP_LEFT;
80+
public CPUDisplayCornerOption CPUDisplayCorner = CPUDisplayCornerOption.TOP_LEFT;
8281
public boolean HideScopeChangeMessages = true;
8382
public boolean HighlighterEnabled = true;
8483
public boolean HighlightExpressions = true;
@@ -125,7 +124,6 @@ public void save() {
125124
object.addProperty("ReachDistance", ReachDistance);
126125
object.addProperty("AutoFly", AutoFly);
127126
object.addProperty("CodeLayerInteractionMode", CodeLayerInteractionMode.name());
128-
object.addProperty("AirControl", AirControl);
129127
object.addProperty("FocusSearch", FocusSearch);
130128
object.addProperty("SaveCharSet", SaveCharSet.name());
131129
object.addProperty("RecentChestInsert", RecentChestInsert);
@@ -165,7 +163,7 @@ public void save() {
165163
object.addProperty("DevNodes", DevNodes);
166164
object.addProperty("GiveUuidNameStrings", GiveUuidNameStrings);
167165
object.addProperty("CPUDisplay", CPUDisplay);
168-
object.addProperty("CPUDisplayCorner", CPUDisplayCornerOption.name());
166+
object.addProperty("CPUDisplayCorner", CPUDisplayCorner.name());
169167
object.addProperty("HideScopeChangeMessages", HideScopeChangeMessages);
170168

171169
object.addProperty("HighlighterEnabled", HighlighterEnabled);
@@ -337,7 +335,7 @@ public YetAnotherConfigLib getLibConfig() {
337335
.text(Text.translatable("codeclient.config.noclip.description"))
338336
.build())
339337
.binding(
340-
true,
338+
false,
341339
() -> NoClipEnabled,
342340
opt -> NoClipEnabled = opt
343341
)
@@ -360,7 +358,7 @@ public YetAnotherConfigLib getLibConfig() {
360358
.build())
361359
.option(Option.createBuilder(float.class)
362360
.name(Text.translatable("codeclient.config.angle_up"))
363-
.description(OptionDescription.of(Text.translatable("codeclient.config.angle_up.description")))
361+
.description(OptionDescription.of(Text.translatable("codeclient.config.angle_up.description"), Text.translatable("codeclient.config.requires_noclip")))
364362
.binding(
365363
50F,
366364
() -> UpAngle,
@@ -370,7 +368,7 @@ public YetAnotherConfigLib getLibConfig() {
370368
.build())
371369
.option(Option.createBuilder(float.class)
372370
.name(Text.translatable("codeclient.config.angle_down"))
373-
.description(OptionDescription.of(Text.translatable("codeclient.config.angle_down.description")))
371+
.description(OptionDescription.of(Text.translatable("codeclient.config.angle_down.description"), Text.translatable("codeclient.config.requires_noclip")))
374372
.binding(50F,
375373
() -> DownAngle,
376374
opt -> DownAngle = opt
@@ -379,7 +377,7 @@ public YetAnotherConfigLib getLibConfig() {
379377
.build())
380378
.option(Option.createBuilder(boolean.class)
381379
.name(Text.translatable("codeclient.config.tp_up"))
382-
.description(OptionDescription.of(Text.translatable("codeclient.config.tp_up.description")))
380+
.description(OptionDescription.of(Text.translatable("codeclient.config.tp_up.description"), Text.translatable("codeclient.config.requires_noclip")))
383381
.binding(
384382
false,
385383
() -> TeleportUp,
@@ -389,7 +387,7 @@ public YetAnotherConfigLib getLibConfig() {
389387
.build())
390388
.option(Option.createBuilder(boolean.class)
391389
.name(Text.translatable("codeclient.config.tp_down"))
392-
.description(OptionDescription.of(Text.translatable("codeclient.config.tp_down.description")))
390+
.description(OptionDescription.of(Text.translatable("codeclient.config.tp_down.description"), Text.translatable("codeclient.config.requires_noclip")))
393391
.binding(
394392
false,
395393
() -> TeleportDown,
@@ -409,18 +407,6 @@ public YetAnotherConfigLib getLibConfig() {
409407
)
410408
.controller(TickBoxControllerBuilder::create)
411409
.build())
412-
// .option(Option.createBuilder(boolean.class)
413-
// .name(Text.literal("Air Control"))
414-
// .description(OptionDescription.createBuilder()
415-
// .text(Text.literal("Gives you the same control in air as walking."))
416-
// .build())
417-
// .binding(
418-
// false,
419-
// () -> AirControl,
420-
// opt -> AirControl = opt
421-
// )
422-
// .controller(TickBoxController::new)
423-
// .build())
424410
.build())
425411
//</editor-fold>
426412
//<editor-fold desc="Interaction">
@@ -672,15 +658,15 @@ public YetAnotherConfigLib getLibConfig() {
672658
)
673659
.controller(TickBoxControllerBuilder::create)
674660
.build())
675-
.option(Option.createBuilder(Config.CPUDisplayCorner.class)
661+
.option(Option.createBuilder(CPUDisplayCornerOption.class)
676662
.name(Text.translatable("codeclient.config.cpu_display_corner.name"))
677663
.description(OptionDescription.of(Text.translatable("codeclient.config.cpu_display_corner.description")))
678664
.binding(
679-
CPUDisplayCorner.TOP_LEFT,
680-
() -> CPUDisplayCornerOption,
681-
opt -> CPUDisplayCornerOption = opt
665+
CPUDisplayCornerOption.TOP_LEFT,
666+
() -> CPUDisplayCorner,
667+
opt -> CPUDisplayCorner = opt
682668
)
683-
.controller(nodeOption -> () -> new EnumController<>(nodeOption, Config.CPUDisplayCorner.class))
669+
.controller(nodeOption -> () -> new EnumController<>(nodeOption, CPUDisplayCornerOption.class))
684670
.build())
685671
.option(Option.createBuilder(Boolean.class)
686672
.name(Text.translatable("codeclient.config.hide_scope_change_messages"))
@@ -1017,7 +1003,7 @@ public enum DestroyItemReset {
10171003
}
10181004
}
10191005

1020-
public enum CPUDisplayCorner {
1006+
public enum CPUDisplayCornerOption {
10211007
TOP_LEFT,
10221008
TOP_RIGHT,
10231009
BOTTOM_LEFT,

src/main/java/dev/dfonline/codeclient/dev/Navigation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public boolean shouldTeleportUp() {
3232
public boolean onCrouch(boolean lastSneaking) {
3333
var player = CodeClient.MC.player;
3434
if (CodeClient.location instanceof Dev dev
35+
&& Config.getConfig().NoClipEnabled
3536
&& Config.getConfig().TeleportDown
3637
&& player != null
3738
&& dev.isInDevSpace()
@@ -53,6 +54,7 @@ public boolean onCrouch(boolean lastSneaking) {
5354
public Float jumpHeight() {
5455
if (CodeClient.location instanceof Dev dev
5556
&& dev.isInDev(CodeClient.MC.player.getPos())
57+
&& Config.getConfig().NoClipEnabled
5658
&& CodeClient.MC.player.getPitch() <= Config.getConfig().UpAngle - 90)
5759
return 0.91f;
5860
return null;

src/main/java/dev/dfonline/codeclient/mixin/render/hud/MInGameHud.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,28 @@ private void onRender(DrawContext context, float tickDelta, CallbackInfo ci) {
4242

4343
List<Text> overlay = new ArrayList<>(List.copyOf(OverlayManager.getOverlayText()));
4444
Text cpuUsage = OverlayManager.getCpuUsage();
45-
if (!overlay.isEmpty()) {
46-
if (cpuUsage != null && Config.getConfig().CPUDisplayCornerOption == Config.CPUDisplayCorner.TOP_LEFT) {
45+
if (cpuUsage != null && Config.getConfig().CPUDisplayCorner == Config.CPUDisplayCornerOption.TOP_LEFT) {
46+
if (overlay.isEmpty()) overlay.add(cpuUsage);
47+
else {
4748
overlay.add(0, cpuUsage);
4849
overlay.add(1, Text.empty());
4950
}
51+
}
52+
if (!overlay.isEmpty()) {
5053
int index = 0;
5154
for (Text text : overlay) {
5255
context.drawTextWithShadow(textRenderer, Objects.requireNonNullElseGet(text, () -> Text.literal("NULL")), 30, 30 + (index * 9), -1);
5356
index++;
5457
}
5558
}
56-
if (cpuUsage != null && Config.getConfig().CPUDisplayCornerOption != Config.CPUDisplayCorner.TOP_LEFT) {
59+
60+
if (cpuUsage != null && Config.getConfig().CPUDisplayCorner != Config.CPUDisplayCornerOption.TOP_LEFT) {
5761
int margin = 30;
58-
int x = switch (Config.getConfig().CPUDisplayCornerOption) {
62+
int x = switch (Config.getConfig().CPUDisplayCorner) {
5963
case TOP_LEFT, BOTTOM_LEFT -> margin;
6064
case TOP_RIGHT, BOTTOM_RIGHT -> scaledWidth - margin - textRenderer.getWidth(cpuUsage);
6165
};
62-
int y = switch (Config.getConfig().CPUDisplayCornerOption) {
66+
int y = switch (Config.getConfig().CPUDisplayCorner) {
6367
case TOP_LEFT, TOP_RIGHT -> margin;
6468
case BOTTOM_LEFT, BOTTOM_RIGHT -> scaledHeight - margin - 3;
6569
};

src/main/resources/assets/codeclient/lang/en_us.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"codeclient.config": "CodeClient Config",
2020

2121
"codeclient.config.requires_restart": "(requires restart)",
22+
"codeclient.config.requires_noclip": "(requires NoClip)",
2223
"codeclient.config.default_recommended": "Default recommended.",
2324

2425
"codeclient.config.tab.general": "General",
@@ -57,7 +58,7 @@
5758
"codeclient.config.tab.navigation.description": "How you move about in the codespace and the likes.",
5859

5960
"codeclient.config.noclip": "NoClip",
60-
"codeclient.config.noclip.description": "If you can NoClip in the dev space.",
61+
"codeclient.config.noclip.description": "Whether you can walk through codeblocks, additionally enables codespace travel by looking up/down and jumping/sneaking.",
6162
"codeclient.config.airstrafe_modifier": "AirStrafe Modifier",
6263
"codeclient.config.airstrafe_modifier.description1": "How much faster you go when jumping in dev space.",
6364
"codeclient.config.airstrafe_modifier.description2": "Your jump speed will be based of walking speed.",
@@ -190,8 +191,8 @@
190191
"codeclient.config.command.query.fail": "There is no option with name %s.",
191192
"codeclient.config.command.enable": "Enabled option %s.",
192193
"codeclient.config.command.disable": "Disabled option %s.",
193-
"codeclient.config.command.enum": "Set option %s to %s.",
194-
"codeclient.config.command.enum.fail": "Couldn't set option %s to %s.",
194+
"codeclient.config.command.set": "Set option %s to %s.",
195+
"codeclient.config.command.set.fail": "Couldn't set option %s to %s.",
195196
"codeclient.config.command.fail": "You cannot set this config option.",
196197

197198
"codeclient.config.destroy_item_reset.name": "Destroy Item Reset",

0 commit comments

Comments
 (0)