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 Oct 27, 2024
2 parents 73c4b05 + 67e15e7 commit 0db6cfa
Show file tree
Hide file tree
Showing 19 changed files with 152 additions and 11 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
## Changes
- Added forge support
- Added 3d compass rendering to config gui
- Added toggle3dCompass subcommand
- Added 3d compass toggle keybind

## New Features
- It is now possible to render a 3d compass client-side in the world
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class Bindings {
public static final KeyMapping changeHudPosition = new KeyMapping("key.coordinatesdisplay.changeHudPos", GLFW.GLFW_KEY_F9, "category.coordinatesdisplay");
public static final KeyMapping cycleDisplayMode = new KeyMapping("key.coordinatesdisplay.cycleDisplayMode", GLFW.GLFW_KEY_M, "category.coordinatesdisplay");

public static final KeyMapping toggle3DCompass = new KeyMapping("key.coordinatesdisplay.toggle3DCompass", GLFW.GLFW_KEY_F8, "category.coordinatesdisplay");

public static void toggleHud() {
CoordinatesDisplay.LOGGER.info("Toggling HUD visibility");
CoordinatesDisplay.CONFIG.get().enabled = !CoordinatesDisplay.CONFIG.get().enabled;
Expand Down Expand Up @@ -61,6 +63,11 @@ public static void cycleDisplayMode() {

CoordinatesDisplay.CONFIG.save();
}

public static void toggle3DCompass() {
CoordinatesDisplay.getConfig().render3dCompass = !CoordinatesDisplay.getConfig().render3dCompass;
CoordinatesDisplay.CONFIG.save();
}

public static void checkBindings(Position pos) {
if (hudEnabled.consumeClick()) toggleHud();
Expand All @@ -76,6 +83,8 @@ public static void checkBindings(Position pos) {
if (changeHudPosition.consumeClick()) openHudPositionGui();

if (cycleDisplayMode.consumeClick()) cycleDisplayMode();

if (toggle3DCompass.consumeClick()) toggle3DCompass();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package dev.boxadactle.coordinatesdisplay;

import com.mojang.blaze3d.vertex.PoseStack;
import dev.boxadactle.boxlib.math.geometry.Vec3;
import dev.boxadactle.boxlib.rendering.Renderer3D;
import dev.boxadactle.boxlib.rendering.renderers.TextRenderer;
import dev.boxadactle.boxlib.util.ClientUtils;
import dev.boxadactle.boxlib.util.GuiUtils;
import dev.boxadactle.boxlib.util.WorldUtils;
import net.minecraft.client.Camera;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.network.chat.Component;

public class CompassRenderer3D extends Renderer3D<CompassRenderer3D> {
public CompassRenderer3D() {
super(false);
}

@Override
public void render(PoseStack poseStack, MultiBufferSource multiBufferSource, double v, double v1, double v2) {
if (WorldUtils.getCamera() != null && CoordinatesDisplay.getConfig().render3dCompass) {
float size = 0.15f;

Camera camera = ClientUtils.getClient().gameRenderer.getMainCamera();
net.minecraft.world.phys.Vec3 cameraPos = camera.getPosition();

TextRenderer north = new TextRenderer(false)
.setPos(new Vec3<>(cameraPos.x, cameraPos.y + 1.0, cameraPos.z - 10.0))
.setText(Component.literal("N"))
.setSize(size)
.setColor(GuiUtils.RED)
.setCentered(true)
.setXray(true);
north.render(poseStack, multiBufferSource, v, v1, v2);

TextRenderer east = new TextRenderer(false)
.setPos(new Vec3<>(cameraPos.x + 10.0, cameraPos.y + 1.0, cameraPos.z))
.setText(Component.literal("E"))
.setSize(size)
.setColor(GuiUtils.GREEN)
.setCentered(true)
.setXray(true);
east.render(poseStack, multiBufferSource, v, v1, v2);

TextRenderer south = new TextRenderer(false)
.setPos(new Vec3<>(cameraPos.x, cameraPos.y + 1.0, cameraPos.z + 10.0))
.setText(Component.literal("S"))
.setSize(size)
.setColor(GuiUtils.YELLOW)
.setCentered(true)
.setXray(true);
south.render(poseStack, multiBufferSource, v, v1, v2);

TextRenderer west = new TextRenderer(false)
.setPos(new Vec3<>(cameraPos.x - 10.0, cameraPos.y + 1.0, cameraPos.z))
.setText(Component.literal("W"))
.setSize(size)
.setColor(GuiUtils.WHITE)
.setCentered(true)
.setXray(true);
west.render(poseStack, multiBufferSource, v, v1, v2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.boxadactle.boxlib.command.BCommandManager;
import dev.boxadactle.boxlib.config.BConfigClass;
import dev.boxadactle.boxlib.config.BConfigHandler;
import dev.boxadactle.boxlib.rendering.RenderQueue;
import dev.boxadactle.boxlib.util.ModLogger;
import dev.boxadactle.coordinatesdisplay.command.CoordinatesCommand;
import dev.boxadactle.coordinatesdisplay.hud.Hud;
Expand Down Expand Up @@ -48,6 +49,9 @@ public static void init() {

// initialize HUD
HUD = new Hud();

// register 3d compass renderer
RenderQueue.addRenderer(new CompassRenderer3D());
}

public static ModConfig getConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class ModConfig implements BConfig {
public boolean includeDecimalsWhenCopying = true;
public TeleportMode teleportMode = TeleportMode.EXECUTE;

public boolean render3dCompass = false;

public static void checkValidity(ModConfig config) throws NullPointerException {
Class<?> clazz = config.getClass();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
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.Bindings;
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 net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;

public class CoordinatesCommand {

public static BCommand createCommand() {
return BCommand.create("coordinates", CoordinatesCommand::openCoordinatesScreen)
.registerSubcommand(new BasicSubcommand("toggle3dCompass", CoordinatesCommand::toggleCompass))
.registerSubcommand(ToggleSubcommand.create())
.registerSubcommand(MoveHudSubcommand.create())
.registerSubcommand(ConfigSubcommand.create())
Expand All @@ -39,4 +43,13 @@ static int noArgs(CommandContext<BCommandSourceStack> ignored) {
return 1;
}

static int toggleCompass(CommandContext<BCommandSourceStack> ignored) {
Bindings.toggle3DCompass();

String message = CoordinatesDisplay.CONFIG.get().render3dCompass ? GuiUtils.ON.getString() : GuiUtils.OFF.getString();
CoordinatesDisplay.LOGGER.player.info(I18n.get("command.coordinatesdisplay.toggle3dCompass", message));

return 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.boxadactle.boxlib.layouts.layout.RowLayout;
import dev.boxadactle.boxlib.math.geometry.Vec3;
import dev.boxadactle.boxlib.math.mathutils.NumberFormatter;
import dev.boxadactle.boxlib.util.GuiUtils;
import dev.boxadactle.coordinatesdisplay.CoordinatesDisplay;
import dev.boxadactle.coordinatesdisplay.ModUtil;
import dev.boxadactle.coordinatesdisplay.hud.HudDisplayMode;
Expand Down Expand Up @@ -145,6 +146,11 @@ public RenderingLayout renderOverlay(int x, int y, Position pos) {
direction.add(pitchText);
}

direction.add((definition(
"rendering3d",
value(config().render3dCompass ? GuiUtils.ON : GuiUtils.OFF)
)));

hud.addComponent(direction);

return new PaddingLayout(x, y, config().padding, hud);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ protected void initConfigButtons() {
TextScreen::new
));

// 3d compass
addConfigLine(new BBooleanButton(
"button.coordinatesdisplay.3dcompass",
CoordinatesDisplay.getConfig().render3dCompass,
(val) -> CoordinatesDisplay.getConfig().render3dCompass = val
));

this.addConfigLine(new BSpacingEntry());

this.addConfigLine(new BCustomButton(Component.translatable("button.coordinatesdisplay.configfile")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"key.coordinatesdisplay.copypostp": "Copy Current Position as /tp command",
"key.coordinatesdisplay.changeHudPos": "Change HUD Position",
"key.coordinatesdisplay.cycleDisplayMode": "Cycle Display Mode (hold shift to go back)",
"key.coordinatesdisplay.toggle3DCompass": "Toggle 3D Compass Rendering",
"category.coordinatesdisplay": "Coordinates Display",

"hud.coordinatesdisplay.north": "North",
Expand Down Expand Up @@ -75,6 +76,7 @@
"hud.coordinatesdisplay.direction.pitch": "Pitch: %s (%s)",
"hud.coordinatesdisplay.direction.positive": "positive %s",
"hud.coordinatesdisplay.direction.negative": "negative %s",
"hud.coordinatesdisplay.direction.rendering3d": "3D Compass: %s",

"hud.coordinatesdisplay.chunk": "Chunk",
"hud.coordinatesdisplay.chunk.position": "Position",
Expand Down Expand Up @@ -109,6 +111,7 @@
"button.coordinatesdisplay.colorconfig": "Colors...",
"button.coordinatesdisplay.deathpos": "Death Position...",
"button.coordinatesdisplay.text": "Text Settings...",
"button.coordinatesdisplay.3dcompass": "Render 3D Compass: %s",
"button.coordinatesdisplay.visibility": "Visibility: %s",
"button.coordinatesdisplay.decimalPlaces": "Decimal Places: %s",
"button.coordinatesdisplay.decimalPlaces.block_pos": "block pos",
Expand Down Expand Up @@ -184,5 +187,6 @@
"command.coordinatesdisplay.config.open.success": "Successfully opened config file",
"command.coordinatesdisplay.config.open.fail": "Could not open config file",
"command.coordinatesdisplay.movehud.fail": "No Y value specified!",
"command.coordinatesdisplay.movehud.get": "Current HUD position: %s, %s"
"command.coordinatesdisplay.movehud.get": "Current HUD position: %s, %s",
"command.coordinatesdisplay.toggle3dCompass": "3D Compass rendering: %s"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"key.coordinatesdisplay.copypostp": "Copiar la posición actual como /tp",
"key.coordinatesdisplay.changeHudPos": "Cambiar la posición del HUD",
"key.coordinatesdisplay.cycleDisplayMode": "Ciclar el modo renderizado (presionar shift para retroceder)",
"key.coordinatesdisplay.toggle3DCompass": "Activar/desactivar el renderizado de la brújula 3D",
"category.coordinatesdisplay": "Coordinates Display",

"hud.coordinatesdisplay.north": "Norte",
Expand Down Expand Up @@ -75,6 +76,7 @@
"hud.coordinatesdisplay.direction.pitch": "Pitch: %s (%s)",
"hud.coordinatesdisplay.direction.positive": "%s positivo",
"hud.coordinatesdisplay.direction.negative": "%s negativo",
"hud.coordinatesdisplay.direction.rendering3d": "Brújula 3D: %s",

"hud.coordinatesdisplay.chunk": "Pieza",
"hud.coordinatesdisplay.chunk.position": "Posición",
Expand Down Expand Up @@ -109,6 +111,7 @@
"button.coordinatesdisplay.colorconfig": "Colores...",
"button.coordinatesdisplay.deathpos": "Posición de muerte...",
"button.coordinatesdisplay.text": "Ajustes de texto...",
"button.coordinatesdisplay.3dcompass": "Renderizar la brújula 3D: %s",
"button.coordinatesdisplay.visibility": "Visibilidad: %s",
"button.coordinatesdisplay.decimalPlaces": "Cantidad de decimales: %s",
"button.coordinatesdisplay.decimalPlaces.block_pos": "posición de bloque",
Expand Down Expand Up @@ -184,5 +187,6 @@
"command.coordinatesdisplay.config.open.success": "Abrió el archivo de configuración con éxito.",
"command.coordinatesdisplay.config.open.fail": "No se pudo abrir el archivo de configuración.",
"command.coordinatesdisplay.movehud.fail": "No Z value specified!",
"command.coordinatesdisplay.movehud.get": "Current HUD position: %s, %s"
"command.coordinatesdisplay.movehud.get": "Current HUD position: %s, %s",
"command.coordinatesdisplay.toggle3dCompass": "Brújula 3D: %s"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"key.coordinatesdisplay.copypostp": "/tpコマンドとして現在の位置をコピー",
"key.coordinatesdisplay.changeHudPos": "HUDの位置を変更",
"key.coordinatesdisplay.cycleDisplayMode": "表示モードを切り替える(戻るにはShiftを押してください)",
"key.coordinatesdisplay.toggle3DCompass": "Toggle 3D Compass Rendering",
"category.coordinatesdisplay": "Coordinates Display",

"hud.coordinatesdisplay.north": "",
Expand Down Expand Up @@ -75,6 +76,7 @@
"hud.coordinatesdisplay.direction.pitch": "Pitch: %s (%s)",
"hud.coordinatesdisplay.direction.positive": "positive %s",
"hud.coordinatesdisplay.direction.negative": "negative %s",
"hud.coordinatesdisplay.direction.rendering3d": "3D Compass: %s",

"hud.coordinatesdisplay.chunk": "Chunk",
"hud.coordinatesdisplay.chunk.position": "Position",
Expand Down Expand Up @@ -109,6 +111,7 @@
"button.coordinatesdisplay.colorconfig": "色設定...",
"button.coordinatesdisplay.deathpos": "死亡位置設定...",
"button.coordinatesdisplay.text": "テキスト設定...",
"button.coordinatesdisplay.3dcompass": "Render 3D Compass: %s",
"button.coordinatesdisplay.visibility": "Visibility: %s",
"button.coordinatesdisplay.decimalPlaces": "小数点以下桁数: %s",
"button.coordinatesdisplay.decimalPlaces.block_pos": "ブロック位置",
Expand Down Expand Up @@ -184,5 +187,6 @@
"command.coordinatesdisplay.config.open.success": "設定ファイルを正常に開きました",
"command.coordinatesdisplay.config.open.fail": "設定ファイルを開けませんでした",
"command.coordinatesdisplay.movehud.fail": "No Z value specified!",
"command.coordinatesdisplay.movehud.get": "Current HUD position: %s, %s"
"command.coordinatesdisplay.movehud.get": "Current HUD position: %s, %s",
"command.coordinatesdisplay.toggle3dCompass": "3D Compass rendering: %s"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"key.coordinatesdisplay.copypostp": "/tp 명령으로 현재 위치를 복사하십시오",
"key.coordinatesdisplay.changeHudPos": "Change HUD Position",
"key.coordinatesdisplay.cycleDisplayMode": "Cycle Display Mode (hold shift to go back)",
"key.coordinatesdisplay.toggle3DCompass": "Toggle 3D Compass Rendering",
"category.coordinatesdisplay": "Coordinates Display",

"hud.coordinatesdisplay.north": "",
Expand Down Expand Up @@ -75,6 +76,7 @@
"hud.coordinatesdisplay.direction.pitch": "Pitch: %s (%s)",
"hud.coordinatesdisplay.direction.positive": "positive %s",
"hud.coordinatesdisplay.direction.negative": "negative %s",
"hud.coordinatesdisplay.direction.rendering3d": "3D Compass: %s",

"hud.coordinatesdisplay.chunk": "Chunk",
"hud.coordinatesdisplay.chunk.position": "Position",
Expand Down Expand Up @@ -109,6 +111,7 @@
"button.coordinatesdisplay.colorconfig": "색상...",
"button.coordinatesdisplay.deathpos": "죽음의 위치",
"button.coordinatesdisplay.text": "텍스트 설정...",
"button.coordinatesdisplay.3dcompass": "Render 3D Compass: %s",
"button.coordinatesdisplay.decimalPlaces": "소수점 표시: %s",
"button.coordinatesdisplay.visibility": "Visibility: %s",
"button.coordinatesdisplay.decimalPlaces.block_pos": "블록 위치",
Expand Down Expand Up @@ -184,5 +187,6 @@
"command.coordinatesdisplay.config.open.success": "Successfully opened config file",
"command.coordinatesdisplay.config.open.fail": "Could not open config file",
"command.coordinatesdisplay.movehud.fail": "No Z value specified!",
"command.coordinatesdisplay.movehud.get": "Current HUD position: %s, %s"
"command.coordinatesdisplay.movehud.get": "Current HUD position: %s, %s",
"command.coordinatesdisplay.toggle3dCompass": "3D Compass rendering: %s"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"key.coordinatesdisplay.copypostp": "Copy Current Position as /tp command",
"key.coordinatesdisplay.changeHudPos": "Change HUD Position",
"key.coordinatesdisplay.cycleDisplayMode": "Cycle Display Mode (hold shift to go back)",
"key.coordinatesdisplay.toggle3DCompass": "Toggle 3D Compass Rendering",
"category.coordinatesdisplay": "Coordinates Display",

"hud.coordinatesdisplay.north": "Север",
Expand Down Expand Up @@ -75,6 +76,7 @@
"hud.coordinatesdisplay.direction.pitch": "Pitch: %s (%s)",
"hud.coordinatesdisplay.direction.positive": "positive %s",
"hud.coordinatesdisplay.direction.negative": "negative %s",
"hud.coordinatesdisplay.direction.rendering3d": "3D Compass: %s",

"hud.coordinatesdisplay.chunk": "Chunk",
"hud.coordinatesdisplay.chunk.position": "Position",
Expand Down Expand Up @@ -109,6 +111,7 @@
"button.coordinatesdisplay.colorconfig": "Цвета...",
"button.coordinatesdisplay.deathpos": "Позиция смерти...",
"button.coordinatesdisplay.text": "Текстовые настройки...",
"button.coordinatesdisplay.3dcompass": "Render 3D Compass: %s",
"button.coordinatesdisplay.visibility": "Visibility: %s",
"button.coordinatesdisplay.decimalPlaces": "Decimal Places: %s",
"button.coordinatesdisplay.decimalPlaces.block_pos": "позиция блока",
Expand Down Expand Up @@ -184,5 +187,6 @@
"command.coordinatesdisplay.config.open.success": "Successfully opened config file",
"command.coordinatesdisplay.config.open.fail": "Could not open config file",
"command.coordinatesdisplay.movehud.fail": "No Z value specified!",
"command.coordinatesdisplay.movehud.get": "Current HUD position: %s, %s"
"command.coordinatesdisplay.movehud.get": "Current HUD position: %s, %s",
"command.coordinatesdisplay.toggle3dCompass": "3D Compass rendering: %s"
}
Loading

0 comments on commit 0db6cfa

Please sign in to comment.