|
18 | 18 | import eu.midnightdust.midnightcontrols.client.compat.MidnightControlsCompat; |
19 | 19 | import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding; |
20 | 20 | import eu.midnightdust.midnightcontrols.client.enums.VirtualMouseSkin; |
| 21 | +import eu.midnightdust.midnightcontrols.client.mixin.DrawContextAccessor; |
21 | 22 | import eu.midnightdust.midnightcontrols.client.util.HandledScreenAccessor; |
22 | 23 | import net.minecraft.client.MinecraftClient; |
23 | 24 | import net.minecraft.client.font.TextRenderer; |
24 | 25 | import net.minecraft.client.gui.DrawContext; |
25 | | -import net.minecraft.client.render.BufferBuilder; |
26 | | -import net.minecraft.client.render.BufferRenderer; |
27 | | -import net.minecraft.client.render.GameRenderer; |
28 | | -import net.minecraft.client.render.Tessellator; |
29 | | -import net.minecraft.client.render.VertexFormat; |
30 | | -import net.minecraft.client.render.VertexFormats; |
| 26 | +import net.minecraft.client.render.*; |
31 | 27 | import net.minecraft.client.resource.language.I18n; |
32 | 28 | import net.minecraft.client.texture.Sprite; |
33 | 29 | import net.minecraft.screen.slot.Slot; |
34 | 30 | import net.minecraft.util.Identifier; |
| 31 | +import net.minecraft.util.math.ColorHelper; |
35 | 32 | import org.jetbrains.annotations.NotNull; |
36 | 33 | import org.joml.Matrix4f; |
37 | 34 | import org.lwjgl.glfw.GLFW; |
38 | 35 |
|
| 36 | +import java.util.function.Function; |
| 37 | + |
39 | 38 | import static eu.midnightdust.midnightcontrols.MidnightControls.id; |
40 | 39 |
|
41 | 40 | /** |
@@ -175,7 +174,7 @@ else if (button >= 500) { |
175 | 174 | int assetSize = axis || (button >= 15 && button <= 18) ? AXIS_SIZE : BUTTON_SIZE; |
176 | 175 |
|
177 | 176 | RenderSystem.setShaderColor(1.f, second ? 0.f : 1.f, 1.f, 1.f); |
178 | | - context.drawTexture(axis ? MidnightControlsClient.CONTROLLER_AXIS : button >= 15 && button <= 19 ? MidnightControlsClient.CONTROLLER_EXPANDED :MidnightControlsClient.CONTROLLER_BUTTONS |
| 177 | + context.drawTexture(RenderLayer::getGuiTextured, axis ? MidnightControlsClient.CONTROLLER_AXIS : button >= 15 && button <= 19 ? MidnightControlsClient.CONTROLLER_EXPANDED :MidnightControlsClient.CONTROLLER_BUTTONS |
179 | 178 | , x + (ICON_SIZE / 2 - assetSize / 2), y + (ICON_SIZE / 2 - assetSize / 2), |
180 | 179 | (float) buttonOffset, (float) (controllerType * assetSize), |
181 | 180 | assetSize, assetSize, |
@@ -216,7 +215,7 @@ public static void renderWaylandCursor(@NotNull DrawContext context, @NotNull Mi |
216 | 215 | if (MidnightControlsConfig.virtualMouseSkin == VirtualMouseSkin.DEFAULT_DARK || MidnightControlsConfig.virtualMouseSkin == VirtualMouseSkin.SECOND_DARK) |
217 | 216 | spritePath = MidnightControlsClient.WAYLAND_CURSOR_TEXTURE_DARK; |
218 | 217 | Sprite sprite = client.getGuiAtlasManager().getSprite(spritePath); |
219 | | - drawUnalignedTexturedQuad(sprite.getAtlasId(), context, mouseX, mouseX + 8, mouseY, mouseY + 8, 999, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV()); |
| 218 | + drawUnalignedTexturedQuad(RenderLayer::getGuiTextured, sprite.getAtlasId(), context, mouseX, mouseX + 8, mouseY, mouseY + 8, 999, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV()); |
220 | 219 | } catch (IllegalStateException ignored) {} |
221 | 220 | } |
222 | 221 |
|
@@ -260,19 +259,20 @@ public static void renderVirtualCursor(@NotNull DrawContext context, @NotNull Mi |
260 | 259 |
|
261 | 260 | try { |
262 | 261 | Sprite sprite = client.getGuiAtlasManager().getSprite(id(MidnightControlsConfig.virtualMouseSkin.getSpritePath() + (hoverSlot ? "_slot" : ""))); |
263 | | - drawUnalignedTexturedQuad(sprite.getAtlasId(), context, mouseX, mouseX + 16, mouseY, mouseY + 16, 999, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV()); |
| 262 | + drawUnalignedTexturedQuad(RenderLayer::getGuiTextured, sprite.getAtlasId(), context, mouseX, mouseX + 16, mouseY, mouseY + 16, 999, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV()); |
264 | 263 | } catch (IllegalStateException ignored) {} |
265 | 264 | } |
266 | | - private static void drawUnalignedTexturedQuad(Identifier texture, DrawContext context, float x1, float x2, float y1, float y2, float z, float u1, float u2, float v1, float v2) { |
267 | | - RenderSystem.setShaderTexture(0, texture); |
268 | | - RenderSystem.setShader(GameRenderer::getPositionTexProgram); |
| 265 | + private static void drawUnalignedTexturedQuad(Function<Identifier, RenderLayer> renderLayers, Identifier texture, DrawContext context, float x1, float x2, float y1, float y2, float z, float u1, float u2, float v1, float v2) { |
| 266 | + RenderLayer renderLayer = renderLayers.apply(texture); |
| 267 | + //RenderSystem.setShaderTexture(0, texture); |
269 | 268 | Matrix4f matrix4f = context.getMatrices().peek().getPositionMatrix(); |
270 | | - BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE); |
271 | | - bufferBuilder.vertex(matrix4f, x1, y1, z).texture(u1, v1); |
272 | | - bufferBuilder.vertex(matrix4f, x1, y2, z).texture(u1, v2); |
273 | | - bufferBuilder.vertex(matrix4f, x2, y2, z).texture(u2, v2); |
274 | | - bufferBuilder.vertex(matrix4f, x2, y1, z).texture(u2, v1); |
275 | | - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); |
| 269 | + //BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE); |
| 270 | + VertexConsumer vertexConsumer = ((DrawContextAccessor)context).getVertexConsumers().getBuffer(renderLayer); |
| 271 | + vertexConsumer.vertex(matrix4f, x1, y1, z).texture(u1, v1).color(ColorHelper.getWhite(1.0f)); |
| 272 | + vertexConsumer.vertex(matrix4f, x1, y2, z).texture(u1, v2).color(ColorHelper.getWhite(1.0f)); |
| 273 | + vertexConsumer.vertex(matrix4f, x2, y2, z).texture(u2, v2).color(ColorHelper.getWhite(1.0f)); |
| 274 | + vertexConsumer.vertex(matrix4f, x2, y1, z).texture(u2, v1).color(ColorHelper.getWhite(1.0f)); |
| 275 | + context.draw(); |
276 | 276 | } |
277 | 277 |
|
278 | 278 | public record ButtonSize(int length, int height) { |
|
0 commit comments