1212import net .minecraft .world .phys .Vec3 ;
1313import org .joml .Matrix3x2fStack ;
1414
15+ import java .util .ArrayList ;
16+ import java .util .List ;
17+
1518public 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}
0 commit comments