From bf4a0139fb4bbd662ae8d3a2ec9c14028c9eb611 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 4 May 2024 23:02:49 +0100 Subject: [PATCH] Add support for the cape and elytra --- plugins/ShowMeYourPonies | 2 +- .../model/armour/ArmourRendererPlugin.java | 34 +++++++++++- .../render/entity/feature/CapeFeature.java | 18 ++++--- .../render/entity/feature/ElytraFeature.java | 53 +++++++++---------- 4 files changed, 68 insertions(+), 39 deletions(-) diff --git a/plugins/ShowMeYourPonies b/plugins/ShowMeYourPonies index 9932af1f..382a00c1 160000 --- a/plugins/ShowMeYourPonies +++ b/plugins/ShowMeYourPonies @@ -1 +1 @@ -Subproject commit 9932af1fa278a481fe262fbd2ed95510942b5638 +Subproject commit 382a00c11765bee906f0825fa4893b82ac141030 diff --git a/src/main/java/com/minelittlepony/client/model/armour/ArmourRendererPlugin.java b/src/main/java/com/minelittlepony/client/model/armour/ArmourRendererPlugin.java index dc18690f..aff3bee5 100644 --- a/src/main/java/com/minelittlepony/client/model/armour/ArmourRendererPlugin.java +++ b/src/main/java/com/minelittlepony/client/model/armour/ArmourRendererPlugin.java @@ -1,14 +1,15 @@ package com.minelittlepony.client.model.armour; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.model.Model; import net.minecraft.client.render.*; +import net.minecraft.client.render.item.ItemRenderer; import net.minecraft.client.texture.Sprite; import net.minecraft.client.texture.SpriteAtlasTexture; import net.minecraft.component.type.DyedColorComponent; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ArmorMaterial; -import net.minecraft.item.ItemStack; +import net.minecraft.item.*; import net.minecraft.item.trim.ArmorTrim; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.tag.ItemTags; @@ -51,6 +52,10 @@ public interface ArmourRendererPlugin { return 1F; } + default float getElytraAlpha(ItemStack stack, Model model, LivingEntity entity) { + return stack.isOf(Items.ELYTRA) ? 1F : 0F; + } + @Nullable default VertexConsumer getTrimConsumer(EquipmentSlot slot, VertexConsumerProvider provider, RegistryEntry material, ArmorTrim trim, ArmourLayer layer) { @Nullable RenderLayer renderLayer = getTrimLayer(slot, material, trim, layer); @@ -88,4 +93,29 @@ public interface ArmourRendererPlugin { default RenderLayer getGlintLayer(EquipmentSlot slot, ArmourLayer layer) { return RenderLayer.getArmorEntityGlint(); } + + @Nullable + default VertexConsumer getCapeConsumer(LivingEntity entity, VertexConsumerProvider provider, Identifier texture) { + if (entity.getEquippedStack(EquipmentSlot.CHEST).isOf(Items.ELYTRA)) { + return null; + } + @Nullable RenderLayer renderLayer = getCapeLayer(entity, texture); + return renderLayer == null ? null : provider.getBuffer(renderLayer); + } + + @Nullable + default RenderLayer getCapeLayer(LivingEntity entity, Identifier texture) { + return RenderLayer.getEntitySolid(texture); + } + + @Nullable + default VertexConsumer getElytraConsumer(ItemStack stack, Model model, LivingEntity entity, VertexConsumerProvider provider, Identifier texture) { + @Nullable RenderLayer renderLayer = getElytraLayer(entity, texture); + return renderLayer == null ? null : ItemRenderer.getDirectItemGlintConsumer(provider, model.getLayer(texture), false, stack.hasGlint()); + } + + @Nullable + default RenderLayer getElytraLayer(LivingEntity entity, Identifier texture) { + return RenderLayer.getEntitySolid(texture); + } } diff --git a/src/main/java/com/minelittlepony/client/render/entity/feature/CapeFeature.java b/src/main/java/com/minelittlepony/client/render/entity/feature/CapeFeature.java index 841a6d14..30a589fe 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/feature/CapeFeature.java +++ b/src/main/java/com/minelittlepony/client/render/entity/feature/CapeFeature.java @@ -2,18 +2,16 @@ package com.minelittlepony.client.render.entity.feature; import com.minelittlepony.api.model.BodyPart; import com.minelittlepony.client.model.ClientPonyModel; +import com.minelittlepony.client.model.armour.ArmourRendererPlugin; import com.minelittlepony.client.render.PonyRenderContext; import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.render.OverlayTexture; -import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.PlayerModelPart; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.item.Items; import net.minecraft.util.math.*; -import net.minecraft.entity.EquipmentSlot; public class CapeFeature> extends AbstractPonyFeature { @@ -22,12 +20,17 @@ public class CapeFeature> } @Override - public void render(MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, AbstractClientPlayerEntity player, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) { + public void render(MatrixStack stack, VertexConsumerProvider provider, int light, AbstractClientPlayerEntity player, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) { M model = getModelWrapper().body(); if (!player.isInvisible() - && player.isPartVisible(PlayerModelPart.CAPE) && player.getSkinTextures().capeTexture() != null - && player.getEquippedStack(EquipmentSlot.CHEST).getItem() != Items.ELYTRA) { + && player.isPartVisible(PlayerModelPart.CAPE) + && player.getSkinTextures().capeTexture() != null) { + + VertexConsumer vertices = ArmourRendererPlugin.INSTANCE.get().getCapeConsumer(player, provider, player.getSkinTextures().capeTexture()); + if (vertices == null) { + return; + } stack.push(); @@ -67,8 +70,7 @@ public class CapeFeature> stack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(180)); stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(90)); - VertexConsumer vertices = renderContext.getBuffer(RenderLayer.getEntitySolid(player.getSkinTextures().capeTexture())); - model.renderCape(stack, vertices, lightUv, OverlayTexture.DEFAULT_UV); + model.renderCape(stack, vertices, light, OverlayTexture.DEFAULT_UV); stack.pop(); } } diff --git a/src/main/java/com/minelittlepony/client/render/entity/feature/ElytraFeature.java b/src/main/java/com/minelittlepony/client/render/entity/feature/ElytraFeature.java index 1c9bdc45..2705b889 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/feature/ElytraFeature.java +++ b/src/main/java/com/minelittlepony/client/render/entity/feature/ElytraFeature.java @@ -5,6 +5,7 @@ import com.minelittlepony.api.model.PonyModel; import com.minelittlepony.api.pony.PonyPosture; import com.minelittlepony.client.model.ModelType; import com.minelittlepony.client.model.PonyElytra; +import com.minelittlepony.client.model.armour.ArmourRendererPlugin; import com.minelittlepony.client.render.PonyRenderContext; import net.minecraft.client.network.AbstractClientPlayerEntity; @@ -13,47 +14,47 @@ import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.PlayerModelPart; import net.minecraft.client.render.entity.model.EntityModel; -import net.minecraft.client.render.item.ItemRenderer; import net.minecraft.client.util.SkinTextures; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; -import net.minecraft.item.Items; import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; public class ElytraFeature & PonyModel> extends AbstractPonyFeature { - private static final Identifier TEXTURE_ELYTRA = new Identifier("textures/entity/elytra.png"); + private static final Identifier TEXTURE = new Identifier("textures/entity/elytra.png"); @SuppressWarnings("unchecked") - private final PonyElytra modelElytra = (PonyElytra)ModelType.ELYTRA.createModel(); + private final PonyElytra model = (PonyElytra)ModelType.ELYTRA.createModel(); public ElytraFeature(PonyRenderContext rp) { super(rp); } @Override - public void render(MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, T entity, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) { - ItemStack itemstack = entity.getEquippedStack(EquipmentSlot.CHEST); - - if (itemstack.getItem() == Items.ELYTRA) { - stack.push(); - preRenderCallback(stack); - - EntityModel elytra = getElytraModel(); - - getContextModel().copyStateTo(elytra); - if (elytra instanceof PonyElytra) { - ((PonyElytra)elytra).isSneaking = PonyPosture.isCrouching(getContext().getEntityPony(entity), entity); - } - - elytra.setAngles(entity, limbDistance, limbAngle, age, headYaw, headPitch); - VertexConsumer vertexConsumer = ItemRenderer.getDirectItemGlintConsumer(renderContext, modelElytra.getLayer(getElytraTexture(entity)), false, itemstack.hasGlint()); - modelElytra.render(stack, vertexConsumer, lightUv, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1); - - stack.pop(); + public void render(MatrixStack matrices, VertexConsumerProvider provider, int light, T entity, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) { + ItemStack stack = entity.getEquippedStack(EquipmentSlot.CHEST); + ArmourRendererPlugin plugin = ArmourRendererPlugin.INSTANCE.get(); + float alpha = plugin.getElytraAlpha(stack, model, entity); + if (alpha <= 0) { + return; } + + VertexConsumer vertexConsumer = plugin.getElytraConsumer(stack, model, entity, provider, getElytraTexture(entity)); + if (vertexConsumer == null) { + return; + } + + matrices.push(); + preRenderCallback(matrices); + + getContextModel().copyStateTo(model); + model.isSneaking = PonyPosture.isCrouching(getContext().getEntityPony(entity), entity); + model.setAngles(entity, limbDistance, limbAngle, age, headYaw, headPitch); + model.render(matrices, vertexConsumer, light, OverlayTexture.DEFAULT_UV, 1, 1, 1, alpha); + + matrices.pop(); } protected void preRenderCallback(MatrixStack stack) { @@ -62,10 +63,6 @@ public class ElytraFeature & Po body.transform(BodyPart.BODY, stack); } - protected EntityModel getElytraModel() { - return modelElytra; - } - protected Identifier getElytraTexture(T entity) { if (entity instanceof AbstractClientPlayerEntity player) { SkinTextures textures = player.getSkinTextures(); @@ -79,6 +76,6 @@ public class ElytraFeature & Po } } - return TEXTURE_ELYTRA; + return TEXTURE; } }