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

This commit is contained in:
TheBrokenRail 2020-07-31 13:13:55 -04:00
parent 17df481428
commit 81722152da
5 changed files with 30 additions and 17 deletions

View File

@ -8,6 +8,7 @@ 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;
import net.minecraft.client.render.RenderPhase;
import net.minecraft.client.render.VertexConsumer; 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;
@ -16,6 +17,7 @@ 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.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.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Matrix4f;
@ -26,11 +28,12 @@ public class HighlightBlockEntityRenderer extends BlockEntityRenderer<BlockEntit
super(dispatcher); super(dispatcher);
} }
private static RenderLayer getLayer() { private static RenderLayer getLayer(Identifier texture) {
return RenderLayer.of("energonrelics_highlight", VertexFormats.POSITION_COLOR, 7, 256, false, true, RenderLayer.MultiPhaseParameters.builder().transparency(RenderPhaseAccessor.getTRANSLUCENT_TRANSPARENCY()).layering(RenderPhaseAccessor.getVIEW_OFFSET_Z_LAYERING()).build(false)); return RenderLayer.of("energonrelics_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()).target(RenderPhaseAccessor.getITEM_TARGET()).build(false));
} }
private static final RenderLayer LAYER = getLayer(); private static final RenderLayer SELECTED_LAYER = getLayer(new Identifier(EnergonRelics.NAMESPACE, "textures/entity/selected_energy_block.png"));
private static final RenderLayer UNSELECTED_LAYER = getLayer(new Identifier(EnergonRelics.NAMESPACE, "textures/entity/unselected_energy_block.png"));
@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) {
@ -43,22 +46,22 @@ public class HighlightBlockEntityRenderer extends BlockEntityRenderer<BlockEntit
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(); Matrix4f matrix4f = matrices.peek().getModel();
if (!contains) { if (!contains) {
renderLayer(entity, matrix4f, vertexConsumers.getBuffer(LAYER), 1.0f, 0.0f); renderLayer(entity, matrix4f, vertexConsumers.getBuffer(UNSELECTED_LAYER));
} else { } else {
renderLayer(entity, matrix4f, vertexConsumers.getBuffer(LAYER), 0.0f, 1.0f); renderLayer(entity, matrix4f, vertexConsumers.getBuffer(SELECTED_LAYER));
} }
} }
} }
matrices.pop(); matrices.pop();
} }
private void renderLayer(BlockEntity entity, Matrix4f matrix4f, VertexConsumer vertexConsumer, float r, float b) { private void renderLayer(BlockEntity entity, Matrix4f matrix4f, VertexConsumer vertexConsumer) {
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 0f, 1f, 1f, 1f, 1f, 1f, r, b, Direction.SOUTH); 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, r, b, Direction.NORTH); 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, r, b, Direction.EAST); 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, r, b, Direction.WEST); 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, r, b, Direction.DOWN); renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 0f, 0f, 0f, 0f, 1f, 1f, Direction.DOWN);
renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 1.0f, 1.0f, 1f, 1f, 0f, 0f, r, b, Direction.UP); renderSide(entity, matrix4f, vertexConsumer, 0f, 1f, 1.0f, 1.0f, 1f, 1f, 0f, 0f, Direction.UP);
} }
private boolean shouldDrawSide(BlockEntity entity, Direction side) { private boolean shouldDrawSide(BlockEntity entity, Direction side) {
@ -66,12 +69,12 @@ public class HighlightBlockEntityRenderer extends BlockEntityRenderer<BlockEntit
return Block.shouldDrawSide(state, Objects.requireNonNull(entity.getWorld()), entity.getPos(), side); 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, float n, float p, Direction 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) {
if (shouldDrawSide(entity, side)) { if (shouldDrawSide(entity, side)) {
vertexConsumer.vertex(matrix4f, f, h, j).color(n, (float) 0.0, p, 0.2f).next(); vertexConsumer.vertex(matrix4f, f, h, j).color(1f, 1f, 1f, 1f).next();
vertexConsumer.vertex(matrix4f, g, h, k).color(n, (float) 0.0, p, 0.2f).next(); vertexConsumer.vertex(matrix4f, g, h, k).color(1f, 1f, 1f, 1f).next();
vertexConsumer.vertex(matrix4f, g, i, l).color(n, (float) 0.0, p, 0.2f).next(); vertexConsumer.vertex(matrix4f, g, i, l).color(1f, 1f, 1f, 1f).next();
vertexConsumer.vertex(matrix4f, f, i, m).color(n, (float) 0.0, p, 0.2f).next(); vertexConsumer.vertex(matrix4f, f, i, m).color(1f, 1f, 1f, 1f).next();
} }
} }
} }

View File

@ -15,4 +15,14 @@ public interface RenderPhaseAccessor {
static RenderPhase.Layering getVIEW_OFFSET_Z_LAYERING() { static RenderPhase.Layering getVIEW_OFFSET_Z_LAYERING() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Accessor
static RenderPhase.Fog getNO_FOG() {
throw new UnsupportedOperationException();
}
@Accessor
static RenderPhase.Target getITEM_TARGET() {
throw new UnsupportedOperationException();
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 490 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 490 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB