minecraft-src/net/minecraft/client/renderer/entity/FallingBlockRenderer.java
2025-07-04 01:41:11 +03:00

63 lines
2.4 KiB
Java

package net.minecraft.client.renderer.entity;
import com.mojang.blaze3d.vertex.PoseStack;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.state.BlockState;
@Environment(EnvType.CLIENT)
public class FallingBlockRenderer extends EntityRenderer<FallingBlockEntity> {
private final BlockRenderDispatcher dispatcher;
public FallingBlockRenderer(EntityRendererProvider.Context context) {
super(context);
this.shadowRadius = 0.5F;
this.dispatcher = context.getBlockRenderDispatcher();
}
public void render(FallingBlockEntity entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) {
BlockState blockState = entity.getBlockState();
if (blockState.getRenderShape() == RenderShape.MODEL) {
Level level = entity.level();
if (blockState != level.getBlockState(entity.blockPosition()) && blockState.getRenderShape() != RenderShape.INVISIBLE) {
poseStack.pushPose();
BlockPos blockPos = BlockPos.containing(entity.getX(), entity.getBoundingBox().maxY, entity.getZ());
poseStack.translate(-0.5, 0.0, -0.5);
this.dispatcher
.getModelRenderer()
.tesselateBlock(
level,
this.dispatcher.getBlockModel(blockState),
blockState,
blockPos,
poseStack,
buffer.getBuffer(ItemBlockRenderTypes.getMovingBlockRenderType(blockState)),
false,
RandomSource.create(),
blockState.getSeed(entity.getStartPos()),
OverlayTexture.NO_OVERLAY
);
poseStack.popPose();
super.render(entity, entityYaw, partialTicks, poseStack, buffer, packedLight);
}
}
}
/**
* Returns the location of an entity's texture.
*/
public ResourceLocation getTextureLocation(FallingBlockEntity entity) {
return TextureAtlas.LOCATION_BLOCKS;
}
}