| 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.EntityModel;
|
| 7 | import net.minecraft.client.model.geom.EntityModelSet;
|
| 8 | import net.minecraft.client.model.geom.ModelLayers;
|
| 9 | import net.minecraft.client.model.object.equipment.ElytraModel;
|
| 10 | import net.minecraft.client.renderer.SubmitNodeCollector;
|
| 11 | import net.minecraft.client.renderer.entity.RenderLayerParent;
|
| 12 | import net.minecraft.client.renderer.entity.state.AvatarRenderState;
|
| 13 | import net.minecraft.client.renderer.entity.state.HumanoidRenderState;
|
| 14 | import net.minecraft.client.resources.model.EquipmentClientInfo;
|
| 15 | import net.minecraft.core.component.DataComponents;
|
| 16 | import net.minecraft.resources.Identifier;
|
| 17 | import net.minecraft.world.entity.player.PlayerSkin;
|
| 18 | import net.minecraft.world.item.ItemStack;
|
| 19 | import net.minecraft.world.item.equipment.Equippable;
|
| 20 | import org.jspecify.annotations.Nullable;
|
| 21 |
|
| 22 | @Environment(EnvType.CLIENT)
|
| 23 | public class WingsLayer<S extends HumanoidRenderState, M extends EntityModel<S>> extends RenderLayer<S, M> {
|
| 24 | private final ElytraModel elytraModel;
|
| 25 | private final ElytraModel elytraBabyModel;
|
| 26 | private final EquipmentLayerRenderer equipmentRenderer;
|
| 27 |
|
| 28 | public WingsLayer(final RenderLayerParent<S, M> renderer, final EntityModelSet modelSet, final EquipmentLayerRenderer equipmentRenderer) {
|
| 29 | super(renderer);
|
| 30 | this.elytraModel = new ElytraModel(modelSet.bakeLayer(ModelLayers.ELYTRA));
|
| 31 | this.elytraBabyModel = new ElytraModel(modelSet.bakeLayer(ModelLayers.ELYTRA_BABY));
|
| 32 | this.equipmentRenderer = equipmentRenderer;
|
| 33 | }
|
| 34 |
|
| 35 | public void submit(
|
| 36 | final PoseStack poseStack, final SubmitNodeCollector submitNodeCollector, final int lightCoords, final S state, final float yRot, final float xRot
|
| 37 | ) {
|
| 38 | ItemStack itemStack = state.chestEquipment;
|
| 39 | Equippable equippable = itemStack.get(DataComponents.EQUIPPABLE);
|
| 40 | if (equippable != null && !equippable.assetId().isEmpty()) {
|
| 41 | Identifier playerElytraTexture = getPlayerElytraTexture(state);
|
| 42 | ElytraModel model = state.isBaby ? this.elytraBabyModel : this.elytraModel;
|
| 43 | poseStack.pushPose();
|
| 44 | poseStack.translate(0.0F, 0.0F, 0.125F);
|
| 45 | this.equipmentRenderer
|
| 46 | .renderLayers(
|
| 47 | EquipmentClientInfo.LayerType.WINGS,
|
| 48 | equippable.assetId().get(),
|
| 49 | model,
|
| 50 | state,
|
| 51 | itemStack,
|
| 52 | poseStack,
|
| 53 | submitNodeCollector,
|
| 54 | lightCoords,
|
| 55 | playerElytraTexture,
|
| 56 | state.outlineColor,
|
| 57 | 0
|
| 58 | );
|
| 59 | poseStack.popPose();
|
| 60 | }
|
| 61 | }
|
| 62 |
|
| 63 | private static @Nullable Identifier getPlayerElytraTexture(final HumanoidRenderState state) {
|
| 64 | if (state instanceof AvatarRenderState playerState) {
|
| 65 | PlayerSkin skin = playerState.skin;
|
| 66 | if (skin.elytra() != null) {
|
| 67 | return skin.elytra().texturePath();
|
| 68 | }
|
| 69 |
|
| 70 | if (skin.cape() != null && playerState.showCape) {
|
| 71 | return skin.cape().texturePath();
|
| 72 | }
|
| 73 | }
|
| 74 |
|
| 75 | return null;
|
| 76 | }
|
| 77 | }
|
| 78 |
|