diff options
author | Anthony Hilyard <anthony.hilyard@gmail.com> | 2023-08-07 10:32:03 -0700 |
---|---|---|
committer | Anthony Hilyard <anthony.hilyard@gmail.com> | 2023-08-07 10:32:03 -0700 |
commit | f37e965d1f2a8d8aa26c9673bc1c1fb732c22ecc (patch) | |
tree | 555ce3ecfd68a51668f2a2024261d024e0cdd9eb /src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java | |
parent | 4916249af135eec5ca9624d9af1716f2c2364682 (diff) | |
download | Iceberg-f37e965d1f2a8d8aa26c9673bc1c1fb732c22ecc.tar.gz Iceberg-f37e965d1f2a8d8aa26c9673bc1c1fb732c22ecc.tar.bz2 Iceberg-f37e965d1f2a8d8aa26c9673bc1c1fb732c22ecc.zip |
Ported to 1.20.
Diffstat (limited to 'src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java')
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java b/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java index eb91073..0b7da1f 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java +++ b/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java @@ -1,7 +1,5 @@ package com.anthonyhilyard.iceberg.util; -import org.joml.Matrix4f; - import net.minecraft.client.renderer.GameRenderer; import com.mojang.blaze3d.systems.RenderSystem; @@ -9,8 +7,9 @@ import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.BufferUploader; import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexFormat; - +import org.joml.Matrix4f; public class GuiHelper { @@ -74,4 +73,24 @@ public class GuiHelper RenderSystem.disableBlend(); } + + public static void blit(PoseStack poseStack, int x, int y, int width, int height, float texX, float texY, int texWidth, int texHeight, int fullWidth, int fullHeight) { + blit(poseStack, x, x + width, y, y + height, 0, texWidth, texHeight, texX, texY, fullWidth, fullHeight); + } + public static void blit(PoseStack poseStack, int x0, int x1, int y0, int y1, int z, int texWidth, int texHeight, float texX, float texY, int fullWidth, int fullHeight) { + innerBlit(poseStack, x0, x1, y0, y1, z, (texX + 0.0F) / (float)fullWidth, (texX + (float)texWidth) / (float)fullWidth, (texY + 0.0F) / (float)fullHeight, (texY + (float)texHeight) / (float)fullHeight); + } + + private static void innerBlit(PoseStack poseStack, int x0, int x1, int y0, int y1, int z, float u0, float u1, float v0, float v1) + { + RenderSystem.setShader(GameRenderer::getPositionTexShader); + Matrix4f matrix4f = poseStack.last().pose(); + BufferBuilder bufferbuilder = Tesselator.getInstance().getBuilder(); + bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); + bufferbuilder.vertex(matrix4f, (float)x0, (float)y0, (float)z).uv(u0, v0).endVertex(); + bufferbuilder.vertex(matrix4f, (float)x0, (float)y1, (float)z).uv(u0, v1).endVertex(); + bufferbuilder.vertex(matrix4f, (float)x1, (float)y1, (float)z).uv(u1, v1).endVertex(); + bufferbuilder.vertex(matrix4f, (float)x1, (float)y0, (float)z).uv(u1, v0).endVertex(); + BufferUploader.drawWithShader(bufferbuilder.end()); + } } |