mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-25 22:07:59 +01:00
Add a callback after rendering armour
This commit is contained in:
parent
c4968aed4c
commit
aac343cd46
5 changed files with 44 additions and 18 deletions
|
@ -6,6 +6,7 @@ import net.minecraft.client.render.*;
|
||||||
import net.minecraft.client.render.item.ItemRenderer;
|
import net.minecraft.client.render.item.ItemRenderer;
|
||||||
import net.minecraft.client.texture.Sprite;
|
import net.minecraft.client.texture.Sprite;
|
||||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.component.type.DyedColorComponent;
|
import net.minecraft.component.type.DyedColorComponent;
|
||||||
import net.minecraft.entity.EquipmentSlot;
|
import net.minecraft.entity.EquipmentSlot;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
|
@ -32,7 +33,11 @@ public interface ArmourRendererPlugin {
|
||||||
return ArmourTextureResolver.INSTANCE;
|
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) };
|
return new ItemStack[] { entity.getEquippedStack(armorSlot) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,4 +119,11 @@ public interface ArmourRendererPlugin {
|
||||||
static VertexConsumer getOptionalBuffer(VertexConsumerProvider provider, @Nullable RenderLayer layer) {
|
static VertexConsumer getOptionalBuffer(VertexConsumerProvider provider, @Nullable RenderLayer layer) {
|
||||||
return layer == null ? null : provider.getBuffer(layer);
|
return layer == null ? null : provider.getBuffer(layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum ArmourType {
|
||||||
|
ARMOUR,
|
||||||
|
CAPE,
|
||||||
|
ELYTRA,
|
||||||
|
SKULL
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class ArmourFeature<T extends LivingEntity, M extends EntityModel<T> & Po
|
||||||
float age, float headYaw, float headPitch,
|
float age, float headYaw, float headPitch,
|
||||||
EquipmentSlot armorSlot, ArmourLayer layer, ArmourRendererPlugin plugin) {
|
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()) {
|
if (stack.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -119,5 +119,7 @@ public class ArmourFeature<T extends LivingEntity, M extends EntityModel<T> & Po
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugin.onArmourRendered(entity, matrices, provider, armorSlot, layer, ArmourRendererPlugin.ArmourType.ARMOUR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.minelittlepony.client.render.entity.feature;
|
||||||
|
|
||||||
import com.minelittlepony.api.model.BodyPart;
|
import com.minelittlepony.api.model.BodyPart;
|
||||||
import com.minelittlepony.client.model.ClientPonyModel;
|
import com.minelittlepony.client.model.ClientPonyModel;
|
||||||
|
import com.minelittlepony.client.model.armour.ArmourLayer;
|
||||||
import com.minelittlepony.client.model.armour.ArmourRendererPlugin;
|
import com.minelittlepony.client.model.armour.ArmourRendererPlugin;
|
||||||
import com.minelittlepony.client.render.PonyRenderContext;
|
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.VertexConsumerProvider;
|
||||||
import net.minecraft.client.render.entity.PlayerModelPart;
|
import net.minecraft.client.render.entity.PlayerModelPart;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.entity.EquipmentSlot;
|
||||||
import net.minecraft.util.math.*;
|
import net.minecraft.util.math.*;
|
||||||
|
|
||||||
public class CapeFeature<M extends ClientPonyModel<AbstractClientPlayerEntity>> extends AbstractPonyFeature<AbstractClientPlayerEntity, M> {
|
public class CapeFeature<M extends ClientPonyModel<AbstractClientPlayerEntity>> extends AbstractPonyFeature<AbstractClientPlayerEntity, M> {
|
||||||
|
@ -20,26 +22,28 @@ public class CapeFeature<M extends ClientPonyModel<AbstractClientPlayerEntity>>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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();
|
M model = getModelWrapper().body();
|
||||||
|
|
||||||
if (!player.isInvisible()
|
if (!player.isInvisible()
|
||||||
&& player.isPartVisible(PlayerModelPart.CAPE)
|
&& player.isPartVisible(PlayerModelPart.CAPE)
|
||||||
&& player.getSkinTextures().capeTexture() != null) {
|
&& 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) {
|
if (vertices == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stack.push();
|
matrices.push();
|
||||||
|
|
||||||
stack.translate(0, 0.24F, 0);
|
matrices.translate(0, 0.24F, 0);
|
||||||
if (model.getAttributes().isLyingDown) {
|
if (model.getAttributes().isLyingDown) {
|
||||||
stack.translate(0, -0.05F, 0);
|
matrices.translate(0, -0.05F, 0);
|
||||||
}
|
}
|
||||||
model.transform(BodyPart.BODY, stack);
|
model.transform(BodyPart.BODY, matrices);
|
||||||
model.getBodyPart(BodyPart.BODY).rotate(stack);
|
model.getBodyPart(BodyPart.BODY).rotate(matrices);
|
||||||
|
|
||||||
double capeX = MathHelper.lerp(tickDelta, player.capeX, player.prevCapeX) - MathHelper.lerp(tickDelta, player.prevX, player.getX());
|
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());
|
double capeY = MathHelper.lerp(tickDelta, player.capeY, player.prevCapeY) - MathHelper.lerp(tickDelta, player.prevY, player.getY());
|
||||||
|
@ -64,14 +68,16 @@ public class CapeFeature<M extends ClientPonyModel<AbstractClientPlayerEntity>>
|
||||||
float camera = MathHelper.lerp(tickDelta, player.prevStrideDistance, player.strideDistance);
|
float camera = MathHelper.lerp(tickDelta, player.prevStrideDistance, player.strideDistance);
|
||||||
capeMotionY += MathHelper.sin(MathHelper.lerp(tickDelta, player.prevHorizontalSpeed, player.horizontalSpeed) * 6) * 32 * camera;
|
capeMotionY += MathHelper.sin(MathHelper.lerp(tickDelta, player.prevHorizontalSpeed, player.horizontalSpeed) * 6) * 32 * camera;
|
||||||
|
|
||||||
stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(2 + capeMotionX / 12 + capeMotionY));
|
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(2 + capeMotionX / 12 + capeMotionY));
|
||||||
stack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees( diagMotion / 2));
|
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees( diagMotion / 2));
|
||||||
stack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-diagMotion / 2));
|
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-diagMotion / 2));
|
||||||
stack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(180));
|
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(180));
|
||||||
stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(90));
|
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(90));
|
||||||
|
|
||||||
model.renderCape(stack, vertices, light, OverlayTexture.DEFAULT_UV);
|
model.renderCape(matrices, vertices, light, OverlayTexture.DEFAULT_UV);
|
||||||
stack.pop();
|
matrices.pop();
|
||||||
|
|
||||||
|
plugin.onArmourRendered(player, matrices, provider, EquipmentSlot.BODY, ArmourLayer.OUTER, ArmourRendererPlugin.ArmourType.CAPE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class ElytraFeature<T extends LivingEntity, M extends EntityModel<T> & Po
|
||||||
public void render(MatrixStack matrices, VertexConsumerProvider provider, int light, T entity, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) {
|
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();
|
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);
|
float alpha = plugin.getElytraAlpha(stack, model, entity);
|
||||||
if (alpha <= 0) {
|
if (alpha <= 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -56,6 +56,8 @@ public class ElytraFeature<T extends LivingEntity, M extends EntityModel<T> & Po
|
||||||
|
|
||||||
matrices.pop();
|
matrices.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugin.onArmourRendered(entity, matrices, provider, EquipmentSlot.BODY, ArmourLayer.OUTER, ArmourRendererPlugin.ArmourType.ELYTRA);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void preRenderCallback(MatrixStack stack) {
|
protected void preRenderCallback(MatrixStack stack) {
|
||||||
|
|
|
@ -44,7 +44,9 @@ public class SkullFeature<T extends LivingEntity, M extends EntityModel<T> & Pon
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(MatrixStack matrices, VertexConsumerProvider provider, int light, T entity, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) {
|
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()) {
|
if (stack.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -73,6 +75,8 @@ public class SkullFeature<T extends LivingEntity, M extends EntityModel<T> & Pon
|
||||||
|
|
||||||
matrices.pop();
|
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) {
|
private void renderBlock(MatrixStack matrices, VertexConsumerProvider provider, T entity, ItemStack stack, int light) {
|
||||||
|
|
Loading…
Reference in a new issue