Skip to content

Commit

Permalink
fix: move block outline rendering to AFTER_PARTICLES
Browse files Browse the repository at this point in the history
Also switch to using vanilla to build block outline to avoid duplicate code

Closes #864
  • Loading branch information
klikli-dev committed Dec 19, 2022
1 parent b7ca014 commit 94d0524
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

public class OccultismRenderType extends RenderType {
private static final LineStateShard THICK_LINES = new LineStateShard(OptionalDouble.of(4.0D));
public static final RenderType OVERLAY_LINES = create("overlay_lines",
DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.LINES, 256, true, false,
private static final RenderType OVERLAY_LINES = create("overlay_lines",
DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.LINES, 256, false, false,
CompositeState.builder().setLineState(THICK_LINES)
.setLayeringState(VIEW_OFFSET_Z_LAYERING)
.setShaderState(RENDERTYPE_LINES_SHADER)
Expand All @@ -41,11 +41,17 @@ public class OccultismRenderType extends RenderType {
.setCullState(NO_CULL)
.setLightmapState(NO_LIGHTMAP)
.setWriteMaskState(COLOR_WRITE)
.setOutputState(PARTICLES_TARGET)
.createCompositeState(false));


public OccultismRenderType(String name, VertexFormat vertexFormat, VertexFormat.Mode drawMode, int bufferSize,
boolean useDelegate, boolean needsSorting, Runnable setupTaskIn,
Runnable clearTaskIn) {
super(name, vertexFormat, drawMode, bufferSize, useDelegate, needsSorting, setupTaskIn, clearTaskIn);
}

public static RenderType overlayLines() {
return OVERLAY_LINES;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

package com.github.klikli_dev.occultism.client.render;

import com.github.klikli_dev.occultism.util.RenderUtil;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.Vec3;
Expand Down Expand Up @@ -85,7 +85,7 @@ public void RenderLevelLastEvent(RenderLevelStageEvent event) {
}

protected void renderSelectedBlocks(RenderLevelStageEvent event) {
if (event.getStage() != Stage.AFTER_TRANSLUCENT_BLOCKS)
if (event.getStage() != Stage.AFTER_PARTICLES)
return;

if (!this.selectedBlocks.isEmpty()) {
Expand All @@ -102,27 +102,26 @@ protected void renderSelectedBlocks(RenderLevelStageEvent event) {

PoseStack matrixStack = event.getPoseStack();
MultiBufferSource.BufferSource buffer = Minecraft.getInstance().renderBuffers().bufferSource();
VertexConsumer builder = buffer.getBuffer(OccultismRenderType.OVERLAY_LINES);

VertexConsumer builder = buffer.getBuffer(OccultismRenderType.overlayLines());
matrixStack.pushPose();

Vec3 projectedView = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition();
matrixStack.translate(-projectedView.x, -projectedView.y, -projectedView.z);
var camera = Minecraft.getInstance().gameRenderer.getMainCamera();
Vec3 cameraPosition = camera.getPosition();
matrixStack.translate(-cameraPosition.x, -cameraPosition.y, -cameraPosition.z);

var positionMatrix = matrixStack.last().pose();
RenderUtil.buildBlockOutline(builder, positionMatrix,
LevelRenderer.renderLineBox(matrixStack, builder,
info.selectedBlock.getX(), info.selectedBlock.getY(), info.selectedBlock.getZ(),
info.selectedBlock.getX() + 1, info.selectedBlock.getY() + 1, info.selectedBlock.getZ() + 1,
info.color.getRed() / 255.0f,
info.color.getGreen() / 255.0f, info.color.getBlue() / 255.0f,
info.color.getAlpha() / 255.0f);
info.color.getAlpha() / 255.0f
);

matrixStack.popPose();
RenderSystem.disableDepthTest();
buffer.endBatch(OccultismRenderType.OVERLAY_LINES);
buffer.endBatch(OccultismRenderType.overlayLines());
}
}


}
}
//endregion Methods
Expand Down
33 changes: 0 additions & 33 deletions src/main/java/com/github/klikli_dev/occultism/util/RenderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,6 @@

public class RenderUtil {

//region Static Methods

public static void buildBlockOutline(VertexConsumer buffer, Matrix4f positionMatrix, float mx, float my, float mz, float r, float g, float b, float a) {
buffer.vertex(positionMatrix, mx, my, mz).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx + 1, my, mz).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx, my, mz).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx, my + 1, mz).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx, my, mz).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx, my, mz + 1).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx + 1, my + 1, mz + 1).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx, my + 1, mz + 1).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx + 1, my + 1, mz + 1).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx + 1, my, mz + 1).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx + 1, my + 1, mz + 1).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx + 1, my + 1, mz).color(r, g, b, a).endVertex();

buffer.vertex(positionMatrix, mx, my + 1, mz).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx, my + 1, mz + 1).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx, my + 1, mz).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx + 1, my + 1, mz).color(r, g, b, a).endVertex();

buffer.vertex(positionMatrix, mx + 1, my, mz).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx + 1, my, mz + 1).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx + 1, my, mz).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx + 1, my + 1, mz).color(r, g, b, a).endVertex();

buffer.vertex(positionMatrix, mx, my, mz + 1).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx + 1, my, mz + 1).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx, my, mz + 1).color(r, g, b, a).endVertex();
buffer.vertex(positionMatrix, mx, my + 1, mz + 1).color(r, g, b, a).endVertex();
}

/**
* copied from ItemRenderer.renderGuiItemDecorations but allows to scale
*/
Expand Down Expand Up @@ -117,5 +85,4 @@ public static void renderGuiItemDecorationsWithPose(ItemRenderer renderer, Font

}
}
//endregion Static Methods
}

0 comments on commit 94d0524

Please sign in to comment.