Add horse

This commit is contained in:
lukasabbe
2026-02-21 17:03:21 +01:00
parent 9a8147eab0
commit 5870414653
8 changed files with 222 additions and 10 deletions
@@ -13,6 +13,7 @@ public class Constants {
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 Identifier MinecartHudIdentifier = Identifier.fromNamespaceAndPath(MOD_ID, "minecart_hud");
public final static Identifier HorseHudIdentifier = Identifier.fromNamespaceAndPath(MOD_ID, "horse_hud");
public final static List<Identifier> HudIdentifiers = Arrays.asList(ElytraHudIdentifier, BoatHudIdentifier, MinecartHudIdentifier);
public final static List<Identifier> HudIdentifiers = Arrays.asList(ElytraHudIdentifier, BoatHudIdentifier, MinecartHudIdentifier, HorseHudIdentifier);
}
@@ -1,10 +1,7 @@
package com.lukasabbe.simpletransporthud;
import com.lukasabbe.simpletransporthud.config.Config;
import com.lukasabbe.simpletransporthud.huds.BoatHud;
import com.lukasabbe.simpletransporthud.huds.ElytraHud;
import com.lukasabbe.simpletransporthud.huds.MinecartHud;
import com.lukasabbe.simpletransporthud.huds.SimpleHud;
import com.lukasabbe.simpletransporthud.huds.*;
import com.lukasabbe.simpletransporthud.tools.ElytraTools;
import com.lukasabbe.simpletransporthud.tools.EntityTools;
import net.fabricmc.api.ClientModInitializer;
@@ -21,7 +18,8 @@ public class SimpleTransportHudMod implements ClientModInitializer {
public static List<SimpleHud> HUD_LIST = Arrays.asList(
new ElytraHud(),
new BoatHud(),
new MinecartHud()
new MinecartHud(),
new HorseHud()
);
@Override
@@ -37,6 +37,8 @@ public class Config {
public HudPosition hudPositionBoat = HudPosition.CENTER;
@SerialEntry
public HudPosition hudPositionMinecart = HudPosition.CENTER;
@SerialEntry
public HudPosition hudPositionHorse = HudPosition.CENTER;
//Hud speed unit
@@ -46,6 +48,8 @@ public class Config {
public SpeedEnum speedEnumBoat = SpeedEnum.kmh;
@SerialEntry
public SpeedEnum speedEnumMinecart = SpeedEnum.kmh;
@SerialEntry
public SpeedEnum speedEnumHorse = SpeedEnum.kmh;
//Display speed
@SerialEntry
@@ -54,6 +58,8 @@ public class Config {
public int boatHudDelay = 0;
@SerialEntry
public int minecartHudDelay = 0;
@SerialEntry
public int horseHudDelay = 0;
private Map<String, Boolean> getActiveHuds() {
Map<String, Boolean> activatedHuds = new IdentityHashMap<>();
@@ -1,16 +1,29 @@
package com.lukasabbe.simpletransporthud.huds;
import com.lukasabbe.simpletransporthud.Constants;
import com.lukasabbe.simpletransporthud.config.Config;
import com.lukasabbe.simpletransporthud.config.HudPosition;
import com.lukasabbe.simpletransporthud.tools.EntityTools;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.animal.equine.AbstractHorse;
public class HorseHud extends RideableHud {
@Override
public void render(GuiGraphics graphics, DeltaTracker tracker) {
if(!EntityTools.isRidingEntity(AbstractHorse.class)) return;
super.render(graphics, tracker);
}
@Override
public Identifier getIdentifier() {
return null;
return Constants.HorseHudIdentifier;
}
@Override
public HudPosition getHudPosition() {
return null;
return Config.HANDLER.instance().hudPositionHorse;
}
}
@@ -1,11 +1,188 @@
package com.lukasabbe.simpletransporthud.huds;
import com.lukasabbe.simpletransporthud.config.Config;
import com.lukasabbe.simpletransporthud.tools.EntityTools;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.util.Mth;
public abstract class RideableHud implements SimpleHud {
@Override
public void render(GuiGraphics graphics, DeltaTracker tracker) {
if(!isHudActivated()) return;
if(client.noRender) return;
if(client.player == null) return;
if(EntityTools.getTime() < Config.HANDLER.instance().boatHudDelay) return;
int[] pos = getCornerPos();
int x = pos[0];
int y = pos[1];
renderBackPlate(graphics);
int textX = 5;
float textScale = 0.6f;
int whiteColor = 0xFFFFFFFF;
//Draw speed
int speedTextY = 5;
renderCenteredScaledText(graphics, getSpeed(Config.HANDLER.instance().speedEnumBoat), x + textX, y + speedTextY, whiteColor, textScale);
//Draw coordinates
int coordinatesTextY = 15;
int maxAvailableWidth = 40;
String coordinatesText = String.format("%.0f:%.0f:%.0f", client.player.getX(), client.player.getY(), client.player.getZ());
int textWidth = client.font.width(coordinatesText);
float maxScale = (float) maxAvailableWidth / textWidth;
float finalScale = Math.min(textScale, maxScale);
renderCenteredScaledText(graphics, coordinatesText, x + textX, y + coordinatesTextY, whiteColor, finalScale);
int textureCornerX = 0;
int textureCornerY = 0;
int verticalArrowWidth = 8;
int verticalArrowHeight = 6;
int leftGreenArrowX = x + 40;
int rightRedArrowX = x + 50;
int verticalArrowY = y + 5;
if(client.options.keyLeft.isDown()){
graphics.blit(
RenderPipelines.GUI_TEXTURED,
left_green_arrow,
leftGreenArrowX, verticalArrowY,
textureCornerX, textureCornerY,
verticalArrowWidth, verticalArrowHeight,
verticalArrowWidth, verticalArrowHeight
);
graphics.blit(
RenderPipelines.GUI_TEXTURED,
right_off_red_arrow,
rightRedArrowX, verticalArrowY,
textureCornerX, textureCornerY,
verticalArrowWidth, verticalArrowHeight,
verticalArrowWidth, verticalArrowHeight
);
} else if (client.options.keyRight.isDown()) {
graphics.blit(
RenderPipelines.GUI_TEXTURED,
left_off_green_arrow,
leftGreenArrowX, verticalArrowY,
textureCornerX, textureCornerY,
verticalArrowWidth, verticalArrowHeight,
verticalArrowWidth, verticalArrowHeight
);
graphics.blit(
RenderPipelines.GUI_TEXTURED,
right_red_arrow,
rightRedArrowX, verticalArrowY,
textureCornerX, textureCornerY,
verticalArrowWidth, verticalArrowHeight,
verticalArrowWidth, verticalArrowHeight
);
} else {
graphics.blit(
RenderPipelines.GUI_TEXTURED,
left_off_green_arrow,
leftGreenArrowX, verticalArrowY,
textureCornerX, textureCornerY,
verticalArrowWidth, verticalArrowHeight,
verticalArrowWidth, verticalArrowHeight
);
graphics.blit(
RenderPipelines.GUI_TEXTURED,
right_off_red_arrow,
rightRedArrowX, verticalArrowY,
textureCornerX, textureCornerY,
verticalArrowWidth, verticalArrowHeight,
verticalArrowWidth, verticalArrowHeight
);
}
int arrowWidth = 6;
int arrowHeight = 8;
int greenAndRedArrowX = x + 46;
int greenArrowY = y + 13;
int redArrowY = y + 23;
if(client.options.keyUp.isDown()){
graphics.blit(
RenderPipelines.GUI_TEXTURED,
green_arrow,
greenAndRedArrowX, greenArrowY,
textureCornerX, textureCornerY,
arrowWidth, arrowHeight,
arrowWidth, arrowHeight
);
graphics.blit(
RenderPipelines.GUI_TEXTURED,
off_red_arrow,
greenAndRedArrowX, redArrowY,
textureCornerX, textureCornerY,
arrowWidth, arrowHeight,
arrowWidth, arrowHeight
);
} else if(client.options.keyDown.isDown()) {
graphics.blit(
RenderPipelines.GUI_TEXTURED,
off_green_arrow,
greenAndRedArrowX, greenArrowY,
textureCornerX, textureCornerY,
arrowWidth, arrowHeight,
arrowWidth, arrowHeight
);
graphics.blit(
RenderPipelines.GUI_TEXTURED,
red_arrow,
greenAndRedArrowX, redArrowY,
textureCornerX, textureCornerY,
arrowWidth, arrowHeight,
arrowWidth, arrowHeight
);
} else {
graphics.blit(
RenderPipelines.GUI_TEXTURED,
off_green_arrow,
greenAndRedArrowX, greenArrowY,
textureCornerX, textureCornerY,
arrowWidth, arrowHeight,
arrowWidth, arrowHeight
);
graphics.blit(
RenderPipelines.GUI_TEXTURED,
off_red_arrow,
greenAndRedArrowX, redArrowY,
textureCornerX, textureCornerY,
arrowWidth, arrowHeight,
arrowWidth, arrowHeight
);
}
//Compas background
int compassWidth = 29;
int compassHeight = 29;
int compassX = x + 67;
int compassY = y + 3;
graphics.blit(
RenderPipelines.GUI_TEXTURED,
compass,
compassX, compassY,
textureCornerX, textureCornerY,
compassWidth, compassHeight,
compassWidth, compassHeight
);
double radians = EntityTools.getRadians(tracker.getGameTimeDeltaPartialTick(true));
double radius = 5;
float centerX = compassX + 14;
float centerY = compassY + 14;
float endX = Math.round(centerX + (radius * -Mth.sin(radians)));
float endY = Math.round(centerY + (radius * Mth.cos(radians)));
drawLine(graphics, centerX, centerY, endX, endY, (int) radius, compass_pointer);
}
}
+1 -1
View File
@@ -3,7 +3,7 @@
"id": "simpletransporthud",
"version": "${version}",
"name": "Simple Transport HUD",
"description": "A Hud mod for different transports in Minecraft ",
"description": "A Hud mod for different transports in Minecraft",
"authors": ["Lukasabbe"],
"contact": {
"homepage": "",