Skip to content

Commit 6f9967a

Browse files
committed
Merge branch 'development' into latest
2 parents 57dde81 + bf8538b commit 6f9967a

28 files changed

+315
-273
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
## Changes
2-
- Backport to 1.20.6
3-
- Fixed hotbar renderer in config screens
2+
- Port to 1.21
3+
- Removed help subcommand
4+
- Added relative boolean to corner subcommands
5+
- Opening config file with command now errors to chat
6+
- Added teleport mode subcommand
7+
- Visibility, mode, and corner subcommands log to chat
8+
- Integers can now be specified in movehud subcommand
9+
- Boolean can now be specified in toggle subcommand

common/src/main/java/dev/boxadactle/coordinatesdisplay/CoordinatesDisplay.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class CoordinatesDisplay {
1313

1414
public static final String MOD_ID = "coordinatesdisplay";
1515

16-
public static final String VERSION = "12.0.0";
16+
public static final String VERSION = "13.0.0";
1717

1818
public static final String VERSION_STRING = MOD_NAME + " v" + VERSION;
1919

@@ -39,7 +39,7 @@ public class CoordinatesDisplay {
3939
LOGGER.info("Initializing " + MOD_NAME + " v" + VERSION);
4040

4141
// register commands
42-
BCommandManager.register(CoordinatesCommand.create());
42+
BCommandManager.register(CoordinatesCommand.createCommand());
4343
}
4444

4545
public static void init() {
Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,45 @@
11
package dev.boxadactle.coordinatesdisplay.command;
22

3-
import com.mojang.brigadier.builder.ArgumentBuilder;
43
import com.mojang.brigadier.context.CommandContext;
5-
import dev.boxadactle.boxlib.command.BCommandManager;
64
import dev.boxadactle.boxlib.command.BCommandSourceStack;
7-
import dev.boxadactle.boxlib.command.api.BClientSubcommand;
5+
import dev.boxadactle.boxlib.command.api.BSubcommand;
6+
import dev.boxadactle.boxlib.command.api.subcommand.BasicSubcommand;
87
import dev.boxadactle.boxlib.scheduling.Scheduling;
98
import dev.boxadactle.boxlib.util.ClientUtils;
109
import dev.boxadactle.boxlib.util.GuiUtils;
1110
import dev.boxadactle.coordinatesdisplay.CoordinatesDisplay;
1211
import dev.boxadactle.coordinatesdisplay.ModUtil;
1312
import dev.boxadactle.coordinatesdisplay.screen.ConfigScreen;
1413

15-
public class ConfigSubcommand implements BClientSubcommand {
16-
@Override
17-
public ArgumentBuilder<BCommandSourceStack, ?> getSubcommand() {
18-
return BCommandManager.literal("config")
19-
.executes(this::openConfigGui);
14+
public class ConfigSubcommand {
15+
public static BSubcommand create() {
16+
return new BasicSubcommand("config", ConfigSubcommand::openConfigGui)
17+
.registerSubcommand(new BasicSubcommand("file", ConfigSubcommand::openConfigFile))
18+
.registerSubcommand(new BasicSubcommand("reload", ConfigSubcommand::reloadConfig));
2019
}
2120

22-
@Override
23-
public void build(ArgumentBuilder<BCommandSourceStack, ?> builder) {
24-
builder.then(BCommandManager.literal("file")
25-
.executes(this::openConfigFile)
26-
);
27-
28-
builder.then(BCommandManager.literal("reload")
29-
.executes(this::reloadConfig)
30-
);
31-
32-
builder.then(BCommandManager.literal("gui")
33-
.executes(this::openConfigGui)
34-
);
35-
}
36-
37-
private int openConfigGui(CommandContext<BCommandSourceStack> ignored) {
21+
static int openConfigGui(CommandContext<BCommandSourceStack> ignored) {
3822
Scheduling.nextTick(() -> ClientUtils.setScreen(new ConfigScreen(null)));
3923
CoordinatesDisplay.LOGGER.info("Opening Config GUI");
4024

4125
return 0;
4226
}
4327

44-
private int openConfigFile(CommandContext<BCommandSourceStack> ignored) {
28+
static int openConfigFile(CommandContext<BCommandSourceStack> ignored) {
4529
if (ModUtil.openConfigFile()) {
4630
CoordinatesDisplay.LOGGER.player.info(GuiUtils.getTranslatable("command.coordinatesdisplay.config.open.success"));
4731
return 0;
4832
} else {
49-
CoordinatesDisplay.LOGGER.info(GuiUtils.getTranslatable("command.coordinatesdisplay.config.open.fail"));
33+
CoordinatesDisplay.LOGGER.player.error(GuiUtils.getTranslatable("command.coordinatesdisplay.config.open.fail"));
5034
return 1;
5135
}
5236
}
5337

54-
private int reloadConfig(CommandContext<BCommandSourceStack> ignored) {
38+
static int reloadConfig(CommandContext<BCommandSourceStack> ignored) {
5539
CoordinatesDisplay.CONFIG.reload();
5640
CoordinatesDisplay.LOGGER.player.info(GuiUtils.getTranslatable("command.coordinatesdisplay.config.reload"));
5741
CoordinatesDisplay.LOGGER.info("Reloaded all config");
5842

5943
return 0;
6044
}
61-
}
45+
}
Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,42 @@
11
package dev.boxadactle.coordinatesdisplay.command;
22

3-
import com.google.common.collect.ImmutableList;
43
import com.mojang.brigadier.context.CommandContext;
54
import dev.boxadactle.boxlib.command.BCommandSourceStack;
6-
import dev.boxadactle.boxlib.command.api.BClientCommand;
5+
import dev.boxadactle.boxlib.command.api.BCommand;
6+
import dev.boxadactle.boxlib.command.api.subcommand.BasicSubcommand;
77
import dev.boxadactle.boxlib.scheduling.Scheduling;
88
import dev.boxadactle.boxlib.util.ClientUtils;
9-
import dev.boxadactle.boxlib.util.GuiUtils;
109
import dev.boxadactle.boxlib.util.WorldUtils;
1110
import dev.boxadactle.coordinatesdisplay.CoordinatesDisplay;
11+
import dev.boxadactle.coordinatesdisplay.position.Position;
1212
import dev.boxadactle.coordinatesdisplay.screen.CoordinatesScreen;
1313
import dev.boxadactle.coordinatesdisplay.screen.config.PositionScreen;
14-
import dev.boxadactle.coordinatesdisplay.position.Position;
15-
import net.minecraft.network.chat.Component;
16-
17-
import java.util.List;
14+
import net.minecraft.client.resources.language.I18n;
1815

1916
public class CoordinatesCommand {
2017

21-
public static BClientCommand create() {
22-
return BClientCommand.create("coordinates", CoordinatesCommand::openCoordinatesScreen)
23-
.registerSubcommand(new ConfigSubcommand())
24-
.registerSubcommand(new CornerSubcommand())
25-
.registerSubcommand("help", CoordinatesCommand::showHelpMessage)
26-
.registerSubcommand(new ModeSubcommand())
27-
.registerSubcommand(new VisibilitySubcommand())
28-
.registerSubcommand("movehud", CoordinatesCommand::moveHud)
29-
.registerSubcommand(new PositionSubcommand())
30-
.registerSubcommand("toggle", CoordinatesCommand::toggle);
18+
public static BCommand createCommand() {
19+
return BCommand.create("coordinates", CoordinatesCommand::openCoordinatesScreen)
20+
.registerSubcommand(ToggleSubcommand.create())
21+
.registerSubcommand(MoveHudSubcommand.create())
22+
.registerSubcommand(ConfigSubcommand.create())
23+
.registerSubcommand(CornerSubcommand.create())
24+
.registerSubcommand(ModeSubcommand.create())
25+
.registerSubcommand(VisibilitySubcommand.create())
26+
.registerSubcommand(PositionSubcommand.create())
27+
.registerSubcommand(TeleportModeSubcommand.create());
3128
}
3229

33-
private static int openCoordinatesScreen(CommandContext<BCommandSourceStack> ignored) {
30+
static int openCoordinatesScreen(CommandContext<BCommandSourceStack> ignored) {
3431
Scheduling.nextTick(() -> ClientUtils.setScreen(new CoordinatesScreen(Position.of(WorldUtils.getPlayer()))));
3532

3633
return 0;
3734
}
3835

39-
private static int toggle(CommandContext<BCommandSourceStack> ignored) {
40-
CoordinatesDisplay.getConfig().enabled = !CoordinatesDisplay.getConfig().enabled;
41-
CoordinatesDisplay.CONFIG.save();
42-
43-
return 0;
44-
}
45-
46-
private static int showHelpMessage(CommandContext<BCommandSourceStack> ignored) {
47-
List<Component> components = ImmutableList.of(
48-
GuiUtils.colorize(Component.translatable("command.coordinatesdisplay.helpmenu"), GuiUtils.AQUA),
49-
Component.translatable("command.coordinatesdisplay.config"),
50-
Component.translatable("command.coordinatesdisplay.gui"),
51-
Component.translatable("command.coordinatesdisplay.help"),
52-
Component.translatable("command.coordinatesdisplay.mode"),
53-
Component.translatable("command.coordinatesdisplay.movehud"),
54-
Component.translatable("command.coordinatesdisplay.position"),
55-
Component.translatable("command.coordinatesdisplay.visibility")
56-
);
36+
static int noArgs(CommandContext<BCommandSourceStack> ignored) {
37+
CoordinatesDisplay.LOGGER.player.error(I18n.get("command.coordinatesdisplay.emptyArgs"));
5738

58-
components.forEach(c -> {
59-
CoordinatesDisplay.LOGGER.player.chat(c);
60-
});
61-
62-
return 0;
63-
}
64-
65-
private static int moveHud(CommandContext<BCommandSourceStack> ignored) {
66-
Scheduling.nextTick(() -> ClientUtils.setScreen(new PositionScreen(null)));
67-
68-
return 0;
39+
return 1;
6940
}
7041

71-
}
42+
}
Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,55 @@
11
package dev.boxadactle.coordinatesdisplay.command;
22

3-
import com.mojang.brigadier.builder.ArgumentBuilder;
4-
import dev.boxadactle.boxlib.command.BCommandManager;
5-
import dev.boxadactle.boxlib.command.BCommandSourceStack;
6-
import dev.boxadactle.boxlib.command.api.BClientSubcommand;
3+
import dev.boxadactle.boxlib.command.api.BSubcommand;
4+
import dev.boxadactle.boxlib.command.api.subcommand.BasicSubcommand;
5+
import dev.boxadactle.boxlib.command.api.subcommand.BooleanSubcommand;
76
import dev.boxadactle.boxlib.math.geometry.Dimension;
87
import dev.boxadactle.boxlib.math.geometry.Vec2;
98
import dev.boxadactle.boxlib.util.ClientUtils;
109
import dev.boxadactle.coordinatesdisplay.CoordinatesDisplay;
1110
import dev.boxadactle.coordinatesdisplay.registry.StartCorner;
11+
import net.minecraft.client.resources.language.I18n;
1212

13-
public class CornerSubcommand implements BClientSubcommand {
14-
@Override
15-
public ArgumentBuilder<BCommandSourceStack, ?> getSubcommand() {
16-
return BCommandManager.literal("corner");
17-
}
13+
public class CornerSubcommand {
14+
15+
public static BSubcommand create() {
16+
StartCorner[] corners = StartCorner.values();
1817

19-
@Override
20-
public void build(ArgumentBuilder<BCommandSourceStack, ?> builder) {
21-
StartCorner[] corners = StartCorner.values();
18+
BasicSubcommand subcommand = new BasicSubcommand("corner", CoordinatesCommand::noArgs);
2219

2320
for (StartCorner corner : corners) {
24-
builder.then(BCommandManager.literal(corner.name().toLowerCase())
25-
.executes(c -> {
26-
Vec2<Integer> relative = corner.getModifier().getRelativePos(
27-
CoordinatesDisplay.HUD.getRect(),
28-
new Dimension<>(
29-
Math.round(ClientUtils.getClient().getWindow().getGuiScaledWidth() / CoordinatesDisplay.getConfig().hudScale),
30-
Math.round(ClientUtils.getClient().getWindow().getGuiScaledHeight() / CoordinatesDisplay.getConfig().hudScale)
31-
)
32-
);
33-
34-
CoordinatesDisplay.getConfig().hudX = relative.getX();
35-
CoordinatesDisplay.getConfig().hudY = relative.getY();
36-
CoordinatesDisplay.getConfig().startCorner = corner;
37-
CoordinatesDisplay.CONFIG.save();
38-
return 0;
39-
})
40-
);
21+
subcommand.registerSubcommand(new BasicSubcommand(corner.name().toLowerCase(), (context) -> {
22+
CoordinatesDisplay.getConfig().startCorner = corner;
23+
CoordinatesDisplay.CONFIG.save();
24+
return 0;
25+
}).registerSubcommand(new BooleanSubcommand("relative", (context, bool) -> {
26+
if (bool) {
27+
Vec2<Integer> relative = relative(corner);
28+
29+
CoordinatesDisplay.getConfig().hudX = relative.getX();
30+
CoordinatesDisplay.getConfig().hudY = relative.getY();
31+
}
32+
33+
CoordinatesDisplay.getConfig().startCorner = corner;
34+
CoordinatesDisplay.CONFIG.save();
35+
36+
CoordinatesDisplay.LOGGER.player.info(I18n.get("button.coordinatesdisplay.startcorner", I18n.get("button.coordinatesdisplay.startcorner." + corner.name().toLowerCase())));
37+
38+
return 0;
39+
})));
4140
}
41+
42+
return subcommand;
4243
}
43-
}
44+
45+
static Vec2<Integer> relative(StartCorner corner) {
46+
return corner.getModifier().getRelativePos(
47+
CoordinatesDisplay.HUD.getRect(),
48+
new Dimension<>(
49+
Math.round(ClientUtils.getClient().getWindow().getGuiScaledWidth() / CoordinatesDisplay.getConfig().hudScale),
50+
Math.round(ClientUtils.getClient().getWindow().getGuiScaledHeight() / CoordinatesDisplay.getConfig().hudScale)
51+
)
52+
);
53+
}
54+
55+
}
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
package dev.boxadactle.coordinatesdisplay.command;
22

3-
import com.mojang.brigadier.builder.ArgumentBuilder;
4-
import dev.boxadactle.boxlib.command.BCommandManager;
5-
import dev.boxadactle.boxlib.command.BCommandSourceStack;
6-
import dev.boxadactle.boxlib.command.api.BClientSubcommand;
3+
import dev.boxadactle.boxlib.command.api.BSubcommand;
4+
import dev.boxadactle.boxlib.command.api.subcommand.BasicSubcommand;
75
import dev.boxadactle.coordinatesdisplay.CoordinatesDisplay;
86
import dev.boxadactle.coordinatesdisplay.registry.DisplayMode;
7+
import net.minecraft.client.resources.language.I18n;
98

10-
public class ModeSubcommand implements BClientSubcommand {
11-
@Override
12-
public ArgumentBuilder<BCommandSourceStack, ?> getSubcommand() {
13-
return BCommandManager.literal("mode");
14-
}
9+
public class ModeSubcommand {
1510

16-
@Override
17-
public void build(ArgumentBuilder<BCommandSourceStack, ?> builder) {
11+
public static BSubcommand create() {
1812
DisplayMode[] modes = DisplayMode.values();
1913

14+
BSubcommand subcommand = new BasicSubcommand("mode", CoordinatesCommand::noArgs);
15+
2016
for (DisplayMode mode : modes) {
21-
builder.then(BCommandManager.literal(mode.getId())
22-
.executes(c -> {
23-
CoordinatesDisplay.getConfig().renderMode = mode;
24-
CoordinatesDisplay.CONFIG.save();
25-
return 0;
26-
})
27-
);
17+
subcommand.registerSubcommand(new BasicSubcommand(mode.name().toLowerCase(), (context) -> {
18+
CoordinatesDisplay.getConfig().renderMode = mode;
19+
CoordinatesDisplay.CONFIG.save();
20+
21+
CoordinatesDisplay.LOGGER.player.info(I18n.get("button.coordinatesdisplay.displayMode", mode.getName()));
22+
23+
return 0;
24+
}));
2825
}
26+
27+
return subcommand;
2928
}
30-
}
29+
30+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package dev.boxadactle.coordinatesdisplay.command;
2+
3+
import com.mojang.brigadier.arguments.IntegerArgumentType;
4+
import com.mojang.brigadier.context.CommandContext;
5+
import dev.boxadactle.boxlib.command.BCommandSourceStack;
6+
import dev.boxadactle.boxlib.command.api.BSubcommand;
7+
import dev.boxadactle.boxlib.command.api.subcommand.BasicSubcommand;
8+
import dev.boxadactle.boxlib.command.api.subcommand.IntegerSubcommand;
9+
import dev.boxadactle.boxlib.scheduling.Scheduling;
10+
import dev.boxadactle.boxlib.util.ClientUtils;
11+
import dev.boxadactle.coordinatesdisplay.CoordinatesDisplay;
12+
import dev.boxadactle.coordinatesdisplay.screen.config.PositionScreen;
13+
import net.minecraft.client.resources.language.I18n;
14+
15+
public class MoveHudSubcommand {
16+
17+
public static BSubcommand create() {
18+
return new BasicSubcommand("movehud", MoveHudSubcommand::moveHud)
19+
.registerSubcommand(new BasicSubcommand("get", MoveHudSubcommand::get))
20+
.registerSubcommand(new IntegerSubcommand("xpos", MoveHudSubcommand::xOnly)
21+
.registerSubcommand(new IntegerSubcommand("ypos", MoveHudSubcommand::hudPos))
22+
);
23+
}
24+
25+
static int moveHud(CommandContext<BCommandSourceStack> ignored) {
26+
Scheduling.nextTick(() -> ClientUtils.setScreen(new PositionScreen(null)));
27+
28+
return 0;
29+
}
30+
31+
static int get(CommandContext<BCommandSourceStack> ignored) {
32+
CoordinatesDisplay.LOGGER.player.info(I18n.get(
33+
"command.coordinatesdisplay.movehud.get",
34+
CoordinatesDisplay.getConfig().hudX,
35+
CoordinatesDisplay.getConfig().hudY
36+
));
37+
38+
return 0;
39+
}
40+
41+
static int xOnly(CommandContext<BCommandSourceStack> ignored, int i) {
42+
CoordinatesDisplay.LOGGER.player.error(I18n.get("command.coordinatesdisplay.movehud.fail"));
43+
44+
return 1;
45+
}
46+
47+
static int hudPos(CommandContext<BCommandSourceStack> context, int y) {
48+
CoordinatesDisplay.getConfig().hudX = IntegerArgumentType.getInteger(context, "xpos");
49+
CoordinatesDisplay.getConfig().hudY = y;
50+
51+
return 0;
52+
}
53+
54+
}

0 commit comments

Comments
 (0)