This commit is contained in:
parent
116c03667f
commit
dea30e1073
@ -1,5 +1,8 @@
|
||||
# Changelog
|
||||
|
||||
**Beta 0.1.2**
|
||||
* Improve Highlight Rendering
|
||||
|
||||
**Beta 0.1.1**
|
||||
* Fix Texture Names
|
||||
|
||||
|
@ -10,7 +10,7 @@ org.gradle.jvmargs = -Xmx1G
|
||||
fabric_loader_version = 0.9.0+build.204
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 0.1.1
|
||||
mod_version = 0.1.2
|
||||
maven_group = com.thebrokenrail
|
||||
|
||||
# Dependencies
|
||||
|
@ -22,7 +22,6 @@ public class DefensiveLaserBlockEntityRenderer extends HighlightBlockEntityRende
|
||||
|
||||
@Override
|
||||
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) {
|
||||
matrices.push();
|
||||
matrices.translate(0.5d, 0.5d, 0.5d);
|
||||
@ -61,5 +60,6 @@ public class DefensiveLaserBlockEntityRenderer extends HighlightBlockEntityRende
|
||||
matrices.pop();
|
||||
}
|
||||
}
|
||||
super.render(entity, tickDelta, matrices, vertexConsumers, light, overlay);
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package com.thebrokenrail.energonrelics.client.block.entity.render;
|
||||
import com.thebrokenrail.energonrelics.EnergonRelics;
|
||||
import com.thebrokenrail.energonrelics.api.block.entity.core.EnergyReceiverBlockEntity;
|
||||
import com.thebrokenrail.energonrelics.mixin.RenderPhaseAccessor;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
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.BlockEntityRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class HighlightBlockEntityRenderer extends BlockEntityRenderer<BlockEntity> {
|
||||
public HighlightBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) {
|
||||
super(dispatcher);
|
||||
}
|
||||
|
||||
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"));
|
||||
@ -44,37 +44,68 @@ public class HighlightBlockEntityRenderer extends BlockEntityRenderer<BlockEntit
|
||||
ItemStack stack = client.player.getStackInHand(Hand.MAIN_HAND);
|
||||
if (stack.getItem() == EnergonRelics.NETWORK_CHIP_ITEM) {
|
||||
boolean contains = ((EnergyReceiverBlockEntity) entity).contains(EnergonRelics.NETWORK_CHIP_ITEM.getID(stack));
|
||||
Matrix4f matrix4f = matrices.peek().getModel();
|
||||
if (!contains) {
|
||||
renderLayer(entity, matrix4f, vertexConsumers.getBuffer(UNSELECTED_LAYER));
|
||||
renderCuboid(matrices, vertexConsumers.getBuffer(UNSELECTED_LAYER));
|
||||
} else {
|
||||
renderLayer(entity, matrix4f, vertexConsumers.getBuffer(SELECTED_LAYER));
|
||||
renderCuboid(matrices, vertexConsumers.getBuffer(SELECTED_LAYER));
|
||||
}
|
||||
}
|
||||
}
|
||||
matrices.pop();
|
||||
}
|
||||
|
||||
private void renderLayer(BlockEntity 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);
|
||||
protected static void renderCuboid(MatrixStack matrices, VertexConsumer consumer) {
|
||||
float sizeX = 1f;
|
||||
float sizeY = 1f;
|
||||
float sizeZ = 1f;
|
||||
|
||||
matrices.translate(0.5d, 0.5d, 0.5d);
|
||||
|
||||
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) {
|
||||
BlockState state = entity.getCachedState();
|
||||
return Block.shouldDrawSide(state, Objects.requireNonNull(entity.getWorld()), entity.getPos(), side);
|
||||
private static void vertex(VertexConsumer consumer, Matrix4f model, float x, float y, float z) {
|
||||
consumer.vertex(model, x, y, z).color(1f, 1f, 1f, 1f).next();
|
||||
}
|
||||
|
||||
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) {
|
||||
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();
|
||||
private static void multiply(MatrixStack matrices, Direction side) {
|
||||
switch (side) {
|
||||
case NORTH: {
|
||||
break;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,10 @@ import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gl.Framebuffer;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.RenderPhase;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@ -69,27 +67,9 @@ public class HolographicSkyBlockEntityRenderer extends HighlightBlockEntityRende
|
||||
if (entity instanceof HolographicSkyBlockEntity && entity.getCachedState().get(HolographicSkyBlock.POWERED)) {
|
||||
matrixStack.push();
|
||||
Matrix4f matrix4f = matrixStack.peek().getModel();
|
||||
renderLayer((HolographicSkyBlockEntity) entity, matrix4f, vertexConsumerProvider.getBuffer(LAYER));
|
||||
renderCuboid(matrixStack, vertexConsumerProvider.getBuffer(LAYER));
|
||||
matrixStack.pop();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -25,4 +25,9 @@ public interface RenderPhaseAccessor {
|
||||
static RenderPhase.Cull getENABLE_CULLING() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Accessor
|
||||
static RenderPhase.WriteMaskState getCOLOR_MASK() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user