91 lines
		
	
	
	
		
			3.4 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			91 lines
		
	
	
	
		
			3.4 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package net.minecraft.client.renderer.blockentity;
 | |
| 
 | |
| import com.mojang.blaze3d.vertex.PoseStack;
 | |
| import com.mojang.blaze3d.vertex.VertexConsumer;
 | |
| import java.util.Set;
 | |
| 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.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;
 | |
| import org.joml.Vector3f;
 | |
| 
 | |
| @Environment(EnvType.CLIENT)
 | |
| public class ShulkerBoxRenderer implements BlockEntityRenderer<ShulkerBoxBlockEntity> {
 | |
| 	private final ShulkerBoxRenderer.ShulkerBoxModel model;
 | |
| 
 | |
| 	public ShulkerBoxRenderer(BlockEntityRendererProvider.Context context) {
 | |
| 		this(context.getModelSet());
 | |
| 	}
 | |
| 
 | |
| 	public ShulkerBoxRenderer(EntityModelSet modelSet) {
 | |
| 		this.model = new ShulkerBoxRenderer.ShulkerBoxModel(modelSet.bakeLayer(ModelLayers.SHULKER_BOX));
 | |
| 	}
 | |
| 
 | |
| 	public void render(
 | |
| 		ShulkerBoxBlockEntity blockEntity, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight, int packedOverlay, Vec3 cameraPos
 | |
| 	) {
 | |
| 		Direction direction = blockEntity.getBlockState().getValueOrElse(ShulkerBoxBlock.FACING, Direction.UP);
 | |
| 		DyeColor dyeColor = blockEntity.getColor();
 | |
| 		Material material;
 | |
| 		if (dyeColor == null) {
 | |
| 			material = Sheets.DEFAULT_SHULKER_TEXTURE_LOCATION;
 | |
| 		} else {
 | |
| 			material = Sheets.getShulkerBoxMaterial(dyeColor);
 | |
| 		}
 | |
| 
 | |
| 		float f = blockEntity.getProgress(partialTick);
 | |
| 		this.render(poseStack, bufferSource, packedLight, packedOverlay, direction, f, material);
 | |
| 	}
 | |
| 
 | |
| 	public void render(
 | |
| 		PoseStack poseStack, MultiBufferSource bufferSource, int packedLight, int packedOverlay, Direction facing, float progress, Material material
 | |
| 	) {
 | |
| 		poseStack.pushPose();
 | |
| 		this.prepareModel(poseStack, facing, progress);
 | |
| 		VertexConsumer vertexConsumer = material.buffer(bufferSource, this.model::renderType);
 | |
| 		this.model.renderToBuffer(poseStack, vertexConsumer, packedLight, packedOverlay);
 | |
| 		poseStack.popPose();
 | |
| 	}
 | |
| 
 | |
| 	private void prepareModel(PoseStack poseStack, Direction direction, float progress) {
 | |
| 		poseStack.translate(0.5F, 0.5F, 0.5F);
 | |
| 		float f = 0.9995F;
 | |
| 		poseStack.scale(0.9995F, 0.9995F, 0.9995F);
 | |
| 		poseStack.mulPose(direction.getRotation());
 | |
| 		poseStack.scale(1.0F, -1.0F, -1.0F);
 | |
| 		poseStack.translate(0.0F, -1.0F, 0.0F);
 | |
| 		this.model.animate(progress);
 | |
| 	}
 | |
| 
 | |
| 	public void getExtents(Direction direction, float progress, Set<Vector3f> output) {
 | |
| 		PoseStack poseStack = new PoseStack();
 | |
| 		this.prepareModel(poseStack, direction, progress);
 | |
| 		this.model.root().getExtentsForGui(poseStack, output);
 | |
| 	}
 | |
| 
 | |
| 	@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);
 | |
| 		}
 | |
| 	}
 | |
| }
 |