From aac343cd46a59e35a4cec834196df8b5a8a4f8f8 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 5 May 2024 00:11:15 +0100 Subject: [PATCH] Add a callback after rendering armour --- .../model/armour/ArmourRendererPlugin.java | 14 +++++++- .../render/entity/feature/ArmourFeature.java | 4 ++- .../render/entity/feature/CapeFeature.java | 34 +++++++++++-------- .../render/entity/feature/ElytraFeature.java | 4 ++- .../render/entity/feature/SkullFeature.java | 6 +++- 5 files changed, 44 insertions(+), 18 deletions(-) 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 29ab6d14..d26b8f24 100644 --- a/src/main/java/com/minelittlepony/client/model/armour/ArmourRendererPlugin.java +++ b/src/main/java/com/minelittlepony/client/model/armour/ArmourRendererPlugin.java @@ -6,6 +6,7 @@ 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.client.util.math.MatrixStack; import net.minecraft.component.type.DyedColorComponent; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; @@ -32,7 +33,11 @@ public interface ArmourRendererPlugin { return ArmourTextureResolver.INSTANCE; } - default ItemStack[] getArmorStacks(LivingEntity entity, EquipmentSlot armorSlot, ArmourLayer layer) { + default void onArmourRendered(LivingEntity entity, MatrixStack matrices, VertexConsumerProvider provider, EquipmentSlot armorSlot, ArmourLayer layer, ArmourType type) { + + } + + default ItemStack[] getArmorStacks(LivingEntity entity, EquipmentSlot armorSlot, ArmourLayer layer, ArmourType type) { return new ItemStack[] { entity.getEquippedStack(armorSlot) }; } @@ -114,4 +119,11 @@ public interface ArmourRendererPlugin { static VertexConsumer getOptionalBuffer(VertexConsumerProvider provider, @Nullable RenderLayer layer) { return layer == null ? null : provider.getBuffer(layer); } + + public enum ArmourType { + ARMOUR, + CAPE, + ELYTRA, + SKULL + } } diff --git a/src/main/java/com/minelittlepony/client/render/entity/feature/ArmourFeature.java b/src/main/java/com/minelittlepony/client/render/entity/feature/ArmourFeature.java index 4b514422..72a63b0c 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/feature/ArmourFeature.java +++ b/src/main/java/com/minelittlepony/client/render/entity/feature/ArmourFeature.java @@ -51,7 +51,7 @@ public class ArmourFeature & Po float age, float headYaw, float headPitch, EquipmentSlot armorSlot, ArmourLayer layer, ArmourRendererPlugin plugin) { - for (ItemStack stack : plugin.getArmorStacks(entity, armorSlot, layer)) { + for (ItemStack stack : plugin.getArmorStacks(entity, armorSlot, layer, ArmourRendererPlugin.ArmourType.ARMOUR)) { if (stack.isEmpty()) { continue; } @@ -119,5 +119,7 @@ public class ArmourFeature & Po } } } + + plugin.onArmourRendered(entity, matrices, provider, armorSlot, layer, ArmourRendererPlugin.ArmourType.ARMOUR); } } 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 30a589fe..dcb2b1d2 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,6 +2,7 @@ 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.ArmourLayer; import com.minelittlepony.client.model.armour.ArmourRendererPlugin; import com.minelittlepony.client.render.PonyRenderContext; @@ -11,6 +12,7 @@ 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.entity.EquipmentSlot; import net.minecraft.util.math.*; public class CapeFeature> extends AbstractPonyFeature { @@ -20,26 +22,28 @@ public class CapeFeature> } @Override - public void render(MatrixStack stack, VertexConsumerProvider provider, int light, AbstractClientPlayerEntity player, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) { + public void render(MatrixStack matrices, 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) { - VertexConsumer vertices = ArmourRendererPlugin.INSTANCE.get().getCapeConsumer(player, provider, player.getSkinTextures().capeTexture()); + ArmourRendererPlugin plugin = ArmourRendererPlugin.INSTANCE.get(); + + VertexConsumer vertices = plugin.getCapeConsumer(player, provider, player.getSkinTextures().capeTexture()); if (vertices == null) { return; } - stack.push(); + matrices.push(); - stack.translate(0, 0.24F, 0); + matrices.translate(0, 0.24F, 0); if (model.getAttributes().isLyingDown) { - stack.translate(0, -0.05F, 0); + matrices.translate(0, -0.05F, 0); } - model.transform(BodyPart.BODY, stack); - model.getBodyPart(BodyPart.BODY).rotate(stack); + model.transform(BodyPart.BODY, matrices); + model.getBodyPart(BodyPart.BODY).rotate(matrices); double capeX = MathHelper.lerp(tickDelta, player.capeX, player.prevCapeX) - MathHelper.lerp(tickDelta, player.prevX, player.getX()); double capeY = MathHelper.lerp(tickDelta, player.capeY, player.prevCapeY) - MathHelper.lerp(tickDelta, player.prevY, player.getY()); @@ -64,14 +68,16 @@ public class CapeFeature> float camera = MathHelper.lerp(tickDelta, player.prevStrideDistance, player.strideDistance); capeMotionY += MathHelper.sin(MathHelper.lerp(tickDelta, player.prevHorizontalSpeed, player.horizontalSpeed) * 6) * 32 * camera; - stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(2 + capeMotionX / 12 + capeMotionY)); - stack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees( diagMotion / 2)); - stack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-diagMotion / 2)); - stack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(180)); - stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(90)); + matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(2 + capeMotionX / 12 + capeMotionY)); + matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees( diagMotion / 2)); + matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-diagMotion / 2)); + matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(180)); + matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(90)); - model.renderCape(stack, vertices, light, OverlayTexture.DEFAULT_UV); - stack.pop(); + model.renderCape(matrices, vertices, light, OverlayTexture.DEFAULT_UV); + matrices.pop(); + + plugin.onArmourRendered(player, matrices, provider, EquipmentSlot.BODY, ArmourLayer.OUTER, ArmourRendererPlugin.ArmourType.CAPE); } } } 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 9457ee74..2ca314a9 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 @@ -35,7 +35,7 @@ public class ElytraFeature & Po public void render(MatrixStack matrices, VertexConsumerProvider provider, int light, T entity, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) { ArmourRendererPlugin plugin = ArmourRendererPlugin.INSTANCE.get(); - for (ItemStack stack : plugin.getArmorStacks(entity, EquipmentSlot.CHEST, ArmourLayer.OUTER)) { + for (ItemStack stack : plugin.getArmorStacks(entity, EquipmentSlot.CHEST, ArmourLayer.OUTER, ArmourRendererPlugin.ArmourType.ELYTRA)) { float alpha = plugin.getElytraAlpha(stack, model, entity); if (alpha <= 0) { return; @@ -56,6 +56,8 @@ public class ElytraFeature & Po matrices.pop(); } + + plugin.onArmourRendered(entity, matrices, provider, EquipmentSlot.BODY, ArmourLayer.OUTER, ArmourRendererPlugin.ArmourType.ELYTRA); } protected void preRenderCallback(MatrixStack stack) { diff --git a/src/main/java/com/minelittlepony/client/render/entity/feature/SkullFeature.java b/src/main/java/com/minelittlepony/client/render/entity/feature/SkullFeature.java index d014b9e0..02ed9ffd 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/feature/SkullFeature.java +++ b/src/main/java/com/minelittlepony/client/render/entity/feature/SkullFeature.java @@ -44,7 +44,9 @@ public class SkullFeature & Pon @Override public void render(MatrixStack matrices, VertexConsumerProvider provider, int light, T entity, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) { - for (ItemStack stack : ArmourRendererPlugin.INSTANCE.get().getArmorStacks(entity, EquipmentSlot.HEAD, ArmourLayer.OUTER)) { + ArmourRendererPlugin plugin = ArmourRendererPlugin.INSTANCE.get(); + + for (ItemStack stack : plugin.getArmorStacks(entity, EquipmentSlot.HEAD, ArmourLayer.OUTER, ArmourRendererPlugin.ArmourType.SKULL)) { if (stack.isEmpty()) { continue; } @@ -73,6 +75,8 @@ public class SkullFeature & Pon matrices.pop(); } + + plugin.onArmourRendered(entity, matrices, provider, EquipmentSlot.BODY, ArmourLayer.OUTER, ArmourRendererPlugin.ArmourType.SKULL); } private void renderBlock(MatrixStack matrices, VertexConsumerProvider provider, T entity, ItemStack stack, int light) {