| 1 | package net.minecraft.client.renderer.entity.layers;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.vertex.PoseStack;
|
| 4 | import net.fabricmc.api.EnvType;
|
| 5 | import net.fabricmc.api.Environment;
|
| 6 | import net.minecraft.client.model.animal.llama.BabyLlamaModel;
|
| 7 | import net.minecraft.client.model.animal.llama.LlamaModel;
|
| 8 | import net.minecraft.client.model.geom.EntityModelSet;
|
| 9 | import net.minecraft.client.model.geom.ModelLayers;
|
| 10 | import net.minecraft.client.renderer.SubmitNodeCollector;
|
| 11 | import net.minecraft.client.renderer.entity.RenderLayerParent;
|
| 12 | import net.minecraft.client.renderer.entity.state.LlamaRenderState;
|
| 13 | import net.minecraft.client.resources.model.EquipmentClientInfo;
|
| 14 | import net.minecraft.core.component.DataComponents;
|
| 15 | import net.minecraft.resources.ResourceKey;
|
| 16 | import net.minecraft.world.item.ItemStack;
|
| 17 | import net.minecraft.world.item.equipment.EquipmentAsset;
|
| 18 | import net.minecraft.world.item.equipment.EquipmentAssets;
|
| 19 | import net.minecraft.world.item.equipment.Equippable;
|
| 20 |
|
| 21 | @Environment(EnvType.CLIENT)
|
| 22 | public class LlamaDecorLayer extends RenderLayer<LlamaRenderState, LlamaModel> {
|
| 23 | private final LlamaModel adultModel;
|
| 24 | private final LlamaModel babyModel;
|
| 25 | private final EquipmentLayerRenderer equipmentRenderer;
|
| 26 |
|
| 27 | public LlamaDecorLayer(
|
| 28 | final RenderLayerParent<LlamaRenderState, LlamaModel> renderer, final EntityModelSet modelSet, final EquipmentLayerRenderer equipmentRenderer
|
| 29 | ) {
|
| 30 | super(renderer);
|
| 31 | this.equipmentRenderer = equipmentRenderer;
|
| 32 | this.adultModel = new LlamaModel(modelSet.bakeLayer(ModelLayers.LLAMA_DECOR));
|
| 33 | this.babyModel = new BabyLlamaModel(modelSet.bakeLayer(ModelLayers.LLAMA_BABY_DECOR));
|
| 34 | }
|
| 35 |
|
| 36 | public void submit(
|
| 37 | final PoseStack poseStack,
|
| 38 | final SubmitNodeCollector submitNodeCollector,
|
| 39 | final int lightCoords,
|
| 40 | final LlamaRenderState state,
|
| 41 | final float yRot,
|
| 42 | final float xRot
|
| 43 | ) {
|
| 44 | ItemStack itemStack = state.bodyItem;
|
| 45 | Equippable equippable = itemStack.get(DataComponents.EQUIPPABLE);
|
| 46 | if (equippable != null && equippable.assetId().isPresent() && !state.isBaby) {
|
| 47 | this.renderEquipment(poseStack, submitNodeCollector, state, itemStack, equippable.assetId().get(), lightCoords);
|
| 48 | } else if (state.isTraderLlama) {
|
| 49 | this.renderEquipment(
|
| 50 | poseStack, submitNodeCollector, state, ItemStack.EMPTY, state.isBaby ? EquipmentAssets.TRADER_LLAMA_BABY : EquipmentAssets.TRADER_LLAMA, lightCoords
|
| 51 | );
|
| 52 | }
|
| 53 | }
|
| 54 |
|
| 55 | private void renderEquipment(
|
| 56 | final PoseStack poseStack,
|
| 57 | final SubmitNodeCollector submitNodeCollector,
|
| 58 | final LlamaRenderState state,
|
| 59 | final ItemStack itemStack,
|
| 60 | final ResourceKey<EquipmentAsset> equipmentAssetId,
|
| 61 | final int lightCoords
|
| 62 | ) {
|
| 63 | LlamaModel model = state.isBaby ? this.babyModel : this.adultModel;
|
| 64 | this.equipmentRenderer
|
| 65 | .renderLayers(
|
| 66 | EquipmentClientInfo.LayerType.LLAMA_BODY, equipmentAssetId, model, state, itemStack, poseStack, submitNodeCollector, lightCoords, state.outlineColor
|
| 67 | );
|
| 68 | }
|
| 69 | }
|
| 70 |
|