From 24e220bb29a01e60e4e05ff7e509ba35f395b01a Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 27 Sep 2023 12:11:20 +0100 Subject: [PATCH] Allow armor to render with translucency --- .../client/render/ArmorRenderLayers.java | 33 +++++++++++++++++++ .../client/render/MagicGlow.java | 5 ++- .../render/entity/feature/ArmourFeature.java | 7 ++-- 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/minelittlepony/client/render/ArmorRenderLayers.java diff --git a/src/main/java/com/minelittlepony/client/render/ArmorRenderLayers.java b/src/main/java/com/minelittlepony/client/render/ArmorRenderLayers.java new file mode 100644 index 00000000..261732a3 --- /dev/null +++ b/src/main/java/com/minelittlepony/client/render/ArmorRenderLayers.java @@ -0,0 +1,33 @@ +package com.minelittlepony.client.render; + +import net.minecraft.client.render.*; +import net.minecraft.client.render.RenderLayer.MultiPhaseParameters; +import net.minecraft.util.Identifier; +import net.minecraft.util.Util; + +import java.util.function.BiFunction; + +public class ArmorRenderLayers extends RenderPhase { + private ArmorRenderLayers() { + super(null, null, null); + } + + private static final BiFunction ARMOR_TRANSLUCENT_NO_CULL = Util.memoize((texture, decal) -> { + return RenderLayer.of(decal ? "armor_decal_translucent_no_cull" : "armor_translucent_no_cull", + VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL, VertexFormat.DrawMode.QUADS, 256, true, false, MultiPhaseParameters.builder() + .program(ARMOR_CUTOUT_NO_CULL_PROGRAM) + .texture(new RenderPhase.Texture(texture, false, false)) + .transparency(TRANSLUCENT_TRANSPARENCY) + .cull(DISABLE_CULLING) + .lightmap(ENABLE_LIGHTMAP) + .overlay(ENABLE_OVERLAY_COLOR) + .layering(VIEW_OFFSET_Z_LAYERING) + .depthTest(decal ? EQUAL_DEPTH_TEST : LEQUAL_DEPTH_TEST) + .build(true) + ); + }); + + public static RenderLayer getArmorTranslucentNoCull(Identifier texture, boolean decal) { + return ARMOR_TRANSLUCENT_NO_CULL.apply(texture, decal); + } +} diff --git a/src/main/java/com/minelittlepony/client/render/MagicGlow.java b/src/main/java/com/minelittlepony/client/render/MagicGlow.java index 4c868829..fc40525f 100644 --- a/src/main/java/com/minelittlepony/client/render/MagicGlow.java +++ b/src/main/java/com/minelittlepony/client/render/MagicGlow.java @@ -16,8 +16,8 @@ import java.util.function.BiFunction; import java.util.function.Supplier; public abstract class MagicGlow extends RenderPhase { - private MagicGlow(String name, Runnable beginAction, Runnable endAction) { - super(name, beginAction, endAction); + private MagicGlow() { + super(null, null, null); } private static final Supplier MAGIC = Suppliers.memoize(() -> { @@ -54,7 +54,6 @@ public abstract class MagicGlow extends RenderPhase { } private static class Colored extends Texture { - private final float red; private final float green; private final float blue; 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 212e9cf0..5c45739a 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 @@ -97,7 +97,7 @@ public class ArmourFeature & IP } private static VertexConsumer getArmorConsumer(VertexConsumerProvider provider, Identifier texture, boolean glint) { - return ItemRenderer.getArmorGlintConsumer(provider, RenderLayer.getArmorCutoutNoCull(texture), false, glint); + return ItemRenderer.getArmorGlintConsumer(provider, ArmorRenderLayers.getArmorTranslucentNoCull(texture, false), false, glint); } private static VertexConsumer getTrimConsumer(VertexConsumerProvider provider, ArmorMaterial material, ArmorTrim trim, ArmourLayer layer, boolean glint) { @@ -105,9 +105,8 @@ public class ArmourFeature & IP Sprite sprite = armorTrimsAtlas.getSprite( layer == ArmourLayer.INNER ? trim.getLeggingsModelId(material) : trim.getGenericModelId(material) ); + RenderLayer renderLayer = ArmorRenderLayers.getArmorTranslucentNoCull(TexturedRenderLayers.ARMOR_TRIMS_ATLAS_TEXTURE, trim.getPattern().value().decal()); - return sprite.getTextureSpecificVertexConsumer( - ItemRenderer.getDirectItemGlintConsumer(provider, TexturedRenderLayers.getArmorTrims(), true, glint) - ); + return sprite.getTextureSpecificVertexConsumer(ItemRenderer.getDirectItemGlintConsumer(provider, renderLayer, true, glint)); } }