mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-22 12:37:59 +01:00
Clean up a bit and allow for setting alpha
This commit is contained in:
parent
93a895e90e
commit
0da671b699
3 changed files with 71 additions and 38 deletions
|
@ -1 +1 @@
|
|||
Subproject commit c4f3e09c933521749a7d349c39e212ffabd1b375
|
||||
Subproject commit 9932af1fa278a481fe262fbd2ed95510942b5638
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,13 +56,17 @@ 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();
|
||||
|
||||
float alpha = plugin.getArmourAlpha(armorSlot, layer);
|
||||
|
||||
if (alpha > 0) {
|
||||
for (ArmorMaterial.Layer armorLayer : textureLookup.getArmorLayers(stack, color)) {
|
||||
ArmourTexture layerTexture = textureLookup.getTexture(stack, layer, armorLayer);
|
||||
|
||||
|
@ -82,17 +86,20 @@ public class ArmourFeature<T extends LivingEntity, M extends EntityModel<T> & Po
|
|||
green = Color.g(color);
|
||||
blue = Color.b(color);
|
||||
}
|
||||
m.render(matrices, armorConsumer, light, OverlayTexture.DEFAULT_UV, red, green, blue, 1);
|
||||
m.render(matrices, armorConsumer, light, OverlayTexture.DEFAULT_UV, red, green, blue, alpha);
|
||||
}
|
||||
if (glint) {
|
||||
models.add(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ArmorTrim trim = stack.get(DataComponentTypes.TRIM);
|
||||
|
||||
if (trim != null && stack.getItem() instanceof ArmorItem armor) {
|
||||
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);
|
||||
|
@ -101,12 +108,13 @@ public class ArmourFeature<T extends LivingEntity, M extends EntityModel<T> & Po
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (glint) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue