use of net.minecraft.client.render.block.BlockRenderManager in project BleachHack by BleachDrinker420.
the class MixinChunkRebuildTask method newRender.
private Set<BlockEntity> newRender(float cameraX, float cameraY, float cameraZ, ChunkData data, BlockBufferBuilderStorage buffers) {
BlockPos blockPos = field_20839.getOrigin().toImmutable();
BlockPos blockPos2 = blockPos.add(15, 15, 15);
ChunkOcclusionDataBuilder chunkOcclusionDataBuilder = new ChunkOcclusionDataBuilder();
Set<BlockEntity> set = new HashSet<>();
ChunkRendererRegion chunkRendererRegion = this.region;
this.region = null;
MatrixStack matrixStack = new MatrixStack();
if (chunkRendererRegion != null) {
BlockModelRenderer.enableBrightnessCache();
Random random = new Random();
BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
for (BlockPos blockPos3 : BlockPos.iterate(blockPos, blockPos2)) {
BlockState blockState = chunkRendererRegion.getBlockState(blockPos3);
if (blockState.isOpaqueFullCube(chunkRendererRegion, blockPos3)) {
chunkOcclusionDataBuilder.markClosed(blockPos3);
}
if (blockState.hasBlockEntity()) {
BlockEntity blockEntityx = chunkRendererRegion.getBlockEntity(blockPos3, WorldChunk.CreationType.CHECK);
if (blockEntityx != null) {
this.addBlockEntity(data, set, blockEntityx);
}
}
FluidState fluid = chunkRendererRegion.getFluidState(blockPos3);
if (!fluid.isEmpty()) {
RenderLayer renderLayer = RenderLayers.getFluidLayer(fluid);
BufferBuilder bufferBuilder = buffers.get(renderLayer);
if (data.initializedLayers.add(renderLayer)) {
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
}
EventRenderFluid event = new EventRenderFluid(fluid, blockPos3, bufferBuilder);
BleachHack.eventBus.post(event);
if (event.isCancelled())
continue;
if (blockRenderManager.renderFluid(blockPos3, chunkRendererRegion, bufferBuilder, fluid)) {
data.empty = false;
data.nonEmptyLayers.add(renderLayer);
}
}
if (blockState.getRenderType() != BlockRenderType.INVISIBLE) {
RenderLayer renderLayer = RenderLayers.getBlockLayer(blockState);
BufferBuilder bufferBuilder = buffers.get(renderLayer);
if (data.initializedLayers.add(renderLayer)) {
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
}
EventRenderBlock.Tesselate event = new EventRenderBlock.Tesselate(blockState, blockPos3, matrixStack, bufferBuilder);
BleachHack.eventBus.post(event);
if (event.isCancelled())
continue;
matrixStack.push();
matrixStack.translate(blockPos3.getX() & 15, blockPos3.getY() & 15, blockPos3.getZ() & 15);
if (blockRenderManager.renderBlock(blockState, blockPos3, chunkRendererRegion, matrixStack, bufferBuilder, true, random)) {
data.empty = false;
data.nonEmptyLayers.add(renderLayer);
}
bufferBuilder.unfixColor();
matrixStack.pop();
}
}
if (data.nonEmptyLayers.contains(RenderLayer.getTranslucent())) {
BufferBuilder bufferBuilder2 = buffers.get(RenderLayer.getTranslucent());
bufferBuilder2.setCameraPosition(cameraX - (float) blockPos.getX(), cameraY - (float) blockPos.getY(), cameraZ - (float) blockPos.getZ());
data.bufferState = bufferBuilder2.popState();
}
Stream<RenderLayer> var10000 = data.initializedLayers.stream();
Objects.requireNonNull(buffers);
var10000.map(buffers::get).forEach(BufferBuilder::end);
BlockModelRenderer.disableBrightnessCache();
}
data.occlusionGraph = chunkOcclusionDataBuilder.build();
return set;
}
use of net.minecraft.client.render.block.BlockRenderManager in project Carrier by GabrielOlvH.
the class CarriableGeneric method render.
@Override
public void render(@NotNull PlayerEntity player, @NotNull CarrierComponent carrier, @NotNull MatrixStack matrices, @NotNull VertexConsumerProvider vcp, float tickDelta, int light) {
BlockState blockState = parent.getDefaultState();
matrices.push();
matrices.scale(0.6f, 0.6f, 0.6f);
float yaw = MathHelper.lerpAngleDegrees(tickDelta, player.prevBodyYaw, player.bodyYaw);
matrices.multiply(Vec3f.NEGATIVE_Y.getDegreesQuaternion(180));
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-yaw));
matrices.translate(-0.5, 0.8, -1.3);
BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
try {
blockRenderManager.renderBlockAsEntity(blockState, matrices, vcp, light, OverlayTexture.DEFAULT_UV);
} catch (Exception e) {
// yes this is ignored
}
matrices.pop();
}
use of net.minecraft.client.render.block.BlockRenderManager in project canvas by vram-guild.
the class MixinChunkRenderer method onRebuildChunk.
@Inject(method = "rebuildChunk", at = @At("HEAD"), cancellable = true, require = 1)
private void onRebuildChunk(final float x, final float y, final float z, final ChunkRenderTask chunkRenderTask, final CallbackInfo ci) {
final TerrainRenderContext renderContext = TerrainRenderContext.POOL.get();
final ChunkRebuildHelper help = renderContext.chunkRebuildHelper;
help.clear();
final ChunkRenderData chunkRenderData = ChunkRenderDataStore.claim();
final ChunkRenderDataExt chunkDataExt = (ChunkRenderDataExt) chunkRenderData;
final BlockPos.Mutable origin = this.origin;
final World world = this.world;
if (world != null) {
chunkRenderTask.getLock().lock();
try {
if (chunkRenderTask.getStage() != ChunkRenderTask.Stage.COMPILING) {
return;
}
chunkRenderTask.setRenderData(chunkRenderData);
} finally {
chunkRenderTask.getLock().unlock();
}
// PERF: avoid allocation
final ChunkOcclusionGraphBuilder visibilityData = new ChunkOcclusionGraphBuilder();
// PERF: avoid allocation
final HashSet<BlockEntity> blockEntities = Sets.newHashSet();
final ChunkRendererRegion vanillaRegion = chunkRenderTask.takeRegion();
if (vanillaRegion != null) {
final FastRenderRegion renderRegion = ((ChunkRendererRegionExt) vanillaRegion).canvas_fastRegion();
++chunkUpdateCount;
help.prepareCollectors(origin.getX(), origin.getY(), origin.getZ());
renderContext.setChunkTask(chunkRenderTask);
/**
* Capture the block layer result flags so our renderer can update them when more
* than one layer is rendered for a single model. This is also where we signal the
* renderer to prepare for a new chunk using the data we've accumulated up to this point.
*/
renderContext.prepare((ChunkRenderer) (Object) this, origin);
// NB: We don't use this and it probably isn't needed but leaving just in case - cost is low
BlockModelRenderer.enableBrightnessCache();
final BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
final BlockPos.Mutable searchPos = help.searchPos;
final int xMin = origin.getX();
final int yMin = origin.getY();
final int zMin = origin.getZ();
final int xMax = xMin + 16;
final int yMax = yMin + 16;
final int zMax = zMin + 16;
for (int xPos = xMin; xPos < xMax; xPos++) {
for (int yPos = yMin; yPos < yMax; yPos++) {
for (int zPos = zMin; zPos < zMax; zPos++) {
final BlockState blockState = renderRegion.getBlockState(xPos, yPos, zPos);
searchPos.set(xPos, yPos, zPos);
if (blockState.isFullOpaque(renderRegion, searchPos)) {
visibilityData.markClosed(searchPos);
}
if (blockState.getBlock().hasBlockEntity()) {
final BlockEntity blockEntity = renderRegion.getBlockEntity(searchPos, WorldChunk.CreationType.CHECK);
if (blockEntity != null) {
final BlockEntityRenderer<BlockEntity> blockEntityRenderer = BlockEntityRenderDispatcher.INSTANCE.get(blockEntity);
if (blockEntityRenderer != null) {
// Fixes MC-112730 - no reason to render both globally and in chunk
if (blockEntityRenderer.method_3563(blockEntity)) {
// global renderer - like beacons
blockEntities.add(blockEntity);
} else {
// chunk-local renderer
chunkRenderData.addBlockEntity(blockEntity);
}
}
}
}
BlockRenderLayer renderLayer;
// UGLY: we are relying on knowledge that fluid state is directly derived from block state, which
// may not be true in future versions and may break. However, is significantly faster to re-use block
// state here vs. retrieving it again.
final FluidState fluidState = blockState.getFluidState();
if (!fluidState.isEmpty()) {
renderLayer = fluidState.getRenderLayer();
// TODO: apply appropriate shader props for fluids
final FluidBufferBuilder fluidBuilder = help.fluidBuilder.prepare(help.getCollector(renderLayer).get(Canvas.MATERIAL_STANDARD, ShaderProps.waterProps()), searchPos, renderLayer);
blockRenderManager.tesselateFluid(searchPos, renderRegion, fluidBuilder, fluidState);
}
if (blockState.getRenderType() == BlockRenderType.MODEL) {
renderContext.tesselateBlock(blockState, searchPos);
}
}
}
}
if (!help.solidCollector.isEmpty()) {
chunkRenderData.markBufferInitialized(BlockRenderLayer.SOLID);
chunkDataExt.canvas_setNonEmpty(BlockRenderLayer.SOLID);
final UploadableChunk.Solid abandoned = uploadSolid.getAndSet(help.solidCollector.packUploadSolid());
if (abandoned != null) {
abandoned.cancel();
}
}
if (!help.translucentCollector.isEmpty()) {
final VertexCollectorList vcl = help.translucentCollector;
chunkRenderData.markBufferInitialized(BlockRenderLayer.TRANSLUCENT);
chunkDataExt.canvas_setNonEmpty(BlockRenderLayer.TRANSLUCENT);
vcl.setViewCoordinates(x, y, z);
chunkDataExt.canvas_collectorState(vcl.getCollectorState(null));
final UploadableChunk.Translucent abandoned = uploadTranslucent.getAndSet(vcl.packUploadTranslucent());
if (abandoned != null) {
abandoned.cancel();
}
}
/**
* Release all references. Probably not necessary but would be $#%! to debug if it is.
*/
renderContext.release();
BlockModelRenderer.disableBrightnessCache();
}
chunkRenderData.setOcclusionGraph(visibilityData.build());
lock.lock();
try {
help.tileEntitiesToAdd.addAll(blockEntities);
help.tileEntitiesToRemove.addAll(this.blockEntities);
help.tileEntitiesToAdd.removeAll(this.blockEntities);
help.tileEntitiesToRemove.removeAll(blockEntities);
this.blockEntities.clear();
this.blockEntities.addAll(blockEntities);
renderer.updateBlockEntities(help.tileEntitiesToRemove, help.tileEntitiesToAdd);
} finally {
lock.unlock();
}
}
ci.cancel();
}
use of net.minecraft.client.render.block.BlockRenderManager in project Biome-Makeover by Lemonszz.
the class GlowfishFeatureRenderer method render.
@Override
public void render(MatrixStack ms, VertexConsumerProvider vcp, int i, SalmonEntity e, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
if (!e.isBaby() && !e.isInvisible()) {
BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
BlockState shroom = BMBlocks.ORANGE_GLOWSHROOM.getDefaultState();
int m = LivingEntityRenderer.getOverlay(e, 0.0F);
ms.push();
((SalmonEntityModelAccessor) this.getContextModel()).bm_getTail().rotate(ms);
((SalmonEntityModelAccessor) this.getContextModel()).bm_getTail().visible = false;
ms.translate(0.0D, 0, 0.5F);
ms.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(-90));
ms.scale(-1.0F, -1.0F, 1.0F);
ms.translate(-0.5D, -0.5D, -0.5D);
blockRenderManager.renderBlockAsEntity(shroom, ms, vcp, i, m);
ms.pop();
}
}
use of net.minecraft.client.render.block.BlockRenderManager in project friends-and-foes by Faboslav.
the class MoobloomFlowerFeatureRenderer method render.
public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int light, T moobloomEntity, float f, float g, float h, float j, float k, float l) {
if (!moobloomEntity.isBaby() && !moobloomEntity.isInvisible()) {
BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
BlockState blockState = ModBlocks.BUTTERCUP.get().getDefaultState();
int overlay = LivingEntityRenderer.getOverlay(moobloomEntity, 0.0F);
MinecraftClient minecraftClient = MinecraftClient.getInstance();
boolean renderAsModel = minecraftClient.hasOutline(moobloomEntity) && moobloomEntity.isInvisible();
BakedModel bakedModel = blockRenderManager.getModel(blockState);
// Head
matrixStack.push();
this.getContextModel().getHead().rotate(matrixStack);
matrixStack.translate(0.09D, -0.6D, -0.185D);
matrixStack.scale(-0.8F, -0.8F, 0.8F);
matrixStack.translate(-0.5D, -0.5D, -0.5D);
this.renderFlower(matrixStack, vertexConsumerProvider, light, renderAsModel, blockRenderManager, blockState, overlay, bakedModel);
matrixStack.pop();
// Body
matrixStack.push();
matrixStack.translate(0.22D, -0.28D, -0.06D);
matrixStack.scale(-0.8F, -0.8F, 0.8F);
matrixStack.translate(-0.5D, -0.5D, -0.5D);
this.renderFlower(matrixStack, vertexConsumerProvider, light, renderAsModel, blockRenderManager, blockState, overlay, bakedModel);
matrixStack.pop();
matrixStack.push();
matrixStack.translate(-0.2D, -0.22D, 0.01D);
matrixStack.scale(-0.8F, -0.8F, 0.8F);
matrixStack.translate(-0.5D, -0.5D, -0.5D);
this.renderFlower(matrixStack, vertexConsumerProvider, light, renderAsModel, blockRenderManager, blockState, overlay, bakedModel);
matrixStack.pop();
matrixStack.push();
matrixStack.translate(0.03D, -0.28D, 0.47D);
matrixStack.scale(-0.8F, -0.8F, 0.8F);
matrixStack.translate(-0.5D, -0.5D, -0.5D);
this.renderFlower(matrixStack, vertexConsumerProvider, light, renderAsModel, blockRenderManager, blockState, overlay, bakedModel);
matrixStack.pop();
}
}
Aggregations