From 967509e32db29fd8d90a5abad1eb518cde6b1a34 Mon Sep 17 00:00:00 2001 From: XyperCode Date: Sun, 31 Mar 2024 08:28:17 +0200 Subject: [PATCH] Attempts were made --- .../java/com/ultreon/devices/Devices.java | 1 - .../com/ultreon/devices/api/print/IPrint.java | 6 ++- .../ultreon/devices/api/utils/RenderUtil.java | 41 ++++++++++++++----- .../block/entity/renderer/PaperRenderer.java | 6 ++- .../entity/renderer/PrinterRenderer.java | 2 +- .../devices/programs/PixelPainterApp.java | 6 +-- 6 files changed, 42 insertions(+), 20 deletions(-) diff --git a/common/src/main/java/com/ultreon/devices/Devices.java b/common/src/main/java/com/ultreon/devices/Devices.java index ff5095c2..022caa13 100644 --- a/common/src/main/java/com/ultreon/devices/Devices.java +++ b/common/src/main/java/com/ultreon/devices/Devices.java @@ -160,7 +160,6 @@ public static boolean isDevelopmentPreview() { return IS_DEV_PREVIEW; } - @Deprecated(forRemoval = true) public static MinecraftServer getServer() { return server; } diff --git a/common/src/main/java/com/ultreon/devices/api/print/IPrint.java b/common/src/main/java/com/ultreon/devices/api/print/IPrint.java index 1ca7db21..e43c137c 100644 --- a/common/src/main/java/com/ultreon/devices/api/print/IPrint.java +++ b/common/src/main/java/com/ultreon/devices/api/print/IPrint.java @@ -1,10 +1,12 @@ package com.ultreon.devices.api.print; import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.VertexConsumer; import com.ultreon.devices.init.DeviceBlocks; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; @@ -79,9 +81,9 @@ static ItemStack generateItem(IPrint print) { interface Renderer { default boolean render(PoseStack pose, CompoundTag data) { - return render(pose, null, data, 0, 0); + return render(pose, Tesselator.getInstance().getBuilder(), data, 0, 0, Direction.NORTH); } - boolean render(PoseStack pose, VertexConsumer buffer, CompoundTag data, int packedLight, int packedOverlay); + boolean render(PoseStack pose, VertexConsumer buffer, CompoundTag data, int packedLight, int packedOverlay, Direction direction); } } diff --git a/common/src/main/java/com/ultreon/devices/api/utils/RenderUtil.java b/common/src/main/java/com/ultreon/devices/api/utils/RenderUtil.java index 8bb99e8d..ea38201c 100644 --- a/common/src/main/java/com/ultreon/devices/api/utils/RenderUtil.java +++ b/common/src/main/java/com/ultreon/devices/api/utils/RenderUtil.java @@ -10,10 +10,14 @@ import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.core.Direction; +import net.minecraft.core.Vec3i; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; - import org.jetbrains.annotations.Nullable; +import org.joml.Matrix3f; +import org.joml.Vector3f; +import org.joml.Vector4f; import org.lwjgl.opengl.GL11; import java.awt.*; @@ -148,7 +152,7 @@ public static void drawRectWithTexture2(ResourceLocation location, PoseStack pos buffer.vertex(e, (float) (x + width), (float) (y + height), 0).uv((u + textureWidth) * scaleWidth, (v + textureHeight) * scaleHeight).endVertex(); buffer.vertex(e, (float) (x + width), (float) y, 0).uv((u + textureWidth) * scaleWidth, v * scaleHeight).endVertex(); buffer.vertex(e, (float) x, (float) y, 0).uv(u * scaleWidth, v * scaleHeight).endVertex(); - RenderSystem.setShaderColor(1f, 1f, 1f, 1f); +// RenderSystem.setShaderColor(1f, 1f, 1f, 1f); RenderSystem.disableCull(); RenderSystem.depthFunc(GL11.GL_LEQUAL); Tesselator.getInstance().end(); @@ -164,16 +168,14 @@ public static void drawRectWithTexture2(ResourceLocation location, PoseStack pos RenderSystem.setShader(GameRenderer::getPositionTexShader); BufferBuilder buffer = Tesselator.getInstance().getBuilder(); buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); - buffer.vertex(e, (float) x, (float) (y + height), 0).uv(u * scaleWidth, (v + textureHeight) * scaleHeight).uv2(packedLight).overlayCoords(packedOverlay).endVertex(); - buffer.vertex(e, (float) (x + width), (float) (y + height), 0).uv((u + textureWidth) * scaleWidth, (v + textureHeight) * scaleHeight).uv2(packedLight).overlayCoords(packedOverlay).endVertex(); - buffer.vertex(e, (float) (x + width), (float) y, 0).uv((u + textureWidth) * scaleWidth, v * scaleHeight).uv2(packedLight).overlayCoords(packedOverlay).endVertex(); - buffer.vertex(e, (float) x, (float) y, 0).uv(u * scaleWidth, v * scaleHeight).uv2(packedLight).overlayCoords(packedOverlay).endVertex(); - RenderSystem.setShaderColor(1f, 1f, 1f, 1f); + buffer.vertex(e, (float) x, (float) (y + height), 0).uv(u * scaleWidth, (v + textureHeight) * scaleHeight).uv2(packedLight).overlayCoords(packedOverlay).color(packedLight).endVertex(); + buffer.vertex(e, (float) (x + width), (float) (y + height), 0).uv((u + textureWidth) * scaleWidth, (v + textureHeight) * scaleHeight).uv2(packedLight).overlayCoords(packedOverlay).color(packedLight).endVertex(); + buffer.vertex(e, (float) (x + width), (float) y, 0).uv((u + textureWidth) * scaleWidth, v * scaleHeight).uv2(packedLight).overlayCoords(packedOverlay).color(packedLight).endVertex(); + buffer.vertex(e, (float) x, (float) y, 0).uv(u * scaleWidth, v * scaleHeight).uv2(packedLight).overlayCoords(packedOverlay).color(packedLight).endVertex(); RenderSystem.disableCull(); RenderSystem.depthFunc(GL11.GL_LEQUAL); Tesselator.getInstance().end(); RenderSystem.enableCull(); -// BufferUploader.drawWithShader(buffer.end()); } public static void drawRectWithTexture2(ResourceLocation location, PoseStack pose, double x, double y, float u, float v, int width, int height, float textureWidth, float textureHeight, int sourceWidth, int sourceHeight, int packedLight, int packedOverlay, float normalX, float normalY, float normalZ) { @@ -181,19 +183,36 @@ public static void drawRectWithTexture2(ResourceLocation location, PoseStack pos float scaleWidth = 1f / sourceWidth; float scaleHeight = 1f / sourceHeight; var e = pose.last().pose(); - RenderSystem.setShader(GameRenderer::getPositionTexShader); BufferBuilder buffer = Tesselator.getInstance().getBuilder(); buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); buffer.vertex(e, (float) x, (float) (y + height), 0).uv(u * scaleWidth, (v + textureHeight) * scaleHeight).uv2(packedLight).overlayCoords(packedOverlay).normal(normalX, normalY, normalZ).endVertex(); buffer.vertex(e, (float) (x + width), (float) (y + height), 0).uv((u + textureWidth) * scaleWidth, (v + textureHeight) * scaleHeight).uv2(packedLight).overlayCoords(packedOverlay).normal(normalX, normalY, normalZ).endVertex(); buffer.vertex(e, (float) (x + width), (float) y, 0).uv((u + textureWidth) * scaleWidth, v * scaleHeight).uv2(packedLight).overlayCoords(packedOverlay).normal(normalX, normalY, normalZ).endVertex(); buffer.vertex(e, (float) x, (float) y, 0).uv(u * scaleWidth, v * scaleHeight).uv2(packedLight).overlayCoords(packedOverlay).normal(normalX, normalY, normalZ).endVertex(); - RenderSystem.setShaderColor(1f, 1f, 1f, 1f); RenderSystem.disableCull(); RenderSystem.depthFunc(GL11.GL_LEQUAL); Tesselator.getInstance().end(); RenderSystem.enableCull(); -// BufferUploader.drawWithShader(buffer.end()); + } + + public static void drawRectInLevel(VertexConsumer buffer, PoseStack pose, float x, float y, float z, float u, float v, int width, int height, float textureWidth, float textureHeight, int sourceWidth, int sourceHeight, int packedLight, int packedOverlay, Direction direction) { + float scaleWidth = 1f / sourceWidth; + float scaleHeight = 1f / sourceHeight; + + // Get the normal of the last matrix + Matrix3f poseNormal = pose.last().normal(); + Vec3i normal = direction.getNormal(); + Vector3f transformedNor = poseNormal.transform(new Vector3f(normal.getX(), normal.getY(), normal.getZ())); + float normalX = transformedNor.x(); + float normalY = transformedNor.y(); + float normalZ = transformedNor.z(); + + // Draw the quad + Vector4f vector4f = pose.last().pose().transform(new Vector4f(x, y, z, 1.0F)); + buffer.vertex(x, y + height, 0, 1, 1, 1, 1, u * scaleWidth, (v + textureHeight) * scaleHeight, packedOverlay, packedLight, normalX, normalY, normalZ); + buffer.vertex(x + width, y + height, 0, 1, 1, 1, 1, (u + textureWidth) * scaleWidth, (v + textureHeight) * scaleHeight, packedOverlay, packedLight, normalX, normalY, normalZ); + buffer.vertex(x + width, y, 0, 1, 1, 1, 1, (u + textureWidth) * scaleWidth, v * scaleHeight, packedOverlay, packedLight, normalX, normalY, normalZ); + buffer.vertex(x, y, 0, 1, 1, 1, 1, u * scaleWidth, v * scaleHeight, packedOverlay, packedLight, normalX, normalY, normalZ); } public static void drawApplicationIcon(GuiGraphics graphics, @Nullable AppInfo info, double x, double y) { diff --git a/common/src/main/java/com/ultreon/devices/block/entity/renderer/PaperRenderer.java b/common/src/main/java/com/ultreon/devices/block/entity/renderer/PaperRenderer.java index 719a01ad..a3092b23 100644 --- a/common/src/main/java/com/ultreon/devices/block/entity/renderer/PaperRenderer.java +++ b/common/src/main/java/com/ultreon/devices/block/entity/renderer/PaperRenderer.java @@ -27,6 +27,8 @@ import java.awt.*; import java.util.Objects; +import static net.minecraft.client.renderer.texture.OverlayTexture.NO_OVERLAY; + /** * @author MrCrayfish */ @@ -101,7 +103,7 @@ private static void drawPixels(PoseStack poseStack, int[] pixels, int resolution ResourceLocation resourcelocation = Minecraft.getInstance().getTextureManager().register("map/" + TextureIndex, d); Matrix4f matrix4f = poseStack.last().pose(); - var vertexconsumer = bufferSource.getBuffer(RenderType.text(resourcelocation)); + var vertexconsumer = bufferSource.getBuffer(RenderType.entitySolid(resourcelocation)); vertexconsumer.vertex(matrix4f, 0.0f, 128.0f, -0.01f).color(255, 255, 255, 255).uv(0.0f, 1.0f).uv2(packedLight).overlayCoords(packedOverlay).endVertex(); vertexconsumer.vertex(matrix4f, 128.0f, 128.0f, -0.01f).color(255, 255, 255, 255).uv(1.0f, 1.0f).uv2(packedLight).overlayCoords(packedOverlay).endVertex(); vertexconsumer.vertex(matrix4f, 128.0f, 0.0f, -0.01f).color(255, 255, 255, 255).uv(1.0f, 0.0f).uv2(packedLight).overlayCoords(packedOverlay).endVertex(); @@ -158,7 +160,7 @@ public void render(PaperBlockEntity blockEntity, float partialTick, @NotNull Pos { IPrint.Renderer renderer = PrintingManager.getRenderer(print); VertexConsumer buffer = bufferSource.getBuffer(RenderType.entitySolid(PrinterRenderer.PaperModel.TEXTURE)); - renderer.render(pose, buffer, data, packedLight, packedOverlay); + renderer.render(pose, buffer, data, packedLight, NO_OVERLAY, blockEntity.getBlockState().getValue(PaperBlock.FACING)); } pose.popPose(); //endregion diff --git a/common/src/main/java/com/ultreon/devices/block/entity/renderer/PrinterRenderer.java b/common/src/main/java/com/ultreon/devices/block/entity/renderer/PrinterRenderer.java index fec9b9ed..0e7dd7e9 100644 --- a/common/src/main/java/com/ultreon/devices/block/entity/renderer/PrinterRenderer.java +++ b/common/src/main/java/com/ultreon/devices/block/entity/renderer/PrinterRenderer.java @@ -117,7 +117,7 @@ private static void renderPrint(PrinterBlockEntity blockEntity, @NotNull PoseSta IPrint.Renderer renderer = PrintingManager.getRenderer(print); VertexConsumer buffer = bufferSource.getBuffer(paperModel.renderType(PaperModel.TEXTURE)); - renderer.render(pose, buffer, print.toTag(), packedLight, packedOverlay); + renderer.render(pose, buffer, print.toTag(), packedLight, packedOverlay, blockEntity.getBlockState().getValue(PrinterBlock.FACING)); pose.popPose(); } //endregion diff --git a/common/src/main/java/com/ultreon/devices/programs/PixelPainterApp.java b/common/src/main/java/com/ultreon/devices/programs/PixelPainterApp.java index 4cafdf75..e1d250f8 100644 --- a/common/src/main/java/com/ultreon/devices/programs/PixelPainterApp.java +++ b/common/src/main/java/com/ultreon/devices/programs/PixelPainterApp.java @@ -27,6 +27,7 @@ import com.ultreon.devices.programs.system.layout.StandardLayout; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.resources.ResourceLocation; @@ -494,7 +495,7 @@ public static class PictureRenderer implements IPrint.Renderer { @SuppressWarnings("resource") @Override - public boolean render(PoseStack pose, VertexConsumer buffer, CompoundTag data, int packedLight, int packedOverlay) { + public boolean render(PoseStack pose, VertexConsumer buffer, CompoundTag data, int packedLight, int packedOverlay, Direction direction) { if (data.contains("pixels", Tag.TAG_INT_ARRAY) && data.contains("resolution", Tag.TAG_INT)) { int[] pixels = data.getIntArray("pixels"); int resolution = data.getInt("resolution"); @@ -505,7 +506,6 @@ public boolean render(PoseStack pose, VertexConsumer buffer, CompoundTag data, i RenderSystem.enableBlend(); RenderSystem.enableDepthTest(); -// GlStateManager.disableLighting(); pose.mulPose(new Quaternionf(0, 0, 0, 180)); // This is for the paper background @@ -535,7 +535,7 @@ public boolean render(PoseStack pose, VertexConsumer buffer, CompoundTag data, i RenderSystem.setShaderTexture(0, textureId); Matrix3f poseNormal = pose.last().normal(); - Vector3f transformedNor = poseNormal.transform(new Vector3f(0, 0, 0)); + Vector3f transformedNor = poseNormal.transform(new Vector3f()); float norX = transformedNor.x(); float norY = transformedNor.y(); float norZ = transformedNor.z();