0.1.2
All checks were successful
EnergonRelics/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2020-08-17 18:59:31 -04:00
parent 116c03667f
commit dea30e1073
6 changed files with 66 additions and 47 deletions

View File

@ -1,5 +1,8 @@
# Changelog # Changelog
**Beta 0.1.2**
* Improve Highlight Rendering
**Beta 0.1.1** **Beta 0.1.1**
* Fix Texture Names * Fix Texture Names

View File

@ -10,7 +10,7 @@ org.gradle.jvmargs = -Xmx1G
fabric_loader_version = 0.9.0+build.204 fabric_loader_version = 0.9.0+build.204
# Mod Properties # Mod Properties
mod_version = 0.1.1 mod_version = 0.1.2
maven_group = com.thebrokenrail maven_group = com.thebrokenrail
# Dependencies # Dependencies

View File

@ -22,7 +22,6 @@ public class DefensiveLaserBlockEntityRenderer extends HighlightBlockEntityRende
@Override @Override
public void render(BlockEntity entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { public void render(BlockEntity entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
super.render(entity, tickDelta, matrices, vertexConsumers, light, overlay);
if (entity instanceof DefensiveLaserBlockEntity) { if (entity instanceof DefensiveLaserBlockEntity) {
matrices.push(); matrices.push();
matrices.translate(0.5d, 0.5d, 0.5d); matrices.translate(0.5d, 0.5d, 0.5d);
@ -61,5 +60,6 @@ public class DefensiveLaserBlockEntityRenderer extends HighlightBlockEntityRende
matrices.pop(); matrices.pop();
} }
} }
super.render(entity, tickDelta, matrices, vertexConsumers, light, overlay);
} }
} }

View File

@ -3,8 +3,8 @@ package com.thebrokenrail.energonrelics.client.block.entity.render;
import com.thebrokenrail.energonrelics.EnergonRelics; import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.api.block.entity.core.EnergyReceiverBlockEntity; import com.thebrokenrail.energonrelics.api.block.entity.core.EnergyReceiverBlockEntity;
import com.thebrokenrail.energonrelics.mixin.RenderPhaseAccessor; import com.thebrokenrail.energonrelics.mixin.RenderPhaseAccessor;
import net.minecraft.block.Block; import net.fabricmc.api.EnvType;
import net.minecraft.block.BlockState; import net.fabricmc.api.Environment;
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;
@ -15,21 +15,21 @@ import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher; import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.render.block.entity.BlockEntityRenderer; import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Identifier; 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)
public class HighlightBlockEntityRenderer extends BlockEntityRenderer<BlockEntity> { public class HighlightBlockEntityRenderer extends BlockEntityRenderer<BlockEntity> {
public HighlightBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) { public HighlightBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) {
super(dispatcher); super(dispatcher);
} }
private static RenderLayer getLayer(Identifier texture) { private static RenderLayer getLayer(Identifier texture) {
return RenderLayer.of(EnergonRelics.NAMESPACE + ":highlight", VertexFormats.POSITION_COLOR, 7, 256, false, true, RenderLayer.MultiPhaseParameters.builder().transparency(RenderPhaseAccessor.getTRANSLUCENT_TRANSPARENCY()).layering(RenderPhaseAccessor.getVIEW_OFFSET_Z_LAYERING()).texture(new RenderPhase.Texture(texture, false, false)).fog(RenderPhaseAccessor.getNO_FOG()).cull(RenderPhaseAccessor.getENABLE_CULLING()).build(false)); return RenderLayer.of(EnergonRelics.NAMESPACE + ":highlight", VertexFormats.POSITION_COLOR, 7, 256, false, true, RenderLayer.MultiPhaseParameters.builder().writeMaskState(RenderPhaseAccessor.getCOLOR_MASK()).transparency(RenderPhaseAccessor.getTRANSLUCENT_TRANSPARENCY()).layering(RenderPhaseAccessor.getVIEW_OFFSET_Z_LAYERING()).texture(new RenderPhase.Texture(texture, false, false)).fog(RenderPhaseAccessor.getNO_FOG()).cull(RenderPhaseAccessor.getENABLE_CULLING()).build(false));
} }
private static final RenderLayer SELECTED_LAYER = getLayer(new Identifier(EnergonRelics.NAMESPACE, "textures/entity/selected_energy_block.png")); private static final RenderLayer SELECTED_LAYER = getLayer(new Identifier(EnergonRelics.NAMESPACE, "textures/entity/selected_energy_block.png"));
@ -44,37 +44,68 @@ public class HighlightBlockEntityRenderer extends BlockEntityRenderer<BlockEntit
ItemStack stack = client.player.getStackInHand(Hand.MAIN_HAND); ItemStack stack = client.player.getStackInHand(Hand.MAIN_HAND);
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));
Matrix4f matrix4f = matrices.peek().getModel();
if (!contains) { if (!contains) {
renderLayer(entity, matrix4f, vertexConsumers.getBuffer(UNSELECTED_LAYER)); renderCuboid(matrices, vertexConsumers.getBuffer(UNSELECTED_LAYER));
} else { } else {
renderLayer(entity, matrix4f, vertexConsumers.getBuffer(SELECTED_LAYER)); renderCuboid(matrices, vertexConsumers.getBuffer(SELECTED_LAYER));
} }
} }
} }
matrices.pop(); matrices.pop();
} }
private void renderLayer(BlockEntity entity, Matrix4f matrix4f, VertexConsumer vertexConsumer) { protected static void renderCuboid(MatrixStack matrices, VertexConsumer consumer) {
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 0f, 1f, 1f, 1f, 1f, 1f, Direction.SOUTH); float sizeX = 1f;
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, Direction.NORTH); float sizeY = 1f;
renderSide(entity, matrix4f, vertexConsumer, 1f, 1f, 1f, 0f, 0f, 1f, 1f, 0f, Direction.EAST); float sizeZ = 1f;
renderSide(entity, matrix4f, vertexConsumer, 0f, 0f, 0f, 1f, 0f, 1f, 1f, 0f, Direction.WEST);
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 0f, 0f, 0f, 0f, 1f, 1f, Direction.DOWN); matrices.translate(0.5d, 0.5d, 0.5d);
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 1f, 1f, 1f, 1f, 0f, 0f, Direction.UP);
for (Direction side : Direction.values()) {
matrices.push();
multiply(matrices, side);
Matrix4f model = matrices.peek().getModel();
vertex(consumer, model, -0.5f, -0.5f, -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, -0.5f);
matrices.pop();
}
} }
protected boolean shouldDrawSide(BlockEntity entity, Direction side) { private static void vertex(VertexConsumer consumer, Matrix4f model, float x, float y, float z) {
BlockState state = entity.getCachedState(); consumer.vertex(model, x, y, z).color(1f, 1f, 1f, 1f).next();
return Block.shouldDrawSide(state, Objects.requireNonNull(entity.getWorld()), entity.getPos(), side);
} }
private void renderSide(BlockEntity entity, Matrix4f matrix4f, VertexConsumer vertexConsumer, float f, float g, float h, float i, float j, float k, float l, float m, Direction side) { private static void multiply(MatrixStack matrices, Direction side) {
if (shouldDrawSide(entity, side)) { switch (side) {
vertexConsumer.vertex(matrix4f, f, h, j).color(1f, 1f, 1f, 1f).next(); case NORTH: {
vertexConsumer.vertex(matrix4f, g, h, k).color(1f, 1f, 1f, 1f).next(); break;
vertexConsumer.vertex(matrix4f, g, i, l).color(1f, 1f, 1f, 1f).next(); }
vertexConsumer.vertex(matrix4f, f, i, m).color(1f, 1f, 1f, 1f).next(); case SOUTH: {
matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(180));
break;
}
case EAST: {
matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(-90));
break;
}
case WEST: {
matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(90));
break;
}
case UP: {
matrices.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(90));
break;
}
case DOWN: {
matrices.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(-90));
break;
}
} }
} }
} }

View File

@ -12,12 +12,10 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.Framebuffer; import net.minecraft.client.gl.Framebuffer;
import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderPhase; import net.minecraft.client.render.RenderPhase;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.VertexFormats; import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher; import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Matrix4f;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
@ -69,27 +67,9 @@ 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();
renderLayer((HolographicSkyBlockEntity) entity, matrix4f, vertexConsumerProvider.getBuffer(LAYER)); renderCuboid(matrixStack, vertexConsumerProvider.getBuffer(LAYER));
matrixStack.pop(); matrixStack.pop();
} }
super.render(entity, f, matrixStack, vertexConsumerProvider, i, j); super.render(entity, f, matrixStack, vertexConsumerProvider, i, j);
} }
private void renderLayer(HolographicSkyBlockEntity entity, Matrix4f matrix4f, VertexConsumer vertexConsumer) {
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 0f, 1f, 1f, 1f, 1f, 1f, Direction.SOUTH);
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, Direction.NORTH);
renderSide(entity, matrix4f, vertexConsumer, 1f, 1f, 1f, 0f, 0f, 1f, 1f, 0f, Direction.EAST);
renderSide(entity, matrix4f, vertexConsumer, 0f, 0f, 0f, 1f, 0f, 1f, 1f, 0f, Direction.WEST);
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 0f, 0f, 0f, 0f, 1f, 1f, Direction.DOWN);
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 1f, 1f, 1f, 1f, 0f, 0f, Direction.UP);
}
private void renderSide(HolographicSkyBlockEntity entity, Matrix4f matrix4f, VertexConsumer vertexConsumer, float f, float g, float h, float i, float j, float k, float l, float m, Direction side) {
if (shouldDrawSide(entity, side)) {
vertexConsumer.vertex(matrix4f, f, h, j).color(1f, 1f, 1f, 1f).next();
vertexConsumer.vertex(matrix4f, g, h, k).color(1f, 1f, 1f, 1f).next();
vertexConsumer.vertex(matrix4f, g, i, l).color(1f, 1f, 1f, 1f).next();
vertexConsumer.vertex(matrix4f, f, i, m).color(1f, 1f, 1f, 1f).next();
}
}
} }

View File

@ -25,4 +25,9 @@ public interface RenderPhaseAccessor {
static RenderPhase.Cull getENABLE_CULLING() { static RenderPhase.Cull getENABLE_CULLING() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Accessor
static RenderPhase.WriteMaskState getCOLOR_MASK() {
throw new UnsupportedOperationException();
}
} }