33import com .jumpcutfindo .onmymark .OnMyMarkMod ;
44import com .jumpcutfindo .onmymark .client .graphics .utils .DrawUtils ;
55import com .jumpcutfindo .onmymark .client .graphics .utils .RenderMath ;
6+ import com .jumpcutfindo .onmymark .client .party .ClientPartyMember ;
67import com .jumpcutfindo .onmymark .marker .Marker ;
78import net .minecraft .client .MinecraftClient ;
89import net .minecraft .client .gui .DrawContext ;
10+ import net .minecraft .client .gui .PlayerSkinDrawer ;
11+ import net .minecraft .client .util .SkinTextures ;
12+ import net .minecraft .util .Colors ;
913import net .minecraft .util .math .ColorHelper ;
1014import net .minecraft .util .math .MathHelper ;
1115import net .minecraft .util .math .Vec3d ;
@@ -30,6 +34,8 @@ public abstract class MarkerRenderer {
3034 private boolean isClamped ;
3135 private float clampWidth , clampHeight ;
3236
37+ private final SkinTextures playerSkinTextures ;
38+
3339 protected MarkerRenderer (MinecraftClient client , Marker marker , PointerShape pointerShape ) {
3440 this .client = client ;
3541 this .marker = marker ;
@@ -40,6 +46,12 @@ protected MarkerRenderer(MinecraftClient client, Marker marker, PointerShape poi
4046 this .pointerShape = pointerShape ;
4147
4248 this .creationTime = Instant .now ();
49+
50+ this .playerSkinTextures = MinecraftClient .getInstance ()
51+ .getSkinProvider ()
52+ .getSkinTextures (
53+ ((ClientPartyMember )marker .owner ()).gameProfile ()
54+ );
4355 }
4456
4557 public Vector4f screenPos () {
@@ -154,26 +166,37 @@ public void draw(DrawContext drawContext) {
154166 float pointerHeight = OnMyMarkMod .CONFIG .markerPointerHeight () * pointerSizeModifier ;
155167 int pointerColor = ColorHelper .withAlpha ((int ) Math .min ((float ) existTimeMs / 20 , 1.0F ) * 255 , this .getPointerColor ());
156168
157- if (this .isClamped ) {
169+ // Calculate label width
170+ int labelWidth = this .getLabelWidth ();
171+ int labelHeight = this .getLabelHeight ();
172+
173+ float playerHeadScale = OnMyMarkMod .CONFIG .playerHeadScale ();
158174
175+ if (this .isClamped ) {
159176 // Draw edge pointer if the marker has been clamped
160177 this .drawEdgePointer (drawContext , pointerWidth , pointerHeight , pointerColor );
161178
162- Vector2f iconPos = this .getClampedLabelPos (this .getLabelWidth (), this .getLabelHeight (), 16F + distanceLabelHeight * screenPosNormal .y );
163- this .drawLabel (drawContext , iconPos .x (), iconPos .y (), true );
179+ Vector2f labelPos = this .getClampedLabelPos (labelWidth , labelHeight , 16F + distanceLabelHeight * screenPosNormal .y );
180+
181+ this .drawLabel (drawContext , labelPos .x (), labelPos .y (), true );
182+ this .drawDistanceLabel (drawContext , labelPos .x () + labelWidth / 2F - distanceLabelWidth / 2F , labelPos .y () + labelHeight + 4F , distanceLabelScale );
164183
165- this .drawDistanceLabel (drawContext , iconPos .x () + getLabelWidth () / 2F - distanceLabelWidth / 2F , iconPos .y () + getLabelHeight () + 4F , distanceLabelScale );
184+ if (OnMyMarkMod .CONFIG .isPlayerHeadEnabled ()) {
185+ this .drawPlayerHead (drawContext , labelPos .x () - 4F , labelPos .y () + labelHeight / 2F , playerHeadScale );
186+ }
166187 } else {
167188 // Draw pointer that points directly toward object
168-
169189 this .drawPointer (drawContext , pointerWidth , pointerHeight , pointerColor );
170190
171- float screenX = screenPos .x () - this . getLabelWidth () / 2F ;
172- float screenY = screenPos .y () - OnMyMarkMod .CONFIG .markerPointerHeight () - getLabelHeight () - 4F ;
191+ float screenX = screenPos .x () - labelWidth / 2F ;
192+ float screenY = screenPos .y () - OnMyMarkMod .CONFIG .markerPointerHeight () - labelHeight - 4F ;
173193
174194 this .drawLabel (drawContext , screenX , screenY , true );
175-
176195 this .drawDistanceLabel (drawContext , screenPos .x () - distanceLabelWidth / 2F , screenPos .y () - OnMyMarkMod .CONFIG .markerPointerHeight () - distanceLabelHeight - 24F , distanceLabelScale );
196+
197+ if (OnMyMarkMod .CONFIG .isPlayerHeadEnabled ()) {
198+ this .drawPlayerHead (drawContext , screenX - 4F , screenY + labelHeight / 2F , playerHeadScale );
199+ }
177200 }
178201
179202 }
@@ -190,7 +213,7 @@ private void drawPointer(DrawContext drawContext, float width, float height, int
190213 float x3 = this .screenPos .x + width / 2F ;
191214 float y3 = this .screenPos .y - height ;
192215
193- DrawUtils .drawTriangle (drawContext , x1 , y1 , x2 , y2 , x3 , y3 , color );
216+ DrawUtils .drawTriangle (drawContext , ( int ) x1 , ( int ) y1 , ( int ) x2 , ( int ) y2 , ( int ) x3 , ( int ) y3 , color );
194217 } else {
195218 float x2 = this .screenPos .x - width / 2F ;
196219 float y2 = this .screenPos .y - height / 2F ;
@@ -201,7 +224,7 @@ private void drawPointer(DrawContext drawContext, float width, float height, int
201224 float x4 = this .screenPos .x + width / 2F ;
202225 float y4 = this .screenPos .y - height / 2F ;
203226
204- DrawUtils .drawQuad (drawContext , x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 , color );
227+ DrawUtils .drawQuad (drawContext , ( int ) x1 , ( int ) y1 , ( int ) x2 , ( int ) y2 , ( int ) x3 , ( int ) y3 , ( int ) x4 , ( int ) y4 , color );
205228 }
206229
207230 }
@@ -219,10 +242,21 @@ private String getDistanceLabelString() {
219242 }
220243
221244 private void drawDistanceLabel (DrawContext drawContext , float screenX , float screenY , float scale ) {
222- drawContext .getMatrices ().push ();
223- drawContext .getMatrices ().scale (scale , scale , scale );
224- drawContext .drawText (this .client .textRenderer , getDistanceLabelString (), (int ) (screenX / scale ), (int ) (screenY / scale ), 0xFFFFFFFF , true );
225- drawContext .getMatrices ().pop ();
245+ drawContext .getMatrices ().pushMatrix ();
246+ drawContext .getMatrices ().scale (scale , scale );
247+ drawContext .drawText (this .client .textRenderer , getDistanceLabelString (), (int ) (screenX / scale ), (int ) (screenY / scale ), Colors .WHITE , true );
248+ drawContext .getMatrices ().popMatrix ();
249+ }
250+
251+ private void drawPlayerHead (DrawContext drawContext , float screenX , float screenY , float scale ) {
252+ float headSize = 8 * scale ;
253+
254+ int headScreenX = (int ) (screenX - headSize );
255+ int headScreenY = (int ) (screenY - headSize / 2 );
256+
257+ if (this .playerSkinTextures != null ) {
258+ PlayerSkinDrawer .draw (drawContext , this .playerSkinTextures .texture (), headScreenX , headScreenY , (int ) headSize , false , false , -1 );
259+ }
226260 }
227261
228262 /**
@@ -258,7 +292,7 @@ private void drawEdgePointer(DrawContext drawContext, float width, float height,
258292 float baseRightX = baseCenterX + baseOffsetX ;
259293 float baseRightY = baseCenterY + baseOffsetY ;
260294
261- DrawUtils .drawTriangle (drawContext , tipX , tipY , baseLeftX , baseLeftY , baseRightX , baseRightY , color );
295+ DrawUtils .drawTriangle (drawContext , ( int ) tipX , ( int ) tipY , ( int ) baseRightX , ( int ) baseRightY , ( int ) baseLeftX , ( int ) baseLeftY , color );
262296 } else {
263297 float centerX = tipX - normal .x * height / 2 ;
264298 float centerY = tipY - normal .y * height / 2 ;
@@ -274,10 +308,10 @@ private void drawEdgePointer(DrawContext drawContext, float width, float height,
274308 Vector2f right = new Vector2f (perpendicular ).mul (hw ).add (centerX , centerY );
275309
276310 DrawUtils .drawQuad (drawContext ,
277- top .x , top .y ,
278- right .x , right .y ,
279- bottom .x , bottom .y ,
280- left .x , left .y ,
311+ ( int ) top .x , ( int ) top .y ,
312+ ( int ) right .x , ( int ) right .y ,
313+ ( int ) bottom .x , ( int ) bottom .y ,
314+ ( int ) left .x , ( int ) left .y ,
281315 color
282316 );
283317 }
@@ -310,7 +344,7 @@ protected Vector2f getClampedLabelPos(float labelWidth, float labelHeight, float
310344
311345 public void drawLabel (DrawContext drawContext , float screenX , float screenY , boolean isOutlined ) {
312346 // Draw the name of the object by default
313- drawContext .drawText (client .textRenderer , this .getName (), (int ) screenX , (int ) screenY , 0xFFFFFF , true );
347+ drawContext .drawText (client .textRenderer , this .getName (), (int ) screenX , (int ) screenY , Colors . WHITE , true );
314348 }
315349
316350 protected abstract LabelDisplayType getLabelDisplayType ();
0 commit comments