Start on Boat HUD

This commit is contained in:
lukasabbe
2026-02-10 20:40:50 +01:00
parent de243d28cb
commit 714f2fcdbc
6 changed files with 62 additions and 17 deletions
@@ -11,6 +11,7 @@ public class Constants {
public final static Identifier ConfigIdentifier = Identifier.fromNamespaceAndPath(MOD_ID, "config");
//Hud:s
public final static Identifier ElytraHudIdentifier = Identifier.fromNamespaceAndPath(MOD_ID, "elytra_hud");
public final static Identifier BoatHudIdentifier = Identifier.fromNamespaceAndPath(MOD_ID, "boat_hud");
public final static List<Identifier> HudIdentifiers = Arrays.asList(ElytraHudIdentifier);
public final static List<Identifier> HudIdentifiers = Arrays.asList(ElytraHudIdentifier, BoatHudIdentifier);
}
@@ -1,6 +1,7 @@
package com.lukasabbe.simplehud;
import com.lukasabbe.simplehud.config.Config;
import com.lukasabbe.simplehud.huds.BoatHud;
import com.lukasabbe.simplehud.huds.ElytraHud;
import com.lukasabbe.simplehud.huds.SimpleHud;
import com.lukasabbe.simplehud.tools.ElytraTools;
@@ -14,15 +15,14 @@ import java.util.List;
public class SimpleHudMod implements ClientModInitializer {
public static List<SimpleHud> HUD_LIST = Arrays.asList(
new ElytraHud()
new ElytraHud(),
new BoatHud()
);
public static Config configInstance = null;
@Override
public void onInitializeClient() {
Config.HANDLER.load();
configInstance = Config.HANDLER.instance();
Config.HANDLER.load();
HUD_LIST.forEach(simpleHud -> HudElementRegistry.addFirst(simpleHud.getIdentifier(), simpleHud::render));
ClientTickEvents.END_CLIENT_TICK.register(client -> ElytraTools.tickElytraTools());
}
@@ -0,0 +1,25 @@
package com.lukasabbe.simplehud.huds;
import com.lukasabbe.simplehud.Constants;
import com.lukasabbe.simplehud.tools.BoatTools;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.Identifier;
public class BoatHud implements SimpleHud{
@Override
public void render(GuiGraphics graphics, DeltaTracker tracker) {
if(!isHudActivated()) return;
if(client.noRender) return;
if(!BoatTools.isRidingBoat()) return;
if(client.player == null) return;
renderBackPlate(graphics);
}
@Override
public Identifier getIdentifier() {
return Constants.BoatHudIdentifier;
}
}
@@ -2,6 +2,7 @@ package com.lukasabbe.simplehud.huds;
import com.lukasabbe.simplehud.Constants;
import com.lukasabbe.simplehud.SimpleHudMod;
import com.lukasabbe.simplehud.config.Config;
import com.lukasabbe.simplehud.tools.ElytraTools;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.gui.GuiGraphics;
@@ -23,7 +24,7 @@ public class ElytraHud implements SimpleHud {
@Override
public void render(GuiGraphics graphics, DeltaTracker tracker) {
if(!isHudActivated()) return;
//if(!ElytraTools.isFlying()) return;
if(!ElytraTools.isFlying()) return;
if(client.noRender) return;
if(client.player == null) return;
@@ -150,14 +151,6 @@ public class ElytraHud implements SimpleHud {
drawLine(graphics, centerX, centerY, endX, endY, (int) radius, compass_pointer);
}
private String getSpeed(){
return switch (SimpleHudMod.configInstance.speedEnumElytra){
case kmh -> String.format("%.1f km/h", ElytraTools.getSpeedKmh());
case mph -> String.format("%.1f mph", ElytraTools.getSpeedMph());
case ms -> String.format("%.1f m/s", ElytraTools.getSpeedMs());
};
}
@Override
public Identifier getIdentifier() {
return Constants.ElytraHudIdentifier;
@@ -2,7 +2,9 @@ package com.lukasabbe.simplehud.huds;
import com.lukasabbe.simplehud.Constants;
import com.lukasabbe.simplehud.SimpleHudMod;
import com.lukasabbe.simplehud.config.Config;
import com.lukasabbe.simplehud.config.HudPosition;
import com.lukasabbe.simplehud.tools.ElytraTools;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
@@ -20,7 +22,7 @@ public interface SimpleHud {
Identifier getIdentifier();
default boolean isHudActivated(){
return SimpleHudMod.configInstance.HudActivatedList.get(getIdentifier().toShortString());
return Config.HANDLER.instance().HudActivatedList.get(getIdentifier().toShortString());
}
default void renderBackPlate(GuiGraphics graphics){
@@ -49,7 +51,7 @@ public interface SimpleHud {
final int hudHalfWidth = 50;
final int hudHeight = 36;
if(SimpleHudMod.configInstance.ignoreSafeArea){
if( Config.HANDLER.instance().ignoreSafeArea){
return switch (position){
case TOP_LEFT -> new int[]{hudHalfWidth + padding, 60 + padding};
case TOP_RIGHT -> new int[]{screenWidth - hudHalfWidth - padding, 60 + padding};
@@ -93,7 +95,7 @@ public interface SimpleHud {
int screenWidth = client.getWindow().getGuiScaledWidth();
int screenHeight = client.getWindow().getGuiScaledHeight();
int[] pos = calculateHudPosition(screenWidth, screenHeight, SimpleHudMod.configInstance.hudPositionElytra);
int[] pos = calculateHudPosition(screenWidth, screenHeight, Config.HANDLER.instance().hudPositionElytra);
int x = pos[0] - backPlateCenteredX;
int y = pos[1] - backPlateCenteredY;
return new int[]{x, y};
@@ -114,4 +116,12 @@ public interface SimpleHud {
);
}
}
default String getSpeed(){
return switch (Config.HANDLER.instance().speedEnumElytra){
case kmh -> String.format("%.1f km/h", ElytraTools.getSpeedKmh());
case mph -> String.format("%.1f mph", ElytraTools.getSpeedMph());
case ms -> String.format("%.1f m/s", ElytraTools.getSpeedMs());
};
}
}
@@ -0,0 +1,16 @@
package com.lukasabbe.simplehud.tools;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import org.jspecify.annotations.Nullable;
public class BoatTools {
public static boolean isRidingBoat(){
var player = getLocalPlayer();
if(player == null) return false;
return getLocalPlayer().getVehicle() != null;
}
private static @Nullable LocalPlayer getLocalPlayer() {
return Minecraft.getInstance().player;
}
}