2020import com .mojang .blaze3d .vertex .PoseStack ;
2121import com .mojang .blaze3d .vertex .VertexConsumer ;
2222import me .desht .pneumaticcraft .client .render .ModRenderTypes ;
23+ import me .desht .pneumaticcraft .client .render .pressure_gauge .PressureGaugeRenderer2D .TextScaler ;
2324import me .desht .pneumaticcraft .client .util .RenderUtils ;
2425import net .minecraft .client .renderer .MultiBufferSource ;
2526import net .minecraft .client .renderer .RenderType ;
@@ -61,11 +62,11 @@ public static void drawPressureGauge(PoseStack matrixStack, MultiBufferSource bu
6162 Matrix3f normal = matrixStack .last ().normal ();
6263
6364 // Draw the green and red surface in the gauge.
64- RenderUtils .renderWithType (matrixStack , buffer , ModRenderTypes .TRIANGLE_FAN , (posMat , builder ) ->
65+ RenderUtils .renderWithType (matrixStack , buffer , ModRenderTypes .TRIANGLES , (posMat , builder ) ->
6566 drawGaugeBackground (posMat , builder , minPressure , maxPressure , dangerPressure , minWorkingPressure , xPos , yPos ));
6667
6768 // Draw the surrounding circle in the foreground colour
68- RenderUtils .renderWithType (matrixStack , buffer , RenderType .LINE_STRIP , (posMat , builder ) ->
69+ RenderUtils .renderWithType (matrixStack , buffer , RenderType .LINES , (posMat , builder ) ->
6970 drawGaugeSurround (posMat , normal , builder , xPos , yPos , fgColor ));
7071
7172 // Draw the scale
@@ -75,7 +76,7 @@ public static void drawPressureGauge(PoseStack matrixStack, MultiBufferSource bu
7576 drawScale (posMat , normal , builder , minPressure , maxPressure , xPos , yPos , currentScale , textScalers ));
7677
7778 // Draw the needle.
78- RenderUtils .renderWithType (matrixStack , buffer , RenderType .LINE_STRIP , (posMat , builder ) -> {
79+ RenderUtils .renderWithType (matrixStack , buffer , RenderType .LINES , (posMat , builder ) -> {
7980 float angleIndicator = GAUGE_POINTS - (int ) ((currentPressure - minPressure ) / (maxPressure - minPressure ) * GAUGE_POINTS );
8081 angleIndicator = -angleIndicator / CIRCLE_POINTS * 2F * PI_F - STOP_ANGLE ;
8182 drawNeedle (posMat , normal , builder , xPos , yPos , angleIndicator , fgColor );
@@ -86,11 +87,8 @@ public static void drawPressureGauge(PoseStack matrixStack, MultiBufferSource bu
8687 }
8788
8889 private static void drawGaugeBackground (Matrix4f posMat , VertexConsumer builder , float minPressure , float maxPressure , float dangerPressure , float minWorkingPressure , int xPos , int yPos ) {
89- // vertex builder is set up to draw GL_TRIANGLE_FAN
9090 float [] color = RED ;
9191
92- builder .vertex (posMat , xPos , yPos , 0f ).color (0.5f , 0.5f , 0.1f , 1f ).endVertex ();
93-
9492 int explodeBoundary = GAUGE_POINTS - (int ) ((dangerPressure - minPressure ) / (maxPressure - minPressure ) * GAUGE_POINTS );
9593 int workingBoundary = GAUGE_POINTS - (int ) ((minWorkingPressure - minPressure ) / (maxPressure - minPressure ) * GAUGE_POINTS );
9694
@@ -100,20 +98,23 @@ private static void drawGaugeBackground(Matrix4f posMat, VertexConsumer builder,
10098 for (int i = 0 ; i < GAUGE_POINTS ; i ++) {
10199 if (i == explodeBoundary && !changedColorGreen ) {
102100 color = minWorkingPressure < 0 && minWorkingPressure >= -1 ? YELLOW : GREEN ;
103- builder .vertex (posMat , xPos , yPos , 0f ).color (color [0 ], color [1 ], color [2 ], color [3 ]).endVertex ();
104- i --;
105101 changedColorGreen = true ;
106102 }
107103 if (i == workingBoundary && !changedColorYellow ) {
108104 color = minWorkingPressure < 0 && minWorkingPressure >= -1 ? GREEN : YELLOW ;
109- builder .vertex (posMat , xPos , yPos , 0f ).color (color [0 ], color [1 ], color [2 ], color [3 ]).endVertex ();
110- i --;
111105 changedColorYellow = true ;
112106 }
113107 float angle = -i / (float ) CIRCLE_POINTS * 2F * PI_F - STOP_ANGLE ;
108+ float angle2 = -(i + 1 ) / (float ) CIRCLE_POINTS * 2F * PI_F - STOP_ANGLE ;
109+
110+ builder .vertex (posMat , xPos , yPos , 0f ).color (0.5f , 0.5f , 0.1f , 1f ).endVertex ();
111+
114112 builder .vertex (posMat , Mth .cos (angle ) * RADIUS + xPos , Mth .sin (angle ) * RADIUS + yPos , 0f )
115- .color (color [0 ], color [1 ], color [2 ], color [3 ])
116- .endVertex ();
113+ .color (color [0 ], color [1 ], color [2 ], color [3 ])
114+ .endVertex ();
115+ builder .vertex (posMat , Mth .cos (angle2 ) * RADIUS + xPos , Mth .sin (angle2 ) * RADIUS + yPos , 0f )
116+ .color (color [0 ], color [1 ], color [2 ], color [3 ])
117+ .endVertex ();
117118 }
118119 }
119120
@@ -127,19 +128,19 @@ private static void drawGaugeBackground(Matrix4f posMat, VertexConsumer builder,
127128 }
128129
129130 private static void drawGaugeSurround (Matrix4f posMat , Matrix3f normal , VertexConsumer builder , int xPos , int yPos , int fgColor ) {
130- // vertex builder is set up for VertexMode.LINE_STRIP
131+ // vertex builder is set up for VertexMode.LINES
131132 float [] cols = RenderUtils .decomposeColorF (fgColor );
132133 for (int i = 0 ; i < CIRCLE_POINTS ; i ++) {
133134 RenderUtils .normalLine (builder , posMat , normal ,
134135 GAUGE_SURROUND [i ][0 ] + xPos , GAUGE_SURROUND [i ][1 ] + yPos , 0f ,
135136 GAUGE_SURROUND [i + 1 ][0 ] + xPos , GAUGE_SURROUND [i + 1 ][1 ] + yPos , 0f ,
136137 cols [0 ], cols [1 ], cols [2 ], cols [3 ],
137- true );
138+ false );
138139 }
139140 }
140141
141142 private static void drawScale (Matrix4f posMat , Matrix3f normal , VertexConsumer builder , float minPressure , float maxPressure , int xPos , int yPos , int currentScale , List <TextScaler > textScalers ) {
142- // vertex builder is set up for VertexMode.LINE
143+ // vertex builder is set up for VertexMode.LINES
143144 for (int i = 0 ; i <= GAUGE_POINTS ; i ++) {
144145 float angle = -i / (float ) CIRCLE_POINTS * 2F * PI_F - STOP_ANGLE ;
145146 if (i == GAUGE_POINTS - (int ) ((currentScale - minPressure ) / (maxPressure - minPressure ) * GAUGE_POINTS )) {
@@ -159,20 +160,37 @@ private static void drawScale(Matrix4f posMat, Matrix3f normal, VertexConsumer b
159160 }
160161
161162 private static void drawNeedle (Matrix4f posMat , Matrix3f normal , VertexConsumer builder , int xPos , int yPos , float angle , int fgColor ) {
162- // vertex builder is set up for VertexMode.LINE_STRIP
163163 float [] cols = RenderUtils .decomposeColorF (fgColor );
164164
165165 float x1 = Mth .cos (angle + 0.89F * PI_F ) * RADIUS * 0.3F + xPos ;
166166 float y1 = Mth .sin (angle + 0.89F * PI_F ) * RADIUS * 0.3F + yPos ;
167+
167168 float x2 = Mth .cos (angle + 1.11F * PI_F ) * RADIUS * 0.3F + xPos ;
168169 float y2 = Mth .sin (angle + 1.11F * PI_F ) * RADIUS * 0.3F + yPos ;
170+
169171 float x3 = Mth .cos (angle ) * RADIUS * 0.8F + xPos ;
170172 float y3 = Mth .sin (angle ) * RADIUS * 0.8F + yPos ;
171173
172- RenderUtils .normalLine (builder , posMat , normal , x1 , y1 , 0f , x2 , y2 , 0f , cols [0 ], cols [1 ], cols [2 ], cols [3 ], true );
173- RenderUtils .normalLine (builder , posMat , normal , x2 , y2 , 0f , x3 , y3 , 0f , cols [0 ], cols [1 ], cols [2 ], cols [3 ], true );
174- RenderUtils .normalLine (builder , posMat , normal , x3 , y3 , 0f , x1 , y1 , 0f , cols [0 ], cols [1 ], cols [2 ], cols [3 ], true );
175- RenderUtils .normalLine (builder , posMat , normal , x1 , y1 , 0f , x2 , y2 , 0f , cols [0 ], cols [1 ], cols [2 ], cols [3 ], true );
174+ // Edge 1: x1 -> x2
175+ RenderUtils .normalLine (builder , posMat , normal ,
176+ x1 , y1 , 0f ,
177+ x2 , y2 , 0f ,
178+ cols [0 ], cols [1 ], cols [2 ], cols [3 ],
179+ false );
180+
181+ // Edge 2: x2 -> x3
182+ RenderUtils .normalLine (builder , posMat , normal ,
183+ x2 , y2 , 0f ,
184+ x3 , y3 , 0f ,
185+ cols [0 ], cols [1 ], cols [2 ], cols [3 ],
186+ false );
187+
188+ // Edge 3: x3 -> x1
189+ RenderUtils .normalLine (builder , posMat , normal ,
190+ x3 , y3 , 0f ,
191+ x1 , y1 , 0f ,
192+ cols [0 ], cols [1 ], cols [2 ], cols [3 ],
193+ false );
176194 }
177195
178196 private static void drawText (PoseStack matrixStack , MultiBufferSource buffer , int xPos , int yPos , int fgColor , List <TextScaler > textScalers ) {
0 commit comments