Skip to content

Commit

Permalink
try figure out why it renders through walls
Browse files Browse the repository at this point in the history
  • Loading branch information
Jab125 committed Nov 30, 2023
1 parent 6ea5e7d commit 6061ba3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
23 changes: 23 additions & 0 deletions common/src/main/java/com/ultreon/devices/api/utils/RenderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import net.minecraft.world.item.ItemStack;

import org.jetbrains.annotations.Nullable;
import org.lwjgl.opengl.GL11;

import java.awt.*;

@SuppressWarnings("unused")
Expand Down Expand Up @@ -133,6 +135,27 @@ public static void drawRectWithTexture(ResourceLocation location, PoseStack pose
BufferUploader.drawWithShader(buffer.end());
}

@Deprecated
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) {
//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).endVertex();
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.disableCull();
RenderSystem.depthFunc(GL11.GL_LEQUAL);
Tesselator.getInstance().end();
RenderSystem.enableCull();
// BufferUploader.drawWithShader(buffer.end());
}

public static void drawApplicationIcon(GuiGraphics graphics, @Nullable AppInfo info, double x, double y) {
//TODO: Reset color GlStateManager.color(1f, 1f, 1f);
RenderSystem.setShaderTexture(0, Laptop.ICON_TEXTURES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ public void render(PaperBlockEntity blockEntity, float partialTick, @NotNull Pos
pose.scale(1 / scale, 1 / scale, 1 / scale);
// pose.translate(blockEntity.getBlockPos().getX(), blockEntity.getBlockPos().getY(), blockEntity.getBlockPos().getZ());
// pose.translate(-0.5, -0.5, -0.5);
pose.pushPose();
pose.translate(-0.5, -0.5, -0.5);
pose.mulPose(state.getValue(PaperBlock.FACING).getRotation());
pose.mulPose(new Quaternionf().rotateX((float) Math.toRadians(-90)).rotateY((float) Math.toRadians(-90)));
pose.translate(0.5, 0.5, 0.5);
// pose.translate(0.5, 0.5, 0.5);

IPrint print = blockEntity.getPrint();
Expand Down Expand Up @@ -152,6 +156,7 @@ public void render(PaperBlockEntity blockEntity, float partialTick, @NotNull Pos
}
}
pose.popPose();
pose.popPose();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public boolean render(PoseStack pose, CompoundTag data) {
// This is for the paper background
if (!cut) {
RenderSystem.setShaderTexture(0, TEXTURE);
RenderUtil.drawRectWithTexture(TEXTURE, pose, 0, 0, 0, 0, 1, 1, resolution, resolution, resolution, resolution);
RenderUtil.drawRectWithTexture2(TEXTURE, pose, 0, 0, 0, 0, 1, 1, resolution, resolution, resolution, resolution);
}

// This creates a flipped copy of the pixel array
Expand All @@ -531,7 +531,7 @@ public boolean render(PoseStack pose, CompoundTag data) {
image.upload(0, 0, 0, false);

RenderSystem.setShaderTexture(0, textureId);
RenderUtil.drawRectWithTexture(null, pose, 0, 0, 0, 0, 1, 1, resolution, resolution, resolution, resolution);
RenderUtil.drawRectWithTexture2(null, pose, 0, 0, 0, 0, 1, 1, resolution, resolution, resolution, resolution);
RenderSystem.deleteTexture(textureId);

// RenderSystem.disableRescaleNormal();
Expand Down

0 comments on commit 6061ba3

Please sign in to comment.