1
1
package com .terraformersmc .modmenu .gui .widget ;
2
2
3
+ import com .mojang .blaze3d .buffers .BufferType ;
4
+ import com .mojang .blaze3d .buffers .BufferUsage ;
5
+ import com .mojang .blaze3d .buffers .GpuBuffer ;
6
+ import com .mojang .blaze3d .pipeline .RenderPipeline ;
7
+ import com .mojang .blaze3d .systems .RenderPass ;
3
8
import com .mojang .blaze3d .systems .RenderSystem ;
9
+ import com .mojang .blaze3d .vertex .VertexFormat ;
4
10
import com .terraformersmc .modmenu .ModMenu ;
5
11
import com .terraformersmc .modmenu .config .ModMenuConfig ;
6
12
import com .terraformersmc .modmenu .gui .ModsScreen ;
16
22
import net .minecraft .client .gui .DrawContext ;
17
23
import net .minecraft .client .gui .widget .AlwaysSelectedEntryListWidget ;
18
24
import net .minecraft .client .render .*;
25
+ import net .minecraft .client .util .BufferAllocator ;
19
26
import net .minecraft .text .Text ;
20
27
import net .minecraft .util .math .ColorHelper ;
21
28
import net .minecraft .util .math .MathHelper ;
@@ -214,7 +221,6 @@ private void filter(String searchTerm, boolean refresh, boolean search) {
214
221
@ Override
215
222
protected void renderList (DrawContext drawContext , int mouseX , int mouseY , float delta ) {
216
223
int entryCount = this .getEntryCount ();
217
- Tessellator tessellator = Tessellator .getInstance ();
218
224
for (int index = 0 ; index < entryCount ; ++index ) {
219
225
int entryTop = this .getRowTop (index ) + 2 ;
220
226
int entryBottom = this .getRowTop (index ) + this .itemHeight ;
@@ -230,28 +236,36 @@ protected void renderList(DrawContext drawContext, int mouseX, int mouseY, float
230
236
float float_2 = this .isFocused () ? 1.0F : 0.5F ;
231
237
final int topColor = ColorHelper .fromFloats (1.0F , float_2 , float_2 , float_2 );
232
238
final int bottomColor = ColorHelper .fromFloats (1.0F , 0.0F , 0.0F , 0.0F );
233
- BufferBuilder bufferBuilder = tessellator .begin (VertexFormat .DrawMode .QUADS , VertexFormats .POSITION_COLOR );
234
- bufferBuilder .vertex (matrix , entryLeft , entryTop + entryHeight + 2 , 0.0F ).color (topColor );
235
- bufferBuilder .vertex (matrix , selectionRight , entryTop + entryHeight + 2 , 0.0F ).color (topColor );
236
- bufferBuilder .vertex (matrix , selectionRight , entryTop - 2 , 0.0F ).color (topColor );
237
- bufferBuilder .vertex (matrix , entryLeft , entryTop - 2 , 0.0F ).color (topColor );
238
- bufferBuilder .vertex (matrix , entryLeft + 1 , entryTop + entryHeight + 1 , 0.0F ).color (bottomColor );
239
- bufferBuilder .vertex (matrix , selectionRight - 1 , entryTop + entryHeight + 1 , 0.0F ).color (bottomColor );
240
- bufferBuilder .vertex (matrix , selectionRight - 1 , entryTop - 1 , 0.0F ).color (bottomColor );
241
- bufferBuilder .vertex (matrix , entryLeft + 1 , entryTop - 1 , 0.0F ).color (bottomColor );
242
- try (BuiltBuffer builtBuffer = bufferBuilder .end ()) {
243
- VertexFormat .DrawMode drawMode = builtBuffer .getDrawParameters ().mode ();
244
- Framebuffer framebuffer = MinecraftClient .getInstance ().getFramebuffer ();
245
- try (RenderPass renderPass = RenderSystem .getDevice ().getResourceManager ().newRenderPass (framebuffer .getColorAttachment (), OptionalInt .empty (), framebuffer .getDepthAttachment (), OptionalDouble .empty ());
246
- GpuBuffer gpuBuffer = RenderSystem .getDevice ().createBuffer (() -> "Mod List" , GlBufferTarget .VERTICES , GlUsage .DYNAMIC_WRITE , 786432 )) { // createBuffer
247
- RenderSystem .ShapeIndexBuffer autoStorageIndexBuffer = RenderSystem .getSequentialBuffer (drawMode );
248
- renderPass .bindShader (ShaderPipelines .GUI );
249
- renderPass .setVertexBuffer (0 , gpuBuffer );
250
- renderPass .setIndexBuffer (autoStorageIndexBuffer .getIndexBuffer (builtBuffer .getDrawParameters ().indexCount ()), autoStorageIndexBuffer .getIndexType ());
251
- RenderSystem .getDevice ().getResourceManager ().copyDataInto (gpuBuffer , builtBuffer .getBuffer (), 0 );
252
- renderPass .drawObjects (0 , builtBuffer .getDrawParameters ().indexCount ());
253
- }
254
- }
239
+ RenderPipeline pipeline = RenderPipelines .GUI ;
240
+ try (BufferAllocator alloc = new BufferAllocator (pipeline .getVertexFormat ().getVertexSize () * 4 )) {
241
+ BufferBuilder bufferBuilder = new BufferBuilder (alloc , pipeline .getVertexFormatMode (), pipeline .getVertexFormat ());
242
+ bufferBuilder .vertex (matrix , entryLeft , entryTop + entryHeight + 2 , 0.0F ).color (topColor );
243
+ bufferBuilder .vertex (matrix , selectionRight , entryTop + entryHeight + 2 , 0.0F ).color (topColor );
244
+ bufferBuilder .vertex (matrix , selectionRight , entryTop - 2 , 0.0F ).color (topColor );
245
+ bufferBuilder .vertex (matrix , entryLeft , entryTop - 2 , 0.0F ).color (topColor );
246
+ bufferBuilder .vertex (matrix , entryLeft + 1 , entryTop + entryHeight + 1 , 0.0F ).color (bottomColor );
247
+ bufferBuilder .vertex (matrix , selectionRight - 1 , entryTop + entryHeight + 1 , 0.0F ).color (bottomColor );
248
+ bufferBuilder .vertex (matrix , selectionRight - 1 , entryTop - 1 , 0.0F ).color (bottomColor );
249
+ bufferBuilder .vertex (matrix , entryLeft + 1 , entryTop - 1 , 0.0F ).color (bottomColor );
250
+ try (BuiltBuffer builtBuffer = bufferBuilder .endNullable ()) {
251
+ if (builtBuffer == null ) {
252
+ alloc .close ();
253
+ return ;
254
+ }
255
+ Framebuffer framebuffer = MinecraftClient .getInstance ().getFramebuffer ();
256
+ RenderSystem .ShapeIndexBuffer autoStorageIndexBuffer = RenderSystem .getSequentialBuffer (pipeline .getVertexFormatMode ());
257
+ VertexFormat .IndexType indexType = autoStorageIndexBuffer .getIndexType ();
258
+ GpuBuffer indexBuffer = autoStorageIndexBuffer .getIndexBuffer (builtBuffer .getDrawParameters ().indexCount ());
259
+ GpuBuffer vertexBuffer = RenderSystem .getDevice ().createBuffer (() -> "Mod List" , BufferType .VERTICES , BufferUsage .DYNAMIC_WRITE , builtBuffer .getBuffer ().remaining ());
260
+ RenderSystem .getDevice ().createCommandEncoder ().writeToBuffer (vertexBuffer , builtBuffer .getBuffer (), 0 );
261
+ try (RenderPass renderPass = RenderSystem .getDevice ().createCommandEncoder ().createRenderPass (framebuffer .getColorAttachment (), OptionalInt .empty (), framebuffer .getDepthAttachment (), OptionalDouble .empty ())) {
262
+ renderPass .setPipeline (pipeline );
263
+ renderPass .setVertexBuffer (0 , vertexBuffer );
264
+ renderPass .setIndexBuffer (indexBuffer , indexType );
265
+ renderPass .drawIndexed (0 , builtBuffer .getDrawParameters ().indexCount ());
266
+ }
267
+ }
268
+ }
255
269
}
256
270
257
271
entryLeft = this .getRowLeft ();
0 commit comments