Add support for the cape and elytra

This commit is contained in:
Sollace 2024-05-04 23:02:49 +01:00
parent 53b8921c50
commit bf4a0139fb
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
4 changed files with 68 additions and 39 deletions

@ -1 +1 @@
Subproject commit 9932af1fa278a481fe262fbd2ed95510942b5638
Subproject commit 382a00c11765bee906f0825fa4893b82ac141030

View file

@ -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<ArmorMaterial> 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);
}
}

View file

@ -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<M extends ClientPonyModel<AbstractClientPlayerEntity>> extends AbstractPonyFeature<AbstractClientPlayerEntity, M> {
@ -22,12 +20,17 @@ public class CapeFeature<M extends ClientPonyModel<AbstractClientPlayerEntity>>
}
@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<M extends ClientPonyModel<AbstractClientPlayerEntity>>
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();
}
}

View file

@ -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<T extends LivingEntity, M extends EntityModel<T> & PonyModel<T>> extends AbstractPonyFeature<T, M> {
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<T> modelElytra = (PonyElytra<T>)ModelType.ELYTRA.createModel();
private final PonyElytra<T> model = (PonyElytra<T>)ModelType.ELYTRA.createModel();
public ElytraFeature(PonyRenderContext<T, M> 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<T> elytra = getElytraModel();
getContextModel().copyStateTo(elytra);
if (elytra instanceof PonyElytra) {
((PonyElytra<T>)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<T extends LivingEntity, M extends EntityModel<T> & Po
body.transform(BodyPart.BODY, stack);
}
protected EntityModel<T> getElytraModel() {
return modelElytra;
}
protected Identifier getElytraTexture(T entity) {
if (entity instanceof AbstractClientPlayerEntity player) {
SkinTextures textures = player.getSkinTextures();
@ -79,6 +76,6 @@ public class ElytraFeature<T extends LivingEntity, M extends EntityModel<T> & Po
}
}
return TEXTURE_ELYTRA;
return TEXTURE;
}
}