78 lines
3 KiB
Java
78 lines
3 KiB
Java
package net.minecraft.client.renderer.blockentity;
|
|
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.client.model.Model;
|
|
import net.minecraft.client.model.geom.EntityModelSet;
|
|
import net.minecraft.client.model.geom.ModelLayers;
|
|
import net.minecraft.client.model.geom.ModelPart;
|
|
import net.minecraft.client.renderer.MultiBufferSource;
|
|
import net.minecraft.client.renderer.RenderType;
|
|
import net.minecraft.client.renderer.Sheets;
|
|
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider.Context;
|
|
import net.minecraft.client.resources.model.Material;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.item.DyeColor;
|
|
import net.minecraft.world.level.block.ShulkerBoxBlock;
|
|
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
|
|
import net.minecraft.world.phys.Vec3;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public class ShulkerBoxRenderer implements BlockEntityRenderer<ShulkerBoxBlockEntity> {
|
|
private final ShulkerBoxRenderer.ShulkerBoxModel model;
|
|
|
|
public ShulkerBoxRenderer(Context context) {
|
|
this(context.getModelSet());
|
|
}
|
|
|
|
public ShulkerBoxRenderer(EntityModelSet modelSet) {
|
|
this.model = new ShulkerBoxRenderer.ShulkerBoxModel(modelSet.bakeLayer(ModelLayers.SHULKER_BOX));
|
|
}
|
|
|
|
public void render(ShulkerBoxBlockEntity shulkerBoxBlockEntity, float f, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, int j, Vec3 vec3) {
|
|
Direction direction = shulkerBoxBlockEntity.getBlockState().getValueOrElse(ShulkerBoxBlock.FACING, Direction.UP);
|
|
DyeColor dyeColor = shulkerBoxBlockEntity.getColor();
|
|
Material material;
|
|
if (dyeColor == null) {
|
|
material = Sheets.DEFAULT_SHULKER_TEXTURE_LOCATION;
|
|
} else {
|
|
material = Sheets.getShulkerBoxMaterial(dyeColor);
|
|
}
|
|
|
|
float g = shulkerBoxBlockEntity.getProgress(f);
|
|
this.render(poseStack, multiBufferSource, i, j, direction, g, material);
|
|
}
|
|
|
|
public void render(
|
|
PoseStack poseStack, MultiBufferSource bufferSource, int packedLight, int packedOverlay, Direction facing, float progress, Material material
|
|
) {
|
|
poseStack.pushPose();
|
|
poseStack.translate(0.5F, 0.5F, 0.5F);
|
|
float f = 0.9995F;
|
|
poseStack.scale(0.9995F, 0.9995F, 0.9995F);
|
|
poseStack.mulPose(facing.getRotation());
|
|
poseStack.scale(1.0F, -1.0F, -1.0F);
|
|
poseStack.translate(0.0F, -1.0F, 0.0F);
|
|
this.model.animate(progress);
|
|
VertexConsumer vertexConsumer = material.buffer(bufferSource, this.model::renderType);
|
|
this.model.renderToBuffer(poseStack, vertexConsumer, packedLight, packedOverlay);
|
|
poseStack.popPose();
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
static class ShulkerBoxModel extends Model {
|
|
private final ModelPart lid;
|
|
|
|
public ShulkerBoxModel(ModelPart root) {
|
|
super(root, RenderType::entityCutoutNoCull);
|
|
this.lid = root.getChild("lid");
|
|
}
|
|
|
|
public void animate(float progress) {
|
|
this.lid.setPos(0.0F, 24.0F - progress * 0.5F * 16.0F, 0.0F);
|
|
this.lid.yRot = 270.0F * progress * (float) (Math.PI / 180.0);
|
|
}
|
|
}
|
|
}
|