Clean up a bit and allow for setting alpha

This commit is contained in:
Sollace 2024-05-04 22:01:10 +01:00
parent 93a895e90e
commit 0da671b699
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 71 additions and 38 deletions

@ -1 +1 @@
Subproject commit c4f3e09c933521749a7d349c39e212ffabd1b375
Subproject commit 9932af1fa278a481fe262fbd2ed95510942b5638

View file

@ -35,32 +35,57 @@ public interface ArmourRendererPlugin {
return new ItemStack[] { entity.getEquippedStack(armorSlot) };
}
default boolean shouldRenderGlint(EquipmentSlot slot, ItemStack stack) {
return stack.hasGlint();
default float getGlintAlpha(EquipmentSlot slot, ItemStack stack) {
return stack.hasGlint() ? 1 : 0;
}
default int getDyeColor(EquipmentSlot slot, ItemStack stack) {
return stack.isIn(ItemTags.DYEABLE) ? DyedColorComponent.getColor(stack, -6265536) : Colors.WHITE;
}
default float getArmourAlpha(EquipmentSlot slot, ArmourLayer layer) {
return 1F;
}
default float getTrimAlpha(EquipmentSlot slot, RegistryEntry<ArmorMaterial> material, ArmorTrim trim, ArmourLayer layer) {
return 1F;
}
@Nullable
default VertexConsumer getTrimConsumer(EquipmentSlot slot, VertexConsumerProvider provider, RegistryEntry<ArmorMaterial> material, ArmorTrim trim, ArmourLayer layer) {
@Nullable RenderLayer renderLayer = getTrimLayer(slot, material, trim, layer);
if (renderLayer == null) {
return null;
}
SpriteAtlasTexture armorTrimsAtlas = MinecraftClient.getInstance().getBakedModelManager().getAtlas(TexturedRenderLayers.ARMOR_TRIMS_ATLAS_TEXTURE);
Sprite sprite = armorTrimsAtlas.getSprite(
layer == ArmourLayer.INNER ? trim.getLeggingsModelId(material) : trim.getGenericModelId(material)
);
return sprite.getTextureSpecificVertexConsumer(
provider.getBuffer(TexturedRenderLayers.getArmorTrims(trim.getPattern().value().decal()))
);
Sprite sprite = armorTrimsAtlas.getSprite(layer == ArmourLayer.INNER ? trim.getLeggingsModelId(material) : trim.getGenericModelId(material));
return sprite.getTextureSpecificVertexConsumer(provider.getBuffer(renderLayer));
}
@Nullable
default RenderLayer getTrimLayer(EquipmentSlot slot, RegistryEntry<ArmorMaterial> material, ArmorTrim trim, ArmourLayer layer) {
return TexturedRenderLayers.getArmorTrims(trim.getPattern().value().decal());
}
@Nullable
default VertexConsumer getArmourConsumer(EquipmentSlot slot, VertexConsumerProvider provider, Identifier texture, ArmourLayer layer) {
return provider.getBuffer(RenderLayer.getArmorCutoutNoCull(texture));
@Nullable RenderLayer renderLayer = getArmourLayer(slot, texture, layer);
return renderLayer == null ? null : provider.getBuffer(renderLayer);
}
@Nullable
default RenderLayer getArmourLayer(EquipmentSlot slot, Identifier texture, ArmourLayer layer) {
return RenderLayer.getArmorCutoutNoCull(texture);
}
@Nullable
default VertexConsumer getGlintConsumer(EquipmentSlot slot, VertexConsumerProvider provider, ArmourLayer layer) {
return provider.getBuffer(RenderLayer.getArmorEntityGlint());
@Nullable RenderLayer renderLayer = getGlintLayer(slot, layer);
return renderLayer == null ? null : provider.getBuffer(renderLayer);
}
@Nullable
default RenderLayer getGlintLayer(EquipmentSlot slot, ArmourLayer layer) {
return RenderLayer.getArmorEntityGlint();
}
}

View file

@ -56,36 +56,41 @@ public class ArmourFeature<T extends LivingEntity, M extends EntityModel<T> & Po
continue;
}
boolean glint = plugin.shouldRenderGlint(armorSlot, stack);
float glintAlpha = plugin.getGlintAlpha(armorSlot, stack);
boolean glint = glintAlpha > 0;
int color = plugin.getDyeColor(armorSlot, stack);
Set<PonyArmourModel<?>> models = glint ? new HashSet<>() : null;
ArmourTextureLookup textureLookup = plugin.getTextureLookup();
for (ArmorMaterial.Layer armorLayer : textureLookup.getArmorLayers(stack, color)) {
ArmourTexture layerTexture = textureLookup.getTexture(stack, layer, armorLayer);
float alpha = plugin.getArmourAlpha(armorSlot, layer);
if (layerTexture == ArmourTexture.UNKNOWN) {
continue;
}
if (alpha > 0) {
for (ArmorMaterial.Layer armorLayer : textureLookup.getArmorLayers(stack, color)) {
ArmourTexture layerTexture = textureLookup.getTexture(stack, layer, armorLayer);
var m = pony.getArmourModel(stack, layer, layerTexture.variant()).orElse(null);
if (m != null && m.poseModel(entity, limbAngle, limbDistance, age, headYaw, headPitch, armorSlot, layer, pony.body())) {
VertexConsumer armorConsumer = plugin.getArmourConsumer(armorSlot, provider, layerTexture.texture(), layer);
if (armorConsumer != null) {
float red = 1;
float green = 1;
float blue = 1;
if (armorLayer.isDyeable() && color != Colors.WHITE) {
red = Color.r(color);
green = Color.g(color);
blue = Color.b(color);
}
m.render(matrices, armorConsumer, light, OverlayTexture.DEFAULT_UV, red, green, blue, 1);
if (layerTexture == ArmourTexture.UNKNOWN) {
continue;
}
if (glint) {
models.add(m);
var m = pony.getArmourModel(stack, layer, layerTexture.variant()).orElse(null);
if (m != null && m.poseModel(entity, limbAngle, limbDistance, age, headYaw, headPitch, armorSlot, layer, pony.body())) {
VertexConsumer armorConsumer = plugin.getArmourConsumer(armorSlot, provider, layerTexture.texture(), layer);
if (armorConsumer != null) {
float red = 1;
float green = 1;
float blue = 1;
if (armorLayer.isDyeable() && color != Colors.WHITE) {
red = Color.r(color);
green = Color.g(color);
blue = Color.b(color);
}
m.render(matrices, armorConsumer, light, OverlayTexture.DEFAULT_UV, red, green, blue, alpha);
}
if (glint) {
models.add(m);
}
}
}
}
@ -93,11 +98,14 @@ public class ArmourFeature<T extends LivingEntity, M extends EntityModel<T> & Po
ArmorTrim trim = stack.get(DataComponentTypes.TRIM);
if (trim != null && stack.getItem() instanceof ArmorItem armor) {
var m = pony.getArmourModel(stack, layer, ArmourVariant.TRIM).orElse(null);
if (m != null && m.poseModel(entity, limbAngle, limbDistance, age, headYaw, headPitch, armorSlot, layer, pony.body())) {
VertexConsumer trimConsumer = plugin.getTrimConsumer(armorSlot, provider, armor.getMaterial(), trim, layer);
if (trimConsumer != null) {
m.render(matrices, trimConsumer, light, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1);
float trimAlpha = plugin.getTrimAlpha(armorSlot, armor.getMaterial(), trim, layer);
if (trimAlpha > 0) {
var m = pony.getArmourModel(stack, layer, ArmourVariant.TRIM).orElse(null);
if (m != null && m.poseModel(entity, limbAngle, limbDistance, age, headYaw, headPitch, armorSlot, layer, pony.body())) {
VertexConsumer trimConsumer = plugin.getTrimConsumer(armorSlot, provider, armor.getMaterial(), trim, layer);
if (trimConsumer != null) {
m.render(matrices, trimConsumer, light, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1);
}
}
}
}
@ -106,7 +114,7 @@ public class ArmourFeature<T extends LivingEntity, M extends EntityModel<T> & Po
VertexConsumer glintConsumer = plugin.getGlintConsumer(armorSlot, provider, layer);
if (glintConsumer != null) {
for (var m : models) {
m.render(matrices, glintConsumer, light, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1);
m.render(matrices, glintConsumer, light, OverlayTexture.DEFAULT_UV, 1, 1, 1, glintAlpha);
}
}
}