Skip to content

Commit 3f9b8a8

Browse files
committed
Minimap Waypoint Fix
1 parent 2954319 commit 3f9b8a8

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

src/main/java/dev/xpple/seedmapper/seedmap/SeedMapMinimapScreen.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@
1212
import net.minecraft.world.phys.Vec3;
1313
import org.joml.Matrix3x2fStack;
1414

15+
import java.util.ArrayList;
16+
import java.util.List;
17+
1518
public class SeedMapMinimapScreen extends SeedMapScreen {
1619

1720
private boolean initialized = false;
1821
private int cachedWidth = -1;
1922
private int cachedHeight = -1;
23+
private final List<WaypointLabel> waypointLabels = new ArrayList<>();
2024

2125
public SeedMapMinimapScreen(long seed, int dimension, int version, BlockPos playerPos) {
2226
super(seed, dimension, version, playerPos, new Vec2(0.0F, 0.0F));
@@ -67,6 +71,7 @@ public void renderToHud(GuiGraphics guiGraphics, LocalPlayer player, float parti
6771
this.setFeatureIconRenderingEnabled(false);
6872
this.setMarkerRenderingEnabled(false);
6973
this.setPlayerIconRenderingEnabled(false);
74+
this.waypointLabels.clear();
7075

7176
var pose = guiGraphics.pose();
7277
pose.pushMatrix();
@@ -80,6 +85,8 @@ public void renderToHud(GuiGraphics guiGraphics, LocalPlayer player, float parti
8085
this.renderSeedMap(guiGraphics, Integer.MIN_VALUE, Integer.MIN_VALUE, partialTick);
8186
pose.popMatrix();
8287

88+
this.renderWaypointLabels(guiGraphics, translateX, translateY, centerX, centerY, rotationRadians);
89+
8390
boolean drawIcons = true;
8491
this.setFeatureIconRenderingEnabled(drawIcons);
8592
this.setMarkerRenderingEnabled(drawIcons);
@@ -93,6 +100,7 @@ public void renderToHud(GuiGraphics guiGraphics, LocalPlayer player, float parti
93100
this.drawCenteredPlayerDirectionArrow(guiGraphics, centerX, centerY, 6.0D, partialTick);
94101
}
95102
}
103+
this.waypointLabels.clear();
96104

97105
guiGraphics.disableScissor();
98106
}
@@ -137,6 +145,31 @@ private void renderMinimapIcons(GuiGraphics guiGraphics, double translateX, doub
137145
}
138146
}
139147

148+
private void renderWaypointLabels(GuiGraphics guiGraphics, double translateX, double translateY, double centerX, double centerY, float rotationRadians) {
149+
if (this.waypointLabels.isEmpty()) {
150+
return;
151+
}
152+
double cos = Math.cos(rotationRadians);
153+
double sin = Math.sin(rotationRadians);
154+
double iconScale = Configs.SeedMapMinimapIconScale;
155+
for (WaypointLabel label : this.waypointLabels) {
156+
FeatureWidget widget = label.widget();
157+
MapFeature.Texture texture = widget.texture();
158+
double baseCenterX = widget.drawX() + texture.width() / 2.0D;
159+
double baseCenterY = widget.drawY() + texture.height() / 2.0D;
160+
double shiftedX = baseCenterX + translateX;
161+
double shiftedY = baseCenterY + translateY;
162+
double dx = shiftedX - centerX;
163+
double dy = shiftedY - centerY;
164+
double rotatedX = centerX + dx * cos - dy * sin;
165+
double rotatedY = centerY + dx * sin + dy * cos;
166+
double scaledHeight = Math.max(1.0D, texture.height() * iconScale);
167+
int textX = (int) Math.round(rotatedX);
168+
int textY = (int) Math.round(rotatedY + scaledHeight / 2.0D + 1.0D);
169+
guiGraphics.drawCenteredString(this.font, label.text(), textX, textY, label.colour());
170+
}
171+
}
172+
140173
private void renderSingleIcon(GuiGraphics guiGraphics, FeatureWidget widget, double translateX, double translateY, double centerX, double centerY, double cos, double sin, int colour, double iconScale) {
141174
MapFeature.Texture texture = widget.texture();
142175
int scaledWidth = (int) Math.max(1, Math.round(texture.width() * iconScale));
@@ -220,4 +253,33 @@ protected boolean showFeatureToggleTooltips() {
220253
protected boolean showSeedLabel() {
221254
return false;
222255
}
256+
257+
@Override
258+
protected void drawWaypointLabel(GuiGraphics guiGraphics, FeatureWidget widget, String name, int colour) {
259+
this.waypointLabels.add(new WaypointLabel(widget, name, colour));
260+
}
261+
262+
private static final class WaypointLabel {
263+
private final FeatureWidget widget;
264+
private final String text;
265+
private final int colour;
266+
267+
private WaypointLabel(FeatureWidget widget, String text, int colour) {
268+
this.widget = widget;
269+
this.text = text;
270+
this.colour = colour;
271+
}
272+
273+
public FeatureWidget widget() {
274+
return this.widget;
275+
}
276+
277+
public String text() {
278+
return this.text;
279+
}
280+
281+
public int colour() {
282+
return this.colour;
283+
}
284+
}
223285
}

src/main/java/dev/xpple/seedmapper/seedmap/SeedMapScreen.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,7 +2415,8 @@ protected void renderSeedMap(GuiGraphics guiGraphics, int mouseX, int mouseY, fl
24152415
if (widget == null) {
24162416
return;
24172417
}
2418-
guiGraphics.drawCenteredString(this.font, name, widget.x + widget.width() / 2, widget.y + widget.height(), ARGB.color(255, waypoint.color()));
2418+
int labelColour = ARGB.color(255, waypoint.color());
2419+
this.drawWaypointLabel(guiGraphics, widget, name, labelColour);
24192420
});
24202421
}
24212422

@@ -2516,6 +2517,12 @@ private void renderFeatureToggleTooltip(GuiGraphics guiGraphics, int mouseX, int
25162517
}
25172518
}
25182519

2520+
protected void drawWaypointLabel(GuiGraphics guiGraphics, FeatureWidget widget, String name, int colour) {
2521+
int textX = widget.x + widget.width() / 2;
2522+
int textY = widget.y + widget.height();
2523+
guiGraphics.drawCenteredString(this.font, name, textX, textY, colour);
2524+
}
2525+
25192526
protected void drawCenteredPlayerDirectionArrow(GuiGraphics guiGraphics, double centerX, double centerY, double size, float partialTick) {
25202527
LocalPlayer player = this.minecraft.player;
25212528
if (player == null) return;
@@ -2588,4 +2595,4 @@ protected void updateAllFeatureWidgetPositions() {
25882595
public static int computeSeedMapWidth(int screenWidth) {
25892596
return Math.max(1, screenWidth - 2 * HORIZONTAL_PADDING);
25902597
}
2591-
}
2598+
}

0 commit comments

Comments
 (0)