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 poseStack, MultiBufferSource buff
6162 Matrix3f normal = poseStack .last ().normal ();
6263
6364 // Draw the green and red surface in the gauge.
64- RenderUtils .renderWithType (poseStack , buffer , ModRenderTypes .TRIANGLE_FAN , (posMat , builder ) ->
65+ RenderUtils .renderWithType (poseStack , 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 (poseStack , buffer , RenderType .LINE_STRIP , (posMat , builder ) ->
69+ RenderUtils .renderWithType (poseStack , buffer , RenderType .LINES , (posMat , builder ) ->
6970 drawGaugeSurround (poseStack , builder , xPos , yPos , fgColor ));
7071
7172 // Draw the scale
@@ -75,7 +76,7 @@ public static void drawPressureGauge(PoseStack poseStack, MultiBufferSource buff
7576 drawScale (poseStack , builder , minPressure , maxPressure , xPos , yPos , currentScale , textScalers ));
7677
7778 // Draw the needle.
78- RenderUtils .renderWithType (poseStack , buffer , RenderType .LINE_STRIP , (posMat , builder ) -> {
79+ RenderUtils .renderWithType (poseStack , 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 (poseStack , builder , xPos , yPos , angleIndicator , fgColor );
@@ -86,11 +87,8 @@ public static void drawPressureGauge(PoseStack poseStack, MultiBufferSource buff
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 .addVertex (posMat , xPos , yPos , 0f ).setColor (0.5f , 0.5f , 0.1f , 1f );
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,21 @@ 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 .addVertex (posMat , xPos , yPos , 0f ).setColor (color [0 ], color [1 ], color [2 ], color [3 ]);
104- i --;
105101 changedColorGreen = true ;
106102 }
107103 if (i == workingBoundary && !changedColorYellow ) {
108104 color = minWorkingPressure < 0 && minWorkingPressure >= -1 ? GREEN : YELLOW ;
109- builder .addVertex (posMat , xPos , yPos , 0f ).setColor (color [0 ], color [1 ], color [2 ], color [3 ]);
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 .addVertex (posMat , xPos , yPos , 0f ).setColor (0.5f , 0.5f , 0.1f , 1f );
111+
114112 builder .addVertex (posMat , Mth .cos (angle ) * RADIUS + xPos , Mth .sin (angle ) * RADIUS + yPos , 0f )
115- .setColor (color [0 ], color [1 ], color [2 ], color [3 ])
116- ;
113+ .setColor (color [0 ], color [1 ], color [2 ], color [3 ]);
114+ builder .addVertex (posMat , Mth .cos (angle2 ) * RADIUS + xPos , Mth .sin (angle2 ) * RADIUS + yPos , 0f )
115+ .setColor (color [0 ], color [1 ], color [2 ], color [3 ]);
117116 }
118117 }
119118
@@ -127,19 +126,19 @@ private static void drawGaugeBackground(Matrix4f posMat, VertexConsumer builder,
127126 }
128127
129128 private static void drawGaugeSurround (PoseStack poseStack , VertexConsumer builder , int xPos , int yPos , int fgColor ) {
130- // vertex builder is set up for VertexMode.LINE_STRIP
129+ // vertex builder is set up for VertexMode.LINES
131130 float [] cols = RenderUtils .decomposeColorF (fgColor );
132131 for (int i = 0 ; i < CIRCLE_POINTS ; i ++) {
133132 RenderUtils .normalLine (builder , poseStack ,
134133 GAUGE_SURROUND [i ][0 ] + xPos , GAUGE_SURROUND [i ][1 ] + yPos , 0f ,
135134 GAUGE_SURROUND [i + 1 ][0 ] + xPos , GAUGE_SURROUND [i + 1 ][1 ] + yPos , 0f ,
136135 cols [0 ], cols [1 ], cols [2 ], cols [3 ],
137- true );
136+ false );
138137 }
139138 }
140139
141140 private static void drawScale (PoseStack poseStack , VertexConsumer builder , float minPressure , float maxPressure , int xPos , int yPos , int currentScale , List <TextScaler > textScalers ) {
142- // vertex builder is set up for VertexMode.LINE
141+ // vertex builder is set up for VertexMode.LINES
143142 for (int i = 0 ; i <= GAUGE_POINTS ; i ++) {
144143 float angle = -i / (float ) CIRCLE_POINTS * 2F * PI_F - STOP_ANGLE ;
145144 if (i == GAUGE_POINTS - (int ) ((currentScale - minPressure ) / (maxPressure - minPressure ) * GAUGE_POINTS )) {
@@ -159,20 +158,37 @@ private static void drawScale(PoseStack poseStack, VertexConsumer builder, float
159158 }
160159
161160 private static void drawNeedle (PoseStack poseStack , VertexConsumer builder , int xPos , int yPos , float angle , int fgColor ) {
162- // vertex builder is set up for VertexMode.LINE_STRIP
163161 float [] cols = RenderUtils .decomposeColorF (fgColor );
164162
165163 float x1 = Mth .cos (angle + 0.89F * PI_F ) * RADIUS * 0.3F + xPos ;
166164 float y1 = Mth .sin (angle + 0.89F * PI_F ) * RADIUS * 0.3F + yPos ;
165+
167166 float x2 = Mth .cos (angle + 1.11F * PI_F ) * RADIUS * 0.3F + xPos ;
168167 float y2 = Mth .sin (angle + 1.11F * PI_F ) * RADIUS * 0.3F + yPos ;
168+
169169 float x3 = Mth .cos (angle ) * RADIUS * 0.8F + xPos ;
170170 float y3 = Mth .sin (angle ) * RADIUS * 0.8F + yPos ;
171171
172- RenderUtils .normalLine (builder , poseStack , x1 , y1 , 0f , x2 , y2 , 0f , cols [0 ], cols [1 ], cols [2 ], cols [3 ], true );
173- RenderUtils .normalLine (builder , poseStack , x2 , y2 , 0f , x3 , y3 , 0f , cols [0 ], cols [1 ], cols [2 ], cols [3 ], true );
174- RenderUtils .normalLine (builder , poseStack , x3 , y3 , 0f , x1 , y1 , 0f , cols [0 ], cols [1 ], cols [2 ], cols [3 ], true );
175- RenderUtils .normalLine (builder , poseStack , x1 , y1 , 0f , x2 , y2 , 0f , cols [0 ], cols [1 ], cols [2 ], cols [3 ], true );
172+ // Edge 1: x1 -> x2
173+ RenderUtils .normalLine (builder , poseStack ,
174+ x1 , y1 , 0f ,
175+ x2 , y2 , 0f ,
176+ cols [0 ], cols [1 ], cols [2 ], cols [3 ],
177+ false );
178+
179+ // Edge 2: x2 -> x3
180+ RenderUtils .normalLine (builder , poseStack ,
181+ x2 , y2 , 0f ,
182+ x3 , y3 , 0f ,
183+ cols [0 ], cols [1 ], cols [2 ], cols [3 ],
184+ false );
185+
186+ // Edge 3: x3 -> x1
187+ RenderUtils .normalLine (builder , poseStack ,
188+ x3 , y3 , 0f ,
189+ x1 , y1 , 0f ,
190+ cols [0 ], cols [1 ], cols [2 ], cols [3 ],
191+ false );
176192 }
177193
178194 private static void drawText (PoseStack matrixStack , MultiBufferSource buffer , int xPos , int yPos , int fgColor , List <TextScaler > textScalers ) {
0 commit comments