Skip to content

Commit

Permalink
Attempts were made
Browse files Browse the repository at this point in the history
  • Loading branch information
XyperCode committed Mar 31, 2024
1 parent f482b0e commit 967509e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 20 deletions.
1 change: 0 additions & 1 deletion common/src/main/java/com/ultreon/devices/Devices.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ public static boolean isDevelopmentPreview() {
return IS_DEV_PREVIEW;
}

@Deprecated(forRemoval = true)
public static MinecraftServer getServer() {
return server;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
41 changes: 30 additions & 11 deletions common/src/main/java/com/ultreon/devices/api/utils/RenderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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();
Expand All @@ -164,36 +168,51 @@ 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) {
//Gui.blit(pose, (int) x, (int) y, width, height, u, v, sourceWidth, sourceHeight, (int) textureWidth, (int) textureHeight);
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.awt.*;
import java.util.Objects;

import static net.minecraft.client.renderer.texture.OverlayTexture.NO_OVERLAY;

/**
* @author MrCrayfish
*/
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 967509e

Please sign in to comment.