mirror of
https://github.com/lukasabbe/SimpleTransportHud.git
synced 2026-04-30 10:50:53 +00:00
Added boat HUD
This commit is contained in:
@@ -4,9 +4,23 @@ import com.lukasabbe.simplehud.Constants;
|
|||||||
import com.lukasabbe.simplehud.tools.BoatTools;
|
import com.lukasabbe.simplehud.tools.BoatTools;
|
||||||
import net.minecraft.client.DeltaTracker;
|
import net.minecraft.client.DeltaTracker;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import net.minecraft.client.renderer.RenderPipelines;
|
||||||
import net.minecraft.resources.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
|
||||||
|
public class BoatHud implements SimpleHud {
|
||||||
|
|
||||||
|
Identifier compass = Identifier.fromNamespaceAndPath(Constants.MOD_ID, "textures/compass.png");
|
||||||
|
Identifier compass_pointer = Identifier.fromNamespaceAndPath(Constants.MOD_ID, "textures/compass_pointer.png");
|
||||||
|
Identifier left_green_arrow = Identifier.fromNamespaceAndPath(Constants.MOD_ID, "textures/left_green_arrow.png");
|
||||||
|
Identifier right_red_arrow = Identifier.fromNamespaceAndPath(Constants.MOD_ID, "textures/right_red_arrow.png");
|
||||||
|
Identifier left_off_green_arrow = Identifier.fromNamespaceAndPath(Constants.MOD_ID, "textures/off_left_green_arrow.png");
|
||||||
|
Identifier right_off_red_arrow = Identifier.fromNamespaceAndPath(Constants.MOD_ID, "textures/off_left_red_arrow.png");
|
||||||
|
Identifier green_arrow = Identifier.fromNamespaceAndPath(Constants.MOD_ID, "textures/green_arrow.png");
|
||||||
|
Identifier red_arrow = Identifier.fromNamespaceAndPath(Constants.MOD_ID, "textures/red_arrow.png");
|
||||||
|
Identifier off_green_arrow = Identifier.fromNamespaceAndPath(Constants.MOD_ID, "textures/off_green_arrow.png");
|
||||||
|
Identifier off_red_arrow = Identifier.fromNamespaceAndPath(Constants.MOD_ID, "textures/off_red_arrow.png");
|
||||||
|
|
||||||
public class BoatHud implements SimpleHud{
|
|
||||||
@Override
|
@Override
|
||||||
public void render(GuiGraphics graphics, DeltaTracker tracker) {
|
public void render(GuiGraphics graphics, DeltaTracker tracker) {
|
||||||
if(!isHudActivated()) return;
|
if(!isHudActivated()) return;
|
||||||
@@ -14,8 +28,182 @@ public class BoatHud implements SimpleHud{
|
|||||||
if(!BoatTools.isRidingBoat()) return;
|
if(!BoatTools.isRidingBoat()) return;
|
||||||
if(client.player == null) return;
|
if(client.player == null) return;
|
||||||
|
|
||||||
|
int[] pos = getCornerPos();
|
||||||
|
int x = pos[0];
|
||||||
|
int y = pos[1];
|
||||||
|
|
||||||
renderBackPlate(graphics);
|
renderBackPlate(graphics);
|
||||||
|
|
||||||
|
int textX = 5;
|
||||||
|
float textScale = 0.6f;
|
||||||
|
int whiteColor = 0xFFFFFFFF;
|
||||||
|
|
||||||
|
//Draw boat angle
|
||||||
|
int pitchTextY = 5;
|
||||||
|
double angle = BoatTools.getAngle();
|
||||||
|
renderCenteredScaledText(graphics, String.format("%3.0f °", angle), x + textX, y + pitchTextY, whiteColor, textScale);
|
||||||
|
|
||||||
|
//Draw speed
|
||||||
|
int speedTextY = 15;
|
||||||
|
renderCenteredScaledText(graphics, getSpeed(), x + textX, y + speedTextY, whiteColor, textScale);
|
||||||
|
|
||||||
|
//Draw coordinates
|
||||||
|
int coordinatesTextY = 25;
|
||||||
|
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 = BoatTools.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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.lukasabbe.simplehud.huds;
|
package com.lukasabbe.simplehud.huds;
|
||||||
|
|
||||||
import com.lukasabbe.simplehud.Constants;
|
import com.lukasabbe.simplehud.Constants;
|
||||||
import com.lukasabbe.simplehud.SimpleHudMod;
|
|
||||||
import com.lukasabbe.simplehud.config.Config;
|
|
||||||
import com.lukasabbe.simplehud.tools.ElytraTools;
|
import com.lukasabbe.simplehud.tools.ElytraTools;
|
||||||
import net.minecraft.client.DeltaTracker;
|
import net.minecraft.client.DeltaTracker;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.lukasabbe.simplehud.tools;
|
|||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
import org.jspecify.annotations.Nullable;
|
import org.jspecify.annotations.Nullable;
|
||||||
|
|
||||||
public class BoatTools {
|
public class BoatTools {
|
||||||
@@ -10,7 +11,31 @@ public class BoatTools {
|
|||||||
if(player == null) return false;
|
if(player == null) return false;
|
||||||
return getLocalPlayer().getVehicle() != null;
|
return getLocalPlayer().getVehicle() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double getAngle(){
|
||||||
|
var player = getLocalPlayer();
|
||||||
|
if(player == null) return 0;
|
||||||
|
if(!isRidingBoat()) return 0;
|
||||||
|
|
||||||
|
var vehicle = player.getVehicle();
|
||||||
|
var velocity = vehicle.getDeltaMovement().multiply(1, 0, 1);
|
||||||
|
var angle = Math.toDegrees(Math.acos(velocity.dot(vehicle.getLookAngle()) / velocity.length() * vehicle.getLookAngle().length()));
|
||||||
|
if(Double.isNaN(angle)) angle = 0;
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
private static @Nullable LocalPlayer getLocalPlayer() {
|
private static @Nullable LocalPlayer getLocalPlayer() {
|
||||||
return Minecraft.getInstance().player;
|
return Minecraft.getInstance().player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double getRadians(float partialTick){
|
||||||
|
var player = getLocalPlayer();
|
||||||
|
if(player == null) return 0;
|
||||||
|
if(!isRidingBoat()) return 0;
|
||||||
|
float rawYaw = Mth.lerp(partialTick, player.getVehicle().yRotO, player.getVehicle().getYRot());
|
||||||
|
|
||||||
|
float normalizedYaw = (rawYaw % 360);
|
||||||
|
if (normalizedYaw < 0) normalizedYaw += 360;
|
||||||
|
|
||||||
|
return Math.toRadians(normalizedYaw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 150 B |
Binary file not shown.
|
After Width: | Height: | Size: 148 B |
Binary file not shown.
|
After Width: | Height: | Size: 143 B |
Binary file not shown.
|
After Width: | Height: | Size: 150 B |
Reference in New Issue
Block a user