Skip to content

Commit

Permalink
1.21.4 + add hotbar customizabilty
Browse files Browse the repository at this point in the history
  • Loading branch information
Boxadactle committed Dec 21, 2024
1 parent cd76e02 commit ddbb13d
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 173 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## Changes
- Updated to 1.21.3
- Fixed flipped Y text in direction mode
- Updated to 1.21.4
- Hotbar mode is now configurable
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package dev.boxadactle.coordinatesdisplay;

import com.mojang.blaze3d.systems.RenderSystem;
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.GuiUtils;
import dev.boxadactle.boxlib.util.ModLogger;
import dev.boxadactle.boxlib.util.WorldUtils;
import dev.boxadactle.coordinatesdisplay.command.CoordinatesCommand;
import dev.boxadactle.coordinatesdisplay.hud.Hud;
import dev.boxadactle.coordinatesdisplay.position.Position;
import net.minecraft.client.gui.GuiGraphics;

public class CoordinatesDisplay {

public static final String MOD_NAME = "CoordinatesDisplay";

public static final String MOD_ID = "coordinatesdisplay";

public static final String VERSION = "14.0.0";
public static final String VERSION = "15.0.0";

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

Expand All @@ -27,6 +32,7 @@ public class CoordinatesDisplay {
public static String WIKI_DEATHPOS = WIKI + "#deathpos";
public static String WIKI_TEXTS = WIKI + "#text";

static boolean deltaError = false;

public static final ModLogger LOGGER = new ModLogger(MOD_NAME);

Expand Down Expand Up @@ -58,4 +64,37 @@ public static ModConfig getConfig() {
return CONFIG.get();
}

public static void renderHud(GuiGraphics graphics) {
try {
if (CoordinatesDisplay.HUD.shouldRender(CoordinatesDisplay.getConfig().visibilityFilter)) {
RenderSystem.enableBlend();

ModConfig config = CoordinatesDisplay.getConfig();

CoordinatesDisplay.HUD.render(
graphics,
Hud.RenderType.HUD,
Position.of(WorldUtils.getPlayer()),
config.hudX,
config.hudY,
config.renderMode,
config.startCorner,
config.hudScale
);
}
} catch (NullPointerException e) {
if (deltaError) {
throw new RuntimeException(e);
}

CoordinatesDisplay.LOGGER.error("Unknown error from config file");
CoordinatesDisplay.LOGGER.printStackTrace(e);

CoordinatesDisplay.LOGGER.player.warn(GuiUtils.getTranslatable("message.coordinatesdisplay.configError"));
CoordinatesDisplay.CONFIG.resetConfig();

deltaError = true;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@
import dev.boxadactle.coordinatesdisplay.mixin.OverlayMessageTimeAccessor;
import dev.boxadactle.coordinatesdisplay.position.Position;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.biome.Biome;
import oshi.util.tuples.Triplet;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@HudDisplayMode(
value = "hotbar",
ignoreTranslations = true,
positionModifier = HotbarRenderer.HotbarPosition.class,
allowMove = false,
hasBackground = false,
hasXYZ = false,
hasChunkData = false,
hasDirection = false,
hasDirectionInt = false,
hasBiome = false,
hasMCVersion = false,
hasDimension = false
)
Expand All @@ -41,24 +43,34 @@ public RenderingLayout renderOverlay(int x, int y, Position pos) {
return new ColumnLayout(0, 0, 0);
}

List<Component> components = new ArrayList<>();

Triplet<String, String, String> player = this.roundPosition(pos.position.getPlayerPos(), pos.position.getBlockPos(), CoordinatesDisplay.getConfig().decimalPlaces);

Component xyz = definition(GlobalTexts.XYZ,
if (config().renderXYZ) components.add(definition(GlobalTexts.XYZ,
value(player.getA()),
value(player.getB()),
value(player.getC())
);
));

Component direction = definition(GlobalTexts.FACING, value(resolveDirection(ModUtil.getDirectionFromYaw(pos.headRot.wrapYaw()))));
if (config().renderDirection) components.add(definition(GlobalTexts.FACING, value(resolveDirection(ModUtil.getDirectionFromYaw(pos.headRot.wrapYaw())))));

ResourceLocation bKey = pos.world.getBiomeKey();
Biome b = pos.world.getBiome();
Component biome = ModUtil.getBiomeComponent(bKey, b, config().biomeColors, config().dataColor);
if (config().renderBiome) {
ResourceLocation bKey = pos.world.getBiomeKey();
Biome b = pos.world.getBiome();
components.add(ModUtil.getBiomeComponent(bKey, b, config().biomeColors, config().dataColor));
}

Component all = translation("all", xyz, direction, biome);
MutableComponent all = Component.empty();

Iterator<Component> it = components.iterator();
while (it.hasNext()) {
all.append(it.next());
if (it.hasNext()) all.append(Component.literal(" / "));
}

ColumnLayout hud = new ColumnLayout(x, y, 0);
hud.addComponent(new CenteredParagraphComponent(0, all));
hud.addComponent(new CenteredParagraphComponent(0, definition(all)));

return hud;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"hud.coordinatesdisplay.nether_overworld.error": "Not in overworld or nether",

"hud.coordinatesdisplay.hotbar": "Hotbar",
"hud.coordinatesdisplay.hotbar.all": "%s / %s / %s",

"hud.coordinatesdisplay.spawnpoint": "World Spawn (Compass)",
"hud.coordinatesdisplay.spawnpoint.player": "Player",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"hud.coordinatesdisplay.nether_overworld.error": "No estás en el Overworld o Nether",

"hud.coordinatesdisplay.hotbar": "Barra de acceso rápido",
"hud.coordinatesdisplay.hotbar.all": "%s / %s / %s",

"hud.coordinatesdisplay.spawnpoint": "Punto de generación del mundo (brújula)",
"hud.coordinatesdisplay.spawnpoint.player": "Jugador",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"hud.coordinatesdisplay.nether_overworld.error": "オーバーワールドまたはネザーにいません",

"hud.coordinatesdisplay.hotbar": "ホットバー",
"hud.coordinatesdisplay.hotbar.all": "%s / %s / %s",

"hud.coordinatesdisplay.spawnpoint": "World Spawn (Compass)",
"hud.coordinatesdisplay.spawnpoint.player": "Player",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"hud.coordinatesdisplay.nether_overworld.error": "Not in overworld or nether",

"hud.coordinatesdisplay.hotbar": "핫바",
"hud.coordinatesdisplay.hotbar.all": "%s / %s / %s",

"hud.coordinatesdisplay.spawnpoint": "World Spawn (Compass)",
"hud.coordinatesdisplay.spawnpoint.player": "Player",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"hud.coordinatesdisplay.nether_overworld.error": "Not in overworld or nether",

"hud.coordinatesdisplay.hotbar": "Hotbar",
"hud.coordinatesdisplay.hotbar.all": "%s / %s / %s",

"hud.coordinatesdisplay.spawnpoint": "World Spawn (Compass)",
"hud.coordinatesdisplay.spawnpoint.player": "Player",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"hud.coordinatesdisplay.nether_overworld.error": "Зараз не у Незері/Верхньому світі",

"hud.coordinatesdisplay.hotbar": "Панель швидкого доступу",
"hud.coordinatesdisplay.hotbar.all": "%s / %s / %s",

"hud.coordinatesdisplay.spawnpoint": "Точка появи у світі (компас)",
"hud.coordinatesdisplay.spawnpoint.player": "Гравець",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"hud.coordinatesdisplay.nether_overworld.error": "不在主世界或地獄中",

"hud.coordinatesdisplay.hotbar": "快捷欄",
"hud.coordinatesdisplay.hotbar.all": "%s / %s / %s",

"hud.coordinatesdisplay.spawnpoint": "世界重生點(羅盤)",
"hud.coordinatesdisplay.spawnpoint.player": "玩家",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void onInitializeClient() {

ClientTickEvents.END_CLIENT_TICK.register(this::checkBindings);

HudRenderCallback.EVENT.register(this::renderHud);
HudRenderCallback.EVENT.register((g, d) -> CoordinatesDisplay.renderHud(g));

KeyBindingHelper.registerKeyBinding(Bindings.hudEnabled);
KeyBindingHelper.registerKeyBinding(Bindings.coordinatesGUIKeybind);
Expand All @@ -45,35 +45,4 @@ private void checkBindings(Minecraft client) {
}
}

private void renderHud(GuiGraphics guiGraphics, DeltaTracker deltaTracker) {
try {
if (CoordinatesDisplay.HUD.shouldRender(CoordinatesDisplay.getConfig().visibilityFilter)) {
ModConfig config = CoordinatesDisplay.getConfig();

CoordinatesDisplay.HUD.render(
guiGraphics,
Hud.RenderType.HUD,
Position.of(WorldUtils.getPlayer()),
config.hudX,
config.hudY,
config.renderMode,
config.startCorner,
config.hudScale
);
}
} catch (NullPointerException e) {
if (CoordinatesDisplayFabric.deltaError) {
throw new RuntimeException(e);
}

CoordinatesDisplay.LOGGER.error("Unknown error from config file");
CoordinatesDisplay.LOGGER.printStackTrace(e);

CoordinatesDisplay.LOGGER.player.warn(GuiUtils.getTranslatable("message.coordinatesdisplay.configError"));
CoordinatesDisplay.CONFIG.resetConfig();

CoordinatesDisplayFabric.deltaError = true;
}
}

}
6 changes: 3 additions & 3 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"coordinatesdisplay.mixins.json"
],
"depends": {
"fabricloader": ">=0.16",
"minecraft": ">=1.21.2",
"boxlib": "15.*",
"fabricloader": "*",
"minecraft": ">=1.21.4",
"boxlib": "16.*",
"fabric": "*"
},
"recommends": {
Expand Down
2 changes: 1 addition & 1 deletion forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ architectury {

loom {
forge {
mixinConfig "coordinatesdisplay.mixins.json", "coordinatesdisplay-forge.mixins.json"
mixinConfig "coordinatesdisplay.mixins.json"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.ConfigScreenHandler;
import net.minecraftforge.client.event.CustomizeGuiOverlayEvent;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;

Expand All @@ -23,9 +25,9 @@ public class CoordinatesDisplayForge {
public CoordinatesDisplayForge() {
CoordinatesDisplay.init();

ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () ->
new ConfigScreenHandler.ConfigScreenFactory((minecraft, screen) -> new ConfigScreen(screen))
);
ModList.get().getModContainerById(CoordinatesDisplay.MOD_ID).ifPresent(modContainer -> modContainer.registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () ->
new ConfigScreenHandler.ConfigScreenFactory(((minecraft, screen) -> new ConfigScreen(screen)))
));
}

@Mod.EventBusSubscriber(modid = CoordinatesDisplay.MOD_ID, value = Dist.CLIENT)
Expand All @@ -39,6 +41,11 @@ public static void keyInput(InputEvent.Key e) {
}
}

@SubscribeEvent
public static void renderHud(CustomizeGuiOverlayEvent.Chat e) {
CoordinatesDisplay.renderHud(e.getGuiGraphics());
}

}

@Mod.EventBusSubscriber(modid = CoordinatesDisplay.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ side="BOTH"
[[dependencies.coordinatesdisplay]]
modId="minecraft"
mandatory=true
versionRange="[1.21.2,)"
versionRange="[1.21.4,1.22)"
ordering="NONE"
side="BOTH"

[[dependencies.coordinatesdisplay]]
modId="boxlib"
mandatory=true
versionRange="[15.0.0,16.0.0)"
versionRange="[16.0.0,17.0.0)"
ordering="NONE"
side="CLIENT"
Loading

0 comments on commit ddbb13d

Please sign in to comment.