-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into latest
- Loading branch information
Showing
28 changed files
with
315 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
## Changes | ||
- Backport to 1.20.6 | ||
- Fixed hotbar renderer in config screens | ||
- Port to 1.21 | ||
- Removed help subcommand | ||
- Added relative boolean to corner subcommands | ||
- Opening config file with command now errors to chat | ||
- Added teleport mode subcommand | ||
- Visibility, mode, and corner subcommands log to chat | ||
- Integers can now be specified in movehud subcommand | ||
- Boolean can now be specified in toggle subcommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 12 additions & 28 deletions
40
common/src/main/java/dev/boxadactle/coordinatesdisplay/command/ConfigSubcommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,45 @@ | ||
package dev.boxadactle.coordinatesdisplay.command; | ||
|
||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import dev.boxadactle.boxlib.command.BCommandManager; | ||
import dev.boxadactle.boxlib.command.BCommandSourceStack; | ||
import dev.boxadactle.boxlib.command.api.BClientSubcommand; | ||
import dev.boxadactle.boxlib.command.api.BSubcommand; | ||
import dev.boxadactle.boxlib.command.api.subcommand.BasicSubcommand; | ||
import dev.boxadactle.boxlib.scheduling.Scheduling; | ||
import dev.boxadactle.boxlib.util.ClientUtils; | ||
import dev.boxadactle.boxlib.util.GuiUtils; | ||
import dev.boxadactle.coordinatesdisplay.CoordinatesDisplay; | ||
import dev.boxadactle.coordinatesdisplay.ModUtil; | ||
import dev.boxadactle.coordinatesdisplay.screen.ConfigScreen; | ||
|
||
public class ConfigSubcommand implements BClientSubcommand { | ||
@Override | ||
public ArgumentBuilder<BCommandSourceStack, ?> getSubcommand() { | ||
return BCommandManager.literal("config") | ||
.executes(this::openConfigGui); | ||
public class ConfigSubcommand { | ||
public static BSubcommand create() { | ||
return new BasicSubcommand("config", ConfigSubcommand::openConfigGui) | ||
.registerSubcommand(new BasicSubcommand("file", ConfigSubcommand::openConfigFile)) | ||
.registerSubcommand(new BasicSubcommand("reload", ConfigSubcommand::reloadConfig)); | ||
} | ||
|
||
@Override | ||
public void build(ArgumentBuilder<BCommandSourceStack, ?> builder) { | ||
builder.then(BCommandManager.literal("file") | ||
.executes(this::openConfigFile) | ||
); | ||
|
||
builder.then(BCommandManager.literal("reload") | ||
.executes(this::reloadConfig) | ||
); | ||
|
||
builder.then(BCommandManager.literal("gui") | ||
.executes(this::openConfigGui) | ||
); | ||
} | ||
|
||
private int openConfigGui(CommandContext<BCommandSourceStack> ignored) { | ||
static int openConfigGui(CommandContext<BCommandSourceStack> ignored) { | ||
Scheduling.nextTick(() -> ClientUtils.setScreen(new ConfigScreen(null))); | ||
CoordinatesDisplay.LOGGER.info("Opening Config GUI"); | ||
|
||
return 0; | ||
} | ||
|
||
private int openConfigFile(CommandContext<BCommandSourceStack> ignored) { | ||
static int openConfigFile(CommandContext<BCommandSourceStack> ignored) { | ||
if (ModUtil.openConfigFile()) { | ||
CoordinatesDisplay.LOGGER.player.info(GuiUtils.getTranslatable("command.coordinatesdisplay.config.open.success")); | ||
return 0; | ||
} else { | ||
CoordinatesDisplay.LOGGER.info(GuiUtils.getTranslatable("command.coordinatesdisplay.config.open.fail")); | ||
CoordinatesDisplay.LOGGER.player.error(GuiUtils.getTranslatable("command.coordinatesdisplay.config.open.fail")); | ||
return 1; | ||
} | ||
} | ||
|
||
private int reloadConfig(CommandContext<BCommandSourceStack> ignored) { | ||
static int reloadConfig(CommandContext<BCommandSourceStack> ignored) { | ||
CoordinatesDisplay.CONFIG.reload(); | ||
CoordinatesDisplay.LOGGER.player.info(GuiUtils.getTranslatable("command.coordinatesdisplay.config.reload")); | ||
CoordinatesDisplay.LOGGER.info("Reloaded all config"); | ||
|
||
return 0; | ||
} | ||
} | ||
} |
67 changes: 19 additions & 48 deletions
67
common/src/main/java/dev/boxadactle/coordinatesdisplay/command/CoordinatesCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,42 @@ | ||
package dev.boxadactle.coordinatesdisplay.command; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import dev.boxadactle.boxlib.command.BCommandSourceStack; | ||
import dev.boxadactle.boxlib.command.api.BClientCommand; | ||
import dev.boxadactle.boxlib.command.api.BCommand; | ||
import dev.boxadactle.boxlib.command.api.subcommand.BasicSubcommand; | ||
import dev.boxadactle.boxlib.scheduling.Scheduling; | ||
import dev.boxadactle.boxlib.util.ClientUtils; | ||
import dev.boxadactle.boxlib.util.GuiUtils; | ||
import dev.boxadactle.boxlib.util.WorldUtils; | ||
import dev.boxadactle.coordinatesdisplay.CoordinatesDisplay; | ||
import dev.boxadactle.coordinatesdisplay.position.Position; | ||
import dev.boxadactle.coordinatesdisplay.screen.CoordinatesScreen; | ||
import dev.boxadactle.coordinatesdisplay.screen.config.PositionScreen; | ||
import dev.boxadactle.coordinatesdisplay.position.Position; | ||
import net.minecraft.network.chat.Component; | ||
|
||
import java.util.List; | ||
import net.minecraft.client.resources.language.I18n; | ||
|
||
public class CoordinatesCommand { | ||
|
||
public static BClientCommand create() { | ||
return BClientCommand.create("coordinates", CoordinatesCommand::openCoordinatesScreen) | ||
.registerSubcommand(new ConfigSubcommand()) | ||
.registerSubcommand(new CornerSubcommand()) | ||
.registerSubcommand("help", CoordinatesCommand::showHelpMessage) | ||
.registerSubcommand(new ModeSubcommand()) | ||
.registerSubcommand(new VisibilitySubcommand()) | ||
.registerSubcommand("movehud", CoordinatesCommand::moveHud) | ||
.registerSubcommand(new PositionSubcommand()) | ||
.registerSubcommand("toggle", CoordinatesCommand::toggle); | ||
public static BCommand createCommand() { | ||
return BCommand.create("coordinates", CoordinatesCommand::openCoordinatesScreen) | ||
.registerSubcommand(ToggleSubcommand.create()) | ||
.registerSubcommand(MoveHudSubcommand.create()) | ||
.registerSubcommand(ConfigSubcommand.create()) | ||
.registerSubcommand(CornerSubcommand.create()) | ||
.registerSubcommand(ModeSubcommand.create()) | ||
.registerSubcommand(VisibilitySubcommand.create()) | ||
.registerSubcommand(PositionSubcommand.create()) | ||
.registerSubcommand(TeleportModeSubcommand.create()); | ||
} | ||
|
||
private static int openCoordinatesScreen(CommandContext<BCommandSourceStack> ignored) { | ||
static int openCoordinatesScreen(CommandContext<BCommandSourceStack> ignored) { | ||
Scheduling.nextTick(() -> ClientUtils.setScreen(new CoordinatesScreen(Position.of(WorldUtils.getPlayer())))); | ||
|
||
return 0; | ||
} | ||
|
||
private static int toggle(CommandContext<BCommandSourceStack> ignored) { | ||
CoordinatesDisplay.getConfig().enabled = !CoordinatesDisplay.getConfig().enabled; | ||
CoordinatesDisplay.CONFIG.save(); | ||
|
||
return 0; | ||
} | ||
|
||
private static int showHelpMessage(CommandContext<BCommandSourceStack> ignored) { | ||
List<Component> components = ImmutableList.of( | ||
GuiUtils.colorize(Component.translatable("command.coordinatesdisplay.helpmenu"), GuiUtils.AQUA), | ||
Component.translatable("command.coordinatesdisplay.config"), | ||
Component.translatable("command.coordinatesdisplay.gui"), | ||
Component.translatable("command.coordinatesdisplay.help"), | ||
Component.translatable("command.coordinatesdisplay.mode"), | ||
Component.translatable("command.coordinatesdisplay.movehud"), | ||
Component.translatable("command.coordinatesdisplay.position"), | ||
Component.translatable("command.coordinatesdisplay.visibility") | ||
); | ||
static int noArgs(CommandContext<BCommandSourceStack> ignored) { | ||
CoordinatesDisplay.LOGGER.player.error(I18n.get("command.coordinatesdisplay.emptyArgs")); | ||
|
||
components.forEach(c -> { | ||
CoordinatesDisplay.LOGGER.player.chat(c); | ||
}); | ||
|
||
return 0; | ||
} | ||
|
||
private static int moveHud(CommandContext<BCommandSourceStack> ignored) { | ||
Scheduling.nextTick(() -> ClientUtils.setScreen(new PositionScreen(null))); | ||
|
||
return 0; | ||
return 1; | ||
} | ||
|
||
} | ||
} |
72 changes: 42 additions & 30 deletions
72
common/src/main/java/dev/boxadactle/coordinatesdisplay/command/CornerSubcommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,55 @@ | ||
package dev.boxadactle.coordinatesdisplay.command; | ||
|
||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import dev.boxadactle.boxlib.command.BCommandManager; | ||
import dev.boxadactle.boxlib.command.BCommandSourceStack; | ||
import dev.boxadactle.boxlib.command.api.BClientSubcommand; | ||
import dev.boxadactle.boxlib.command.api.BSubcommand; | ||
import dev.boxadactle.boxlib.command.api.subcommand.BasicSubcommand; | ||
import dev.boxadactle.boxlib.command.api.subcommand.BooleanSubcommand; | ||
import dev.boxadactle.boxlib.math.geometry.Dimension; | ||
import dev.boxadactle.boxlib.math.geometry.Vec2; | ||
import dev.boxadactle.boxlib.util.ClientUtils; | ||
import dev.boxadactle.coordinatesdisplay.CoordinatesDisplay; | ||
import dev.boxadactle.coordinatesdisplay.registry.StartCorner; | ||
import net.minecraft.client.resources.language.I18n; | ||
|
||
public class CornerSubcommand implements BClientSubcommand { | ||
@Override | ||
public ArgumentBuilder<BCommandSourceStack, ?> getSubcommand() { | ||
return BCommandManager.literal("corner"); | ||
} | ||
public class CornerSubcommand { | ||
|
||
public static BSubcommand create() { | ||
StartCorner[] corners = StartCorner.values(); | ||
|
||
@Override | ||
public void build(ArgumentBuilder<BCommandSourceStack, ?> builder) { | ||
StartCorner[] corners = StartCorner.values(); | ||
BasicSubcommand subcommand = new BasicSubcommand("corner", CoordinatesCommand::noArgs); | ||
|
||
for (StartCorner corner : corners) { | ||
builder.then(BCommandManager.literal(corner.name().toLowerCase()) | ||
.executes(c -> { | ||
Vec2<Integer> relative = corner.getModifier().getRelativePos( | ||
CoordinatesDisplay.HUD.getRect(), | ||
new Dimension<>( | ||
Math.round(ClientUtils.getClient().getWindow().getGuiScaledWidth() / CoordinatesDisplay.getConfig().hudScale), | ||
Math.round(ClientUtils.getClient().getWindow().getGuiScaledHeight() / CoordinatesDisplay.getConfig().hudScale) | ||
) | ||
); | ||
|
||
CoordinatesDisplay.getConfig().hudX = relative.getX(); | ||
CoordinatesDisplay.getConfig().hudY = relative.getY(); | ||
CoordinatesDisplay.getConfig().startCorner = corner; | ||
CoordinatesDisplay.CONFIG.save(); | ||
return 0; | ||
}) | ||
); | ||
subcommand.registerSubcommand(new BasicSubcommand(corner.name().toLowerCase(), (context) -> { | ||
CoordinatesDisplay.getConfig().startCorner = corner; | ||
CoordinatesDisplay.CONFIG.save(); | ||
return 0; | ||
}).registerSubcommand(new BooleanSubcommand("relative", (context, bool) -> { | ||
if (bool) { | ||
Vec2<Integer> relative = relative(corner); | ||
|
||
CoordinatesDisplay.getConfig().hudX = relative.getX(); | ||
CoordinatesDisplay.getConfig().hudY = relative.getY(); | ||
} | ||
|
||
CoordinatesDisplay.getConfig().startCorner = corner; | ||
CoordinatesDisplay.CONFIG.save(); | ||
|
||
CoordinatesDisplay.LOGGER.player.info(I18n.get("button.coordinatesdisplay.startcorner", I18n.get("button.coordinatesdisplay.startcorner." + corner.name().toLowerCase()))); | ||
|
||
return 0; | ||
}))); | ||
} | ||
|
||
return subcommand; | ||
} | ||
} | ||
|
||
static Vec2<Integer> relative(StartCorner corner) { | ||
return corner.getModifier().getRelativePos( | ||
CoordinatesDisplay.HUD.getRect(), | ||
new Dimension<>( | ||
Math.round(ClientUtils.getClient().getWindow().getGuiScaledWidth() / CoordinatesDisplay.getConfig().hudScale), | ||
Math.round(ClientUtils.getClient().getWindow().getGuiScaledHeight() / CoordinatesDisplay.getConfig().hudScale) | ||
) | ||
); | ||
} | ||
|
||
} |
38 changes: 19 additions & 19 deletions
38
common/src/main/java/dev/boxadactle/coordinatesdisplay/command/ModeSubcommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
package dev.boxadactle.coordinatesdisplay.command; | ||
|
||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import dev.boxadactle.boxlib.command.BCommandManager; | ||
import dev.boxadactle.boxlib.command.BCommandSourceStack; | ||
import dev.boxadactle.boxlib.command.api.BClientSubcommand; | ||
import dev.boxadactle.boxlib.command.api.BSubcommand; | ||
import dev.boxadactle.boxlib.command.api.subcommand.BasicSubcommand; | ||
import dev.boxadactle.coordinatesdisplay.CoordinatesDisplay; | ||
import dev.boxadactle.coordinatesdisplay.registry.DisplayMode; | ||
import net.minecraft.client.resources.language.I18n; | ||
|
||
public class ModeSubcommand implements BClientSubcommand { | ||
@Override | ||
public ArgumentBuilder<BCommandSourceStack, ?> getSubcommand() { | ||
return BCommandManager.literal("mode"); | ||
} | ||
public class ModeSubcommand { | ||
|
||
@Override | ||
public void build(ArgumentBuilder<BCommandSourceStack, ?> builder) { | ||
public static BSubcommand create() { | ||
DisplayMode[] modes = DisplayMode.values(); | ||
|
||
BSubcommand subcommand = new BasicSubcommand("mode", CoordinatesCommand::noArgs); | ||
|
||
for (DisplayMode mode : modes) { | ||
builder.then(BCommandManager.literal(mode.getId()) | ||
.executes(c -> { | ||
CoordinatesDisplay.getConfig().renderMode = mode; | ||
CoordinatesDisplay.CONFIG.save(); | ||
return 0; | ||
}) | ||
); | ||
subcommand.registerSubcommand(new BasicSubcommand(mode.name().toLowerCase(), (context) -> { | ||
CoordinatesDisplay.getConfig().renderMode = mode; | ||
CoordinatesDisplay.CONFIG.save(); | ||
|
||
CoordinatesDisplay.LOGGER.player.info(I18n.get("button.coordinatesdisplay.displayMode", mode.getName())); | ||
|
||
return 0; | ||
})); | ||
} | ||
|
||
return subcommand; | ||
} | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
common/src/main/java/dev/boxadactle/coordinatesdisplay/command/MoveHudSubcommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package dev.boxadactle.coordinatesdisplay.command; | ||
|
||
import com.mojang.brigadier.arguments.IntegerArgumentType; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import dev.boxadactle.boxlib.command.BCommandSourceStack; | ||
import dev.boxadactle.boxlib.command.api.BSubcommand; | ||
import dev.boxadactle.boxlib.command.api.subcommand.BasicSubcommand; | ||
import dev.boxadactle.boxlib.command.api.subcommand.IntegerSubcommand; | ||
import dev.boxadactle.boxlib.scheduling.Scheduling; | ||
import dev.boxadactle.boxlib.util.ClientUtils; | ||
import dev.boxadactle.coordinatesdisplay.CoordinatesDisplay; | ||
import dev.boxadactle.coordinatesdisplay.screen.config.PositionScreen; | ||
import net.minecraft.client.resources.language.I18n; | ||
|
||
public class MoveHudSubcommand { | ||
|
||
public static BSubcommand create() { | ||
return new BasicSubcommand("movehud", MoveHudSubcommand::moveHud) | ||
.registerSubcommand(new BasicSubcommand("get", MoveHudSubcommand::get)) | ||
.registerSubcommand(new IntegerSubcommand("xpos", MoveHudSubcommand::xOnly) | ||
.registerSubcommand(new IntegerSubcommand("ypos", MoveHudSubcommand::hudPos)) | ||
); | ||
} | ||
|
||
static int moveHud(CommandContext<BCommandSourceStack> ignored) { | ||
Scheduling.nextTick(() -> ClientUtils.setScreen(new PositionScreen(null))); | ||
|
||
return 0; | ||
} | ||
|
||
static int get(CommandContext<BCommandSourceStack> ignored) { | ||
CoordinatesDisplay.LOGGER.player.info(I18n.get( | ||
"command.coordinatesdisplay.movehud.get", | ||
CoordinatesDisplay.getConfig().hudX, | ||
CoordinatesDisplay.getConfig().hudY | ||
)); | ||
|
||
return 0; | ||
} | ||
|
||
static int xOnly(CommandContext<BCommandSourceStack> ignored, int i) { | ||
CoordinatesDisplay.LOGGER.player.error(I18n.get("command.coordinatesdisplay.movehud.fail")); | ||
|
||
return 1; | ||
} | ||
|
||
static int hudPos(CommandContext<BCommandSourceStack> context, int y) { | ||
CoordinatesDisplay.getConfig().hudX = IntegerArgumentType.getInteger(context, "xpos"); | ||
CoordinatesDisplay.getConfig().hudY = y; | ||
|
||
return 0; | ||
} | ||
|
||
} |
Oops, something went wrong.