55import java .util .ArrayList ;
66import java .util .List ;
77import net .minecraft .client .MinecraftClient ;
8- import net .minecraft .client .render .BufferBuilder ;
9- import net .minecraft .client .render .GameRenderer ;
10- import net .minecraft .client .render .Tessellator ;
11- import net .minecraft .client .render .VertexFormat ;
12- import net .minecraft .client .render .VertexFormats ;
8+ import net .minecraft .client .gui .DrawableHelper ;
9+ import net .minecraft .client .render .*;
1310import net .minecraft .client .render .item .ItemRenderer ;
1411import net .minecraft .client .toast .SystemToast ;
1512import net .minecraft .client .util .math .MatrixStack ;
1613import net .minecraft .item .ItemStack ;
1714import net .minecraft .text .MutableText ;
1815import net .minecraft .text .Text ;
1916import net .minecraft .util .Identifier ;
17+ import net .minecraft .util .math .Matrix4f ;
2018import net .minecraft .util .math .Vector4f ;
2119import org .lwjgl .opengl .GL11 ;
2220
@@ -179,4 +177,53 @@ public static void sendToaster(String title, String description, SystemToast.Typ
179177 public static void sendToaster (MutableText title , MutableText description , SystemToast .Type type ) {
180178 MinecraftClient .getInstance ().getToastManager ().add (new SystemToast (type , title , description ));
181179 }
180+
181+ static int renderSteps = 100 ;
182+
183+ public static void renderLine (MatrixStack stack , float x1 , float y1 , float x2 , float y2 , int color , float size ) {
184+ float stepX = (x2 -x1 )/renderSteps ;
185+ float stepY = (y2 -y1 )/renderSteps ;
186+
187+ for (int i = 0 ; i <= renderSteps ; i ++) {
188+ fill (stack , (x1 -(size /2 )), (y1 -(size /2 )), (x1 +(size /2 )), (y1 +(size /2 )), color );
189+
190+ x1 += stepX ;
191+ y1 += stepY ;
192+ }
193+ }
194+
195+ // these functions exist because fabric api dumb and used an integer for positions in the DrawableHelper class...
196+ public static void fill (MatrixStack stack , float x1 , float y1 , float x2 , float y2 , int color ) {
197+ fill (stack .peek ().getPositionMatrix (), x1 , y1 , x2 , y2 , color );
198+ }
199+ public static void fill (Matrix4f matrix , float x1 , float y1 , float x2 , float y2 , int color ) {
200+ float i ;
201+ if (x1 < x2 ) {
202+ i = x1 ;
203+ x1 = x2 ;
204+ x2 = i ;
205+ }
206+ if (y1 < y2 ) {
207+ i = y1 ;
208+ y1 = y2 ;
209+ y2 = i ;
210+ }
211+ float f = (float )(color >> 24 & 0xFF ) / 255.0f ;
212+ float g = (float )(color >> 16 & 0xFF ) / 255.0f ;
213+ float h = (float )(color >> 8 & 0xFF ) / 255.0f ;
214+ float j = (float )(color & 0xFF ) / 255.0f ;
215+ BufferBuilder bufferBuilder = Tessellator .getInstance ().getBuffer ();
216+ RenderSystem .enableBlend ();
217+ RenderSystem .disableTexture ();
218+ RenderSystem .defaultBlendFunc ();
219+ RenderSystem .setShader (GameRenderer ::getPositionColorShader );
220+ bufferBuilder .begin (VertexFormat .DrawMode .QUADS , VertexFormats .POSITION_COLOR );
221+ bufferBuilder .vertex (matrix , x1 , y2 , 0.0f ).color (g , h , j , f ).next ();
222+ bufferBuilder .vertex (matrix , x2 , y2 , 0.0f ).color (g , h , j , f ).next ();
223+ bufferBuilder .vertex (matrix , x2 , y1 , 0.0f ).color (g , h , j , f ).next ();
224+ bufferBuilder .vertex (matrix , x1 , y1 , 0.0f ).color (g , h , j , f ).next ();
225+ BufferRenderer .drawWithShader (bufferBuilder .end ());
226+ RenderSystem .enableTexture ();
227+ RenderSystem .disableBlend ();
228+ }
182229}
0 commit comments