Skip to content

Commit

Permalink
Merge branch 'development' into latest
Browse files Browse the repository at this point in the history
  • Loading branch information
Boxadactle committed Jun 25, 2024
2 parents ed9d114 + 110de3b commit 88d5194
Show file tree
Hide file tree
Showing 44 changed files with 499 additions and 727 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Coordinates Display is a Client-side mod that adds an HUD to show your position,

# Dependencies

Both versions of this mod embed [BoxLib](https://github.com/Boxadactle/BoxLib/), a Client-side library mod developed by me.
#### Versions 10.0.0+ of this mod require [BoxLib](https://modrinth.com/mod/boxlib) a Client-side library mod developed by me.

## Fabric

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package dev.boxadactle.coordinatesdisplay;

import com.mojang.blaze3d.platform.InputConstants;
import dev.boxadactle.boxlib.command.BCommandManager;
import dev.boxadactle.boxlib.config.BConfigClass;
import dev.boxadactle.boxlib.config.BConfigHandler;
import dev.boxadactle.boxlib.util.ClientUtils;
import dev.boxadactle.boxlib.util.ModLogger;
import dev.boxadactle.boxlib.util.WorldUtils;
import dev.boxadactle.coordinatesdisplay.command.CoordinatesCommand;
import dev.boxadactle.coordinatesdisplay.config.screen.ConfigScreen;
import dev.boxadactle.coordinatesdisplay.config.screen.HudPositionScreen;
import dev.boxadactle.coordinatesdisplay.hud.CoordinatesHuds;
import dev.boxadactle.coordinatesdisplay.hud.Hud;
import dev.boxadactle.coordinatesdisplay.config.ModConfig;
import dev.boxadactle.coordinatesdisplay.hud.renderer.*;
import dev.boxadactle.coordinatesdisplay.hud.visibility.AlwaysVisibility;
import dev.boxadactle.coordinatesdisplay.hud.visibility.HoldCompassVisibility;
import dev.boxadactle.coordinatesdisplay.hud.visibility.NeverVisibility;
import dev.boxadactle.coordinatesdisplay.hud.visibility.OwnCompassVisibility;
import dev.boxadactle.coordinatesdisplay.hud.visibility.*;
import dev.boxadactle.coordinatesdisplay.position.Position;

public class CoordinatesDisplay {
Expand Down Expand Up @@ -71,6 +70,11 @@ public static void init() {
CoordinatesHuds.registerVisibilityFilter(NeverVisibility.class);
CoordinatesHuds.registerVisibilityFilter(HoldCompassVisibility.class);
CoordinatesHuds.registerVisibilityFilter(OwnCompassVisibility.class);
CoordinatesHuds.registerVisibilityFilter(HoldMapVisibility.class);
CoordinatesHuds.registerVisibilityFilter(OwnMapVisibility.class);

LOGGER.info("Registering client commands");
BCommandManager.register(CoordinatesCommand.create());

LOGGER.info("Initializing hud");
HUD = new Hud();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public CoordinatesScreen(Position pos) {
@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
this.renderBackground(guiGraphics, mouseX, mouseY, delta);
super.render(guiGraphics, mouseX, mouseY, delta);

Vec3<Double> player = pos.position.getPlayerPos();

Expand All @@ -40,8 +41,6 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta)

guiGraphics.drawCenteredString(this.font, Component.translatable("message.coordinatesdisplay.at"), this.width / 2, (this.height / 4) - 20, GuiUtils.WHITE);
guiGraphics.drawCenteredString(this.font, Component.translatable("message.coordinatesdisplay.location", x, y, z), this.width / 2, (this.height / 4), GuiUtils.WHITE);

super.render(guiGraphics, mouseX, mouseY, delta);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Objects;

@SuppressWarnings("unchecked")
public class ModUtil {
Expand All @@ -39,13 +40,13 @@ public static String parseText(String text, Position pos) {

String direction = getDirectionFromYaw(Mth.wrapDegrees(c.cameraEntity.getXRot()));

Pair[] supported = new Pair[]{
Pair<String, ?>[] supported = new Pair[]{
new Pair<>("dimension", pos.world.getDimension(true)),
new Pair<>("x", x),
new Pair<>("y", y),
new Pair<>("z", z),
new Pair<>("direction", direction),
new Pair<>("name", c.player.getDisplayName().getString())
new Pair<>("name", Objects.requireNonNull(c.player.getDisplayName()).getString())
};
for (Pair<?, ?> pair : supported) {
newTextComponent = newTextComponent.replaceAll("\\{" + pair.getFirst() + "}", (String) pair.getSecond());
Expand Down Expand Up @@ -210,10 +211,6 @@ public static <T> boolean not(T val, T ...compare) {
return toReturn;
}

public static BlockPos toBlockPos(Vec3<Integer> pos) {
return new BlockPos(pos.getX(), pos.getY(), pos.getZ());
}

public static Vec3i doubleVecToIntVec(net.minecraft.world.phys.Vec3 vec) {
return new Vec3i((int)Math.round(vec.x), (int)Math.round(vec.y), (int)Math.round(vec.z));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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.util.GuiUtils;
import dev.boxadactle.coordinatesdisplay.CoordinatesDisplay;
import dev.boxadactle.coordinatesdisplay.ModUtil;

public class ConfigSubcommand implements BClientSubcommand {
@Override
public ArgumentBuilder<BCommandSourceStack, ?> getSubcommand() {
return BCommandManager.literal("config")
.executes(this::openConfigGui);
}

@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) {
CoordinatesDisplay.shouldConfigGuiOpen = true;
CoordinatesDisplay.LOGGER.info("Opening Config GUI");

return 0;
}

private 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"));
return 1;
}
}

private 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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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.util.GuiUtils;
import dev.boxadactle.coordinatesdisplay.CoordinatesDisplay;
import net.minecraft.network.chat.Component;

import java.util.List;

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("movehud", CoordinatesCommand::moveHud)
.registerSubcommand(new PositionSubcommand());
}

private static int openCoordinatesScreen(CommandContext<BCommandSourceStack> ignored) {

CoordinatesDisplay.shouldCoordinatesGuiOpen = true;

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")
);

components.forEach(c -> {
CoordinatesDisplay.LOGGER.player.chat(c);
});

return 0;
}

private static int moveHud(CommandContext<BCommandSourceStack> ignored) {
CoordinatesDisplay.shouldHudPositionGuiOpen = true;

return 0;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +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.coordinatesdisplay.CoordinatesDisplay;
import dev.boxadactle.coordinatesdisplay.config.ModConfig;

public class CornerSubcommand implements BClientSubcommand {
@Override
public ArgumentBuilder<BCommandSourceStack, ?> getSubcommand() {
return BCommandManager.literal("corner");
}

@Override
public void build(ArgumentBuilder<BCommandSourceStack, ?> builder) {
ModConfig.StartCorner[] corners = ModConfig.StartCorner.values();

for (ModConfig.StartCorner corner : corners) {
builder.then(BCommandManager.literal(corner.name().toLowerCase())
.executes(c -> {
CoordinatesDisplay.getConfig().startCorner = corner;
CoordinatesDisplay.CONFIG.save();
return 0;
})
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +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.coordinatesdisplay.CoordinatesDisplay;
import dev.boxadactle.coordinatesdisplay.hud.CoordinatesHuds;

public class ModeSubcommand implements BClientSubcommand {
@Override
public ArgumentBuilder<BCommandSourceStack, ?> getSubcommand() {
return BCommandManager.literal("mode");
}

@Override
public void build(ArgumentBuilder<BCommandSourceStack, ?> builder) {
String[] modes = CoordinatesHuds.registeredOverlays.keySet().toArray(new String[0]);

for (String mode : modes) {
builder.then(BCommandManager.literal(mode.toLowerCase())
.executes(c -> {
CoordinatesDisplay.getConfig().renderMode = mode;
CoordinatesDisplay.CONFIG.save();
return 0;
})
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
package dev.boxadactle.coordinatesdisplay.neoforge.command;
package dev.boxadactle.coordinatesdisplay.command;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
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.util.GuiUtils;
import dev.boxadactle.boxlib.util.WorldUtils;
import dev.boxadactle.coordinatesdisplay.CoordinatesDisplay;
import dev.boxadactle.coordinatesdisplay.ModUtil;
import dev.boxadactle.coordinatesdisplay.position.Position;
import net.minecraft.client.Minecraft;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;

public class PositionCommand extends CoordinatesCommand {
public class PositionSubcommand implements BClientSubcommand {
@Override
public String getName() {
return "position";
public ArgumentBuilder<BCommandSourceStack, ?> getSubcommand() {
return BCommandManager.literal("position");
}

@Override
public void build(LiteralArgumentBuilder<CommandSourceStack> builder) {

public void build(ArgumentBuilder<BCommandSourceStack, ?> builder) {
// send in chat
builder.then(Commands.literal("chat")
builder.then(BCommandManager.literal("chat")
.executes(this::sendPosInChat)
);

// copy to clipboard
builder.then(Commands.literal("copy")
builder.then(BCommandManager.literal("copy")
.executes(this::copyPos)
);

// copy as tp
builder.then(Commands.literal("copytp")
builder.then(BCommandManager.literal("copytp")
.executes(this::copyPosTp)
);

}

private int sendPosInChat(CommandContext<CommandSourceStack> context) {
private int sendPosInChat(CommandContext<BCommandSourceStack> ignored) {

Position pos = Position.of(WorldUtils.getPlayer());

Expand All @@ -46,32 +46,29 @@ private int sendPosInChat(CommandContext<CommandSourceStack> context) {
return 0;
}

private int copyPos(CommandContext<CommandSourceStack> context) {

private int copyPos(CommandContext<BCommandSourceStack> context) {
Position pos = Position.of(WorldUtils.getPlayer());

Minecraft.getInstance().keyboardHandler.setClipboard(ModUtil.parseText(CoordinatesDisplay.CONFIG.get().copyPosMessage, pos));
CoordinatesDisplay.LOGGER.player.info(super.translatable("command.coordinatesdisplay.position.copy"));
CoordinatesDisplay.LOGGER.player.info(GuiUtils.getTranslatable("command.coordinatesdisplay.position.copy"));
CoordinatesDisplay.LOGGER.info("Copied location to clipboard");

return 0;

}

private int copyPosTp(CommandContext<CommandSourceStack> context) {
private int copyPosTp(CommandContext<BCommandSourceStack> context) {
try {
Position pos = Position.of(WorldUtils.getPlayer());

Minecraft.getInstance().keyboardHandler.setClipboard(CoordinatesDisplay.getConfig().teleportMode.toCommand(pos));

CoordinatesDisplay.LOGGER.player.info(super.translatable("command.coordinatesdisplay.position.copytp"));
CoordinatesDisplay.LOGGER.player.info(GuiUtils.getTranslatable("command.coordinatesdisplay.position.copytp"));

return 0;
} catch (Exception ignored) {
CoordinatesDisplay.LOGGER.player.info(super.translatable("command.coordinatesdisplay.internalError"));
CoordinatesDisplay.LOGGER.player.info(GuiUtils.getTranslatable("command.coordinatesdisplay.internalError"));
return 1;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
)
public class SpawnpointRenderer implements HudRenderer {

public static ResourceLocation SOUTH = new ResourceLocation("textures/item/compass_00.png");
public static ResourceLocation WEST = new ResourceLocation("textures/item/compass_07.png");
public static ResourceLocation NORTH = new ResourceLocation("textures/item/compass_16.png");
public static ResourceLocation EAST = new ResourceLocation("textures/item/compass_25.png");
public static ResourceLocation SOUTH = ResourceLocation.withDefaultNamespace("textures/item/compass_00.png");
public static ResourceLocation WEST = ResourceLocation.withDefaultNamespace("textures/item/compass_07.png");
public static ResourceLocation NORTH = ResourceLocation.withDefaultNamespace("textures/item/compass_16.png");
public static ResourceLocation EAST = ResourceLocation.withDefaultNamespace("textures/item/compass_25.png");

// unfortunately, I don't think you can access the player's
// spawnpoint unless your mod is server-side
Expand Down Expand Up @@ -199,7 +199,7 @@ private ResourceLocation resolveCompassTexture(double d) {
};

String texture = "textures/" + textures[(int) (range1 * textures.length)] + ".png";
return new ResourceLocation("minecraft", texture);
return ResourceLocation.withDefaultNamespace(texture);
}

@Override
Expand Down
Loading

0 comments on commit 88d5194

Please sign in to comment.