Add Proper Culling
All checks were successful
EnergonRelics/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2020-08-20 16:02:09 -04:00
parent f38f6fbced
commit 5258a235b5
2 changed files with 23 additions and 12 deletions

View File

@ -5,6 +5,8 @@ import com.thebrokenrail.energonrelics.api.block.entity.core.EnergyReceiverBlock
import com.thebrokenrail.energonrelics.mixin.RenderPhaseAccessor; import com.thebrokenrail.energonrelics.mixin.RenderPhaseAccessor;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.RenderLayer;
@ -22,6 +24,8 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Matrix4f;
import java.util.Objects;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class HighlightBlockEntityRenderer extends BlockEntityRenderer<BlockEntity> { public class HighlightBlockEntityRenderer extends BlockEntityRenderer<BlockEntity> {
public HighlightBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) { public HighlightBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) {
@ -45,16 +49,21 @@ public class HighlightBlockEntityRenderer extends BlockEntityRenderer<BlockEntit
if (stack.getItem() == EnergonRelics.NETWORK_CHIP_ITEM) { if (stack.getItem() == EnergonRelics.NETWORK_CHIP_ITEM) {
boolean contains = ((EnergyReceiverBlockEntity) entity).contains(EnergonRelics.NETWORK_CHIP_ITEM.getID(stack)); boolean contains = ((EnergyReceiverBlockEntity) entity).contains(EnergonRelics.NETWORK_CHIP_ITEM.getID(stack));
if (!contains) { if (!contains) {
renderCuboid(matrices, vertexConsumers.getBuffer(UNSELECTED_LAYER)); renderCuboid(entity, matrices, vertexConsumers.getBuffer(UNSELECTED_LAYER));
} else { } else {
renderCuboid(matrices, vertexConsumers.getBuffer(SELECTED_LAYER)); renderCuboid(entity, matrices, vertexConsumers.getBuffer(SELECTED_LAYER));
} }
} }
} }
matrices.pop(); matrices.pop();
} }
protected static void renderCuboid(MatrixStack matrices, VertexConsumer consumer) { private static boolean shouldDrawSide(BlockEntity entity, Direction side) {
BlockState state = entity.getCachedState();
return Block.shouldDrawSide(state, Objects.requireNonNull(entity.getWorld()), entity.getPos(), side);
}
protected static void renderCuboid(BlockEntity entity, MatrixStack matrices, VertexConsumer consumer) {
float sizeX = 1f; float sizeX = 1f;
float sizeY = 1f; float sizeY = 1f;
float sizeZ = 1f; float sizeZ = 1f;
@ -62,18 +71,20 @@ public class HighlightBlockEntityRenderer extends BlockEntityRenderer<BlockEntit
matrices.translate(0.5d, 0.5d, 0.5d); matrices.translate(0.5d, 0.5d, 0.5d);
for (Direction side : Direction.values()) { for (Direction side : Direction.values()) {
matrices.push(); if (shouldDrawSide(entity, side)) {
matrices.push();
multiply(matrices, side); multiply(matrices, side);
Matrix4f model = matrices.peek().getModel(); Matrix4f model = matrices.peek().getModel();
vertex(consumer, model, -0.5f, -0.5f, -0.5f); vertex(consumer, model, -0.5f, -0.5f, -0.5f);
vertex(consumer, model, -0.5f, -0.5f + sizeY, -0.5f); vertex(consumer, model, -0.5f, -0.5f + sizeY, -0.5f);
vertex(consumer, model, -0.5f + sizeX, -0.5f + sizeY, -0.5f); vertex(consumer, model, -0.5f + sizeX, -0.5f + sizeY, -0.5f);
vertex(consumer, model, -0.5f + sizeX, -0.5f, -0.5f); vertex(consumer, model, -0.5f + sizeX, -0.5f, -0.5f);
matrices.pop(); matrices.pop();
}
} }
} }

View File

@ -67,7 +67,7 @@ public class HolographicSkyBlockEntityRenderer extends HighlightBlockEntityRende
if (entity instanceof HolographicSkyBlockEntity && entity.getCachedState().get(HolographicSkyBlock.POWERED)) { if (entity instanceof HolographicSkyBlockEntity && entity.getCachedState().get(HolographicSkyBlock.POWERED)) {
matrixStack.push(); matrixStack.push();
Matrix4f matrix4f = matrixStack.peek().getModel(); Matrix4f matrix4f = matrixStack.peek().getModel();
renderCuboid(matrixStack, vertexConsumerProvider.getBuffer(LAYER)); renderCuboid(entity, matrixStack, vertexConsumerProvider.getBuffer(LAYER));
matrixStack.pop(); matrixStack.pop();
} }
super.render(entity, f, matrixStack, vertexConsumerProvider, i, j); super.render(entity, f, matrixStack, vertexConsumerProvider, i, j);