From eae309c3ce48008a12749082ffb7f2162834f932 Mon Sep 17 00:00:00 2001 From: cc Date: Wed, 19 Jun 2024 13:39:14 -0400 Subject: [PATCH] update for 1.21 fabric --- gradle.properties | 6 +- .../chunkbounds/ChunkBoundsRenderer.java | 19 ++++-- .../moreoverlays/itemsearch/GuiRenderer.java | 65 ++++++++++--------- .../moreoverlays/itemsearch/ItemUtils.java | 2 +- .../moreoverlays/itemsearch/JeiModule.java | 2 +- .../lightoverlay/LightOverlayRenderer.java | 15 +++-- .../mixin/client/MixinOverlayRenderer.java | 3 +- src/client/resources/fabric.mod.json | 4 +- .../resources/moreoverlays.main.mixins.json | 2 +- 9 files changed, 66 insertions(+), 52 deletions(-) diff --git a/gradle.properties b/gradle.properties index dc3be70..15e8155 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,12 +4,12 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.20.6 -yarn_mappings=1.20.6+build.3 +minecraft_version=1.21 +yarn_mappings=1.21+build.2 loader_version=0.15.11 # Fabric API -fabric_version=0.99.0+1.20.6 +fabric_version=0.100.3+1.21 # Mod Properties mod_version=1.22.5.1-fabric diff --git a/src/client/java/at/ridgo8/moreoverlays/chunkbounds/ChunkBoundsRenderer.java b/src/client/java/at/ridgo8/moreoverlays/chunkbounds/ChunkBoundsRenderer.java index 2ddb027..48adce6 100644 --- a/src/client/java/at/ridgo8/moreoverlays/chunkbounds/ChunkBoundsRenderer.java +++ b/src/client/java/at/ridgo8/moreoverlays/chunkbounds/ChunkBoundsRenderer.java @@ -97,7 +97,6 @@ public static void renderEdge(PoseStack matrixstack, double x, double z, double Matrix4d matrix4d = new Matrix4d(); matrixstack.last().pose().get(matrix4d); Tesselator tess = Tesselator.getInstance(); - BufferBuilder bufferBuilder = tess.getBuilder(); Minecraft minecraft = Minecraft.getInstance(); Camera camera = minecraft.gameRenderer.getMainCamera(); @@ -112,7 +111,7 @@ public static void renderEdge(PoseStack matrixstack, double x, double z, double z -= cameraZ; - bufferBuilder.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR); + BufferBuilder bufferBuilder = tess.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR); float r = ((float) ((color >> 16) & 0xFF)) / 255F; float g = ((float) ((color >> 8) & 0xFF)) / 255F; @@ -121,14 +120,16 @@ public static void renderEdge(PoseStack matrixstack, double x, double z, double drawVertex(bufferBuilder, matrix4d, x, h3, z, r, g, b); drawVertex(bufferBuilder, matrix4d, x, h, z, r, g, b); - tess.end(); + MeshData meshData = bufferBuilder.build(); + if (meshData != null) { + BufferUploader.drawWithShader(meshData); + } } public static void renderGrid(PoseStack matrixstack, float x0, float y0, float z0, float x1, float y1, float z1, float step, int color) { Matrix4d matrix4d = new Matrix4d(); matrixstack.last().pose().get(matrix4d); Tesselator tess = Tesselator.getInstance(); - BufferBuilder renderer = tess.getBuilder(); Minecraft minecraft = Minecraft.getInstance(); Camera camera = minecraft.gameRenderer.getMainCamera(); @@ -137,7 +138,7 @@ public static void renderGrid(PoseStack matrixstack, float x0, float y0, float z double cameraZ = camera.getPosition().z; - renderer.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR); + BufferBuilder renderer = tess.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR); float r = ((float) ((color >> 16) & 0xFF)) / 255F; float g = ((float) ((color >> 8) & 0xFF)) / 255F; float b = ((float) (color & 0xFF)) / 255F; @@ -175,11 +176,15 @@ public static void renderGrid(PoseStack matrixstack, float x0, float y0, float z drawVertex(renderer, matrix4d, x1 - cameraX, y0 - cameraY, z - cameraZ, r, g, b); drawVertex(renderer, matrix4d, x1 - cameraX, y1 - cameraY, z - cameraZ, r, g, b); } - tess.end(); + + MeshData meshData = renderer.build(); + if (meshData != null) { + BufferUploader.drawWithShader(meshData); + } } private static void drawVertex(BufferBuilder renderer, Matrix4d matrix, double x, double y, double z, float r, float g, float b) { Vector4d vector4d = matrix.transform(new Vector4d(x, y, z, 1.0D)); - renderer.vertex(vector4d.x(), vector4d.y(), vector4d.z()).color(r, g, b, 1).endVertex(); + renderer.addVertex((float)vector4d.x(), (float)vector4d.y(), (float)vector4d.z()).setColor(r, g, b, 1); } } diff --git a/src/client/java/at/ridgo8/moreoverlays/itemsearch/GuiRenderer.java b/src/client/java/at/ridgo8/moreoverlays/itemsearch/GuiRenderer.java index 048eac9..7f3845a 100644 --- a/src/client/java/at/ridgo8/moreoverlays/itemsearch/GuiRenderer.java +++ b/src/client/java/at/ridgo8/moreoverlays/itemsearch/GuiRenderer.java @@ -81,7 +81,6 @@ private void drawSearchFrame(EditBox textField, PoseStack matrixstack) { RenderSystem.setShader(GameRenderer::getPositionColorShader); Tesselator tess = Tesselator.getInstance(); - BufferBuilder renderer = tess.getBuilder(); float x = textField.getX() - 2; float y = textField.getY() - 4; @@ -92,28 +91,31 @@ private void drawSearchFrame(EditBox textField, PoseStack matrixstack) { float g = ((float) ((0xFFFF00 >> 8) & 0xFF)) / 255F; float b = ((float) (0xFFFF00 & 0xFF)) / 255F; - renderer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - renderer.vertex(matrix4f, x + width + FRAME_RADIUS, y - FRAME_RADIUS, 1000).color(r, g, b, 1F).endVertex(); - renderer.vertex(matrix4f, x - FRAME_RADIUS, y - FRAME_RADIUS, 1000).color(r, g, b, 1F).endVertex(); - renderer.vertex(matrix4f, x - FRAME_RADIUS, y, 1000).color(r, g, b, 1F).endVertex(); - renderer.vertex(matrix4f, x + width + FRAME_RADIUS, y, 1000).color(r, g, b, 1F).endVertex(); - - renderer.vertex(matrix4f, x, y, 1000).color(r, g, b, 1F).endVertex(); - renderer.vertex(matrix4f, x - FRAME_RADIUS, y, 1000).color(r, g, b, 1F).endVertex(); - renderer.vertex(matrix4f, x - FRAME_RADIUS, y + height, 1000).color(r, g, b, 1F).endVertex(); - renderer.vertex(matrix4f, x, y + height, 1000).color(r, g, b, 1F).endVertex(); - - renderer.vertex(matrix4f, x + width + FRAME_RADIUS, y + height, 1000).color(r, g, b, 1F).endVertex(); - renderer.vertex(matrix4f, x - FRAME_RADIUS, y + height, 1000).color(r, g, b, 1F).endVertex(); - renderer.vertex(matrix4f, x - FRAME_RADIUS, y + height + FRAME_RADIUS, 1000).color(r, g, b, 1F).endVertex(); - renderer.vertex(matrix4f, x + width + FRAME_RADIUS, y + height + FRAME_RADIUS, 1000).color(r, g, b, 1F).endVertex(); - - renderer.vertex(matrix4f, x + width + FRAME_RADIUS, y, 1000).color(r, g, b, 1F).endVertex(); - renderer.vertex(matrix4f, x + width, y, 1000).color(r, g, b, 1F).endVertex(); - renderer.vertex(matrix4f, x + width, y + height, 1000).color(r, g, b, 1F).endVertex(); - renderer.vertex(matrix4f, x + width + FRAME_RADIUS, y + height, 1000).color(r, g, b, 1F).endVertex(); - - tess.end(); + BufferBuilder renderer = tess.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); + renderer.addVertex(matrix4f, x + width + FRAME_RADIUS, y - FRAME_RADIUS, 1000).setColor(r, g, b, 1F); + renderer.addVertex(matrix4f, x - FRAME_RADIUS, y - FRAME_RADIUS, 1000).setColor(r, g, b, 1F); + renderer.addVertex(matrix4f, x - FRAME_RADIUS, y, 1000).setColor(r, g, b, 1F); + renderer.addVertex(matrix4f, x + width + FRAME_RADIUS, y, 1000).setColor(r, g, b, 1F); + + renderer.addVertex(matrix4f, x, y, 1000).setColor(r, g, b, 1F); + renderer.addVertex(matrix4f, x - FRAME_RADIUS, y, 1000).setColor(r, g, b, 1F); + renderer.addVertex(matrix4f, x - FRAME_RADIUS, y + height, 1000).setColor(r, g, b, 1F); + renderer.addVertex(matrix4f, x, y + height, 1000).setColor(r, g, b, 1F); + + renderer.addVertex(matrix4f, x + width + FRAME_RADIUS, y + height, 1000).setColor(r, g, b, 1F); + renderer.addVertex(matrix4f, x - FRAME_RADIUS, y + height, 1000).setColor(r, g, b, 1F); + renderer.addVertex(matrix4f, x - FRAME_RADIUS, y + height + FRAME_RADIUS, 1000).setColor(r, g, b, 1F); + renderer.addVertex(matrix4f, x + width + FRAME_RADIUS, y + height + FRAME_RADIUS, 1000).setColor(r, g, b, 1F); + + renderer.addVertex(matrix4f, x + width + FRAME_RADIUS, y, 1000).setColor(r, g, b, 1F); + renderer.addVertex(matrix4f, x + width, y, 1000).setColor(r, g, b, 1F); + renderer.addVertex(matrix4f, x + width, y + height, 1000).setColor(r, g, b, 1F); + renderer.addVertex(matrix4f, x + width + FRAME_RADIUS, y + height, 1000).setColor(r, g, b, 1F); + + MeshData meshData = renderer.build(); + if (meshData != null) { + BufferUploader.drawWithShader(meshData); + } RenderSystem.disableBlend(); RenderSystem.enableDepthTest(); @@ -135,13 +137,12 @@ private void drawSlotOverlay(AbstractContainerScreen gui) { return; Tesselator tess = Tesselator.getInstance(); - BufferBuilder renderer = tess.getBuilder(); RenderSystem.enableBlend(); RenderSystem.setShader(GameRenderer::getPositionColorShader); - renderer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); + BufferBuilder renderer = tess.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); float r = ((float) ((0x000000 >> 16) & 0xFF)) / 255F; float g = ((float) ((0x000000 >> 8) & 0xFF)) / 255F; @@ -153,15 +154,17 @@ private void drawSlotOverlay(AbstractContainerScreen gui) { Vec2 posvec = slot.getValue().getView().getRenderPos(guiOffsetX, guiOffsetY); float px = posvec.x; float py = posvec.y; - renderer.vertex(px + 16 + guiOffsetX, py + guiOffsetY, OVERLAY_ZLEVEL).color(r, g, b, a).endVertex(); - renderer.vertex(px + guiOffsetX, py + guiOffsetY, OVERLAY_ZLEVEL).color(r, g, b, a).endVertex(); - renderer.vertex(px + guiOffsetX, py + 16 + guiOffsetY, OVERLAY_ZLEVEL).color(r, g, b, a).endVertex(); - renderer.vertex(px + 16 + guiOffsetX, py + 16 + guiOffsetY, OVERLAY_ZLEVEL).color(r, g, b, a).endVertex(); + renderer.addVertex(px + 16 + guiOffsetX, py + guiOffsetY, OVERLAY_ZLEVEL).setColor(r, g, b, a); + renderer.addVertex(px + guiOffsetX, py + guiOffsetY, OVERLAY_ZLEVEL).setColor(r, g, b, a); + renderer.addVertex(px + guiOffsetX, py + 16 + guiOffsetY, OVERLAY_ZLEVEL).setColor(r, g, b, a); + renderer.addVertex(px + 16 + guiOffsetX, py + 16 + guiOffsetY, OVERLAY_ZLEVEL).setColor(r, g, b, a); } } - tess.end(); - + MeshData meshData = renderer.build(); + if (meshData != null) { + BufferUploader.drawWithShader(meshData); + } RenderSystem.disableBlend(); } diff --git a/src/client/java/at/ridgo8/moreoverlays/itemsearch/ItemUtils.java b/src/client/java/at/ridgo8/moreoverlays/itemsearch/ItemUtils.java index 507732d..2455238 100644 --- a/src/client/java/at/ridgo8/moreoverlays/itemsearch/ItemUtils.java +++ b/src/client/java/at/ridgo8/moreoverlays/itemsearch/ItemUtils.java @@ -46,7 +46,7 @@ public static Collection getEnchantmentData(ItemEnchantment int level = nbt.value().getMaxLevel(); if (nbt.value() != null && level > 0) { - enchantments.add(new EnchantmentInstance(nbt.value(), level)); + enchantments.add(new EnchantmentInstance(nbt, level)); } } return enchantments; diff --git a/src/client/java/at/ridgo8/moreoverlays/itemsearch/JeiModule.java b/src/client/java/at/ridgo8/moreoverlays/itemsearch/JeiModule.java index d42ad64..02bc875 100644 --- a/src/client/java/at/ridgo8/moreoverlays/itemsearch/JeiModule.java +++ b/src/client/java/at/ridgo8/moreoverlays/itemsearch/JeiModule.java @@ -60,6 +60,6 @@ public void registerCategories(IRecipeCategoryRegistration registration) { @Override public ResourceLocation getPluginUid() { - return new ResourceLocation(MoreOverlays.MOD_ID, "jei_module"); + return ResourceLocation.fromNamespaceAndPath(MoreOverlays.MOD_ID, "jei_module"); } } diff --git a/src/client/java/at/ridgo8/moreoverlays/lightoverlay/LightOverlayRenderer.java b/src/client/java/at/ridgo8/moreoverlays/lightoverlay/LightOverlayRenderer.java index d2836ba..4d9b98c 100644 --- a/src/client/java/at/ridgo8/moreoverlays/lightoverlay/LightOverlayRenderer.java +++ b/src/client/java/at/ridgo8/moreoverlays/lightoverlay/LightOverlayRenderer.java @@ -25,7 +25,7 @@ public class LightOverlayRenderer implements ILightRenderer { public LightOverlayRenderer() { tess = Tesselator.getInstance(); - renderer = tess.getBuilder(); + renderer = tess.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR); minecraft = Minecraft.getInstance(); } @@ -78,13 +78,13 @@ private static void renderCross(PoseStack matrixstack, BlockPos pos, float r, fl private static void drawVertex(Matrix4d matrix, double x, double y, double z, float r, float g, float b) { Vector4d vector4d = matrix.transform(new Vector4d(x, y, z, 1.0D)); - renderer.vertex(vector4d.x(), vector4d.y(), vector4d.z()).color(r, g, b, 1).endVertex(); + renderer.addVertex((float)vector4d.x(), (float)vector4d.y(), (float)vector4d.z()).setColor(r, g, b, 1); } public void renderOverlays(ILightScanner scanner, PoseStack matrixstack) { RenderSystem.enableDepthTest(); RenderSystem.disableBlend(); - RenderSystem.lineWidth((float) (double) Config.render_chunkLineWidth); + RenderSystem.lineWidth((float) Config.render_chunkLineWidth); RenderSystem.setShader(GameRenderer::getPositionColorShader); float ar = ((float) ((Config.render_spawnAColor >> 16) & 0xFF)) / 255F; @@ -95,7 +95,7 @@ public void renderOverlays(ILightScanner scanner, PoseStack matrixstack) { float ng = ((float) ((Config.render_spawnNColor >> 8) & 0xFF)) / 255F; float nb = ((float) (Config.render_spawnNColor & 0xFF)) / 255F; - renderer.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR); + renderer = tess.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR); for (Pair entry : scanner.getLightModes()) { Byte mode = entry.getValue(); if (mode == null || mode == 0) @@ -105,7 +105,12 @@ else if (mode == 1) else if (mode == 2) renderCross(matrixstack, entry.getKey(), ar, ag, ab); } - tess.end(); + + MeshData meshData = renderer.build(); + if (meshData != null) { + BufferUploader.drawWithShader(meshData); + } + // restore render settings RenderSystem.depthMask(true); RenderSystem.lineWidth(1.0F); diff --git a/src/client/java/at/ridgo8/moreoverlays/mixin/client/MixinOverlayRenderer.java b/src/client/java/at/ridgo8/moreoverlays/mixin/client/MixinOverlayRenderer.java index 6b1733d..20e5add 100644 --- a/src/client/java/at/ridgo8/moreoverlays/mixin/client/MixinOverlayRenderer.java +++ b/src/client/java/at/ridgo8/moreoverlays/mixin/client/MixinOverlayRenderer.java @@ -3,6 +3,7 @@ import java.lang.reflect.Field; +import net.minecraft.client.DeltaTracker; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -20,7 +21,7 @@ @Mixin(Gui.class) public class MixinOverlayRenderer { @Inject(at = @At("TAIL"), method = "render") - private void onRender(GuiGraphics guiGraphics, float f, CallbackInfo ci) { + private void onRender(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) { Minecraft mc = Minecraft.getInstance(); try { if (mc.getDebugOverlay().showDebugScreen()) { diff --git a/src/client/resources/fabric.mod.json b/src/client/resources/fabric.mod.json index 9784e12..aaf6238 100644 --- a/src/client/resources/fabric.mod.json +++ b/src/client/resources/fabric.mod.json @@ -28,8 +28,8 @@ ], "depends": { "fabricloader": ">=0.15.0", - "minecraft": "~1.20", - "java": ">=17", + "minecraft": "~1.21", + "java": ">=21", "fabric-api": "*" } } \ No newline at end of file diff --git a/src/client/resources/moreoverlays.main.mixins.json b/src/client/resources/moreoverlays.main.mixins.json index 96dc10e..f34ec5c 100644 --- a/src/client/resources/moreoverlays.main.mixins.json +++ b/src/client/resources/moreoverlays.main.mixins.json @@ -1,7 +1,7 @@ { "required": false, "package": "at.ridgo8.moreoverlays.mixin.client", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "client": [ "MixinDebugRenderer", "MixinOverlayRenderer",