Fixed tint for overlay for faithful entities not rendering

This commit is contained in:
Sollace 2023-08-05 20:47:24 +01:00
parent c6e94d758b
commit 82daf178df
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
4 changed files with 94 additions and 10 deletions

View file

@ -0,0 +1,14 @@
package com.minelittlepony.unicopia.client.render;
import java.util.Optional;
import net.minecraft.client.render.*;
import net.minecraft.util.Identifier;
public interface RenderLayerUtil {
static Optional<Identifier> getTexture(RenderLayer layer) {
if (layer instanceof RenderLayer.MultiPhase multiphase) {
return multiphase.getPhases().texture.getId();
}
return Optional.empty();
}
}

View file

@ -1,5 +1,6 @@
package com.minelittlepony.unicopia.client.render; package com.minelittlepony.unicopia.client.render;
import java.util.function.BiFunction;
import java.util.function.Function; import java.util.function.Function;
import com.minelittlepony.common.util.Color; import com.minelittlepony.common.util.Color;
@ -8,6 +9,7 @@ import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats; import net.minecraft.client.render.VertexFormats;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util; import net.minecraft.util.Util;
public final class RenderLayers extends RenderLayer { public final class RenderLayers extends RenderLayer {
@ -29,12 +31,28 @@ public final class RenderLayers extends RenderLayer {
MultiPhaseParameters.builder() MultiPhaseParameters.builder()
.program(COLOR_PROGRAM) .program(COLOR_PROGRAM)
.transparency(TRANSLUCENT_TRANSPARENCY) .transparency(TRANSLUCENT_TRANSPARENCY)
.layering(VIEW_OFFSET_Z_LAYERING)
// .target(TRANSLUCENT_TARGET) // .target(TRANSLUCENT_TARGET)
.texturing(solid(Color.r(color), Color.g(color), Color.b(color), 0.6F)) .texturing(solid(Color.r(color), Color.g(color), Color.b(color), 0.6F))
.build(false)); .build(false));
}); });
private static final RenderLayer MAGIC_COLORED = getMagicColored(Color.argbToHex(1, 0.8F, 0.9F, 1)); private static final RenderLayer MAGIC_COLORED = getMagicColored(Color.argbToHex(1, 0.8F, 0.9F, 1));
private static final BiFunction<Identifier, Integer, RenderLayer> MAGIC_TINT_FUNC = Util.memoize((texture, color) -> {
return of("magic_tint_" + color,
VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL,
VertexFormat.DrawMode.QUADS, 256, true, true,
MultiPhaseParameters.builder()
.texture(new Colored(texture, color))
.program(EYES_PROGRAM)
.writeMaskState(COLOR_MASK)
.transparency(TRANSLUCENT_TRANSPARENCY)
.layering(VIEW_OFFSET_Z_LAYERING)
.cull(DISABLE_CULLING)
.build(false));
});
public static RenderLayer getMagicNoColor() { public static RenderLayer getMagicNoColor() {
return MAGIC_NO_COLOR; return MAGIC_NO_COLOR;
} }
@ -47,6 +65,10 @@ public final class RenderLayers extends RenderLayer {
return MAGIC_COLORIN_FUNC.apply(color); return MAGIC_COLORIN_FUNC.apply(color);
} }
public static RenderLayer getMagicColored(Identifier texture, int color) {
return MAGIC_TINT_FUNC.apply(texture, color);
}
private static Texturing solid(float r, float g, float b, float a) { private static Texturing solid(float r, float g, float b, float a) {
return new Texturing("solid", () -> { return new Texturing("solid", () -> {
RenderSystem.setShaderColor(r, g, b, a); RenderSystem.setShaderColor(r, g, b, a);
@ -54,4 +76,42 @@ public final class RenderLayers extends RenderLayer {
RenderSystem.setShaderColor(1, 1, 1, 1); RenderSystem.setShaderColor(1, 1, 1, 1);
}); });
} }
private static class Colored extends Texture {
private final float red;
private final float green;
private final float blue;
private final float alpha;
public Colored(Identifier texture, int color) {
super(texture, false, false);
this.red = Color.r(color);
this.green = Color.g(color);
this.blue = Color.b(color);
this.alpha = 0.8F;
}
@Override
public void startDrawing() {
RenderSystem.setShaderColor(red, green, blue, alpha);
super.startDrawing();
}
@Override
public void endDrawing() {
super.endDrawing();
RenderSystem.setShaderColor(1, 1, 1, 1);
}
@Override
public boolean equals(Object other) {
return super.equals(other)
&& ((Colored)other).red == red
&& ((Colored)other).green == green
&& ((Colored)other).blue == blue
&& ((Colored)other).alpha == alpha;
}
}
} }

View file

@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.client.render;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.minelittlepony.client.util.render.RenderLayerUtil;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.ability.magic.SpellPredicate; import com.minelittlepony.unicopia.ability.magic.SpellPredicate;
@ -35,9 +36,6 @@ import net.minecraft.util.math.*;
public class WorldRenderDelegate { public class WorldRenderDelegate {
public static final WorldRenderDelegate INSTANCE = new WorldRenderDelegate(); public static final WorldRenderDelegate INSTANCE = new WorldRenderDelegate();
private static final PassThroughVertexConsumer.Parameters MINION_OVERLAY = new PassThroughVertexConsumer.Parameters()
.color((parent, r, g, b, a) -> parent.color((float)Math.random(), 0.6F, 1, a / 255F));
private boolean recurseMinion; private boolean recurseMinion;
private boolean recurseFrosting; private boolean recurseFrosting;
@ -50,13 +48,13 @@ public class WorldRenderDelegate {
if (MinecraftClient.getInstance().getResourceManager().getResource(frostingTexture).isPresent()) { if (MinecraftClient.getInstance().getResourceManager().getResource(frostingTexture).isPresent()) {
recurseFrosting = true; recurseFrosting = true;
//dispatcher.render(entity, x, y, z, yaw, tickDelta, matrices, vertices, light);
dispatcher.render(entity, x, y, z, yaw, tickDelta, matrices, vertices, light);
dispatcher.setRenderShadows(false);
dispatcher.render(entity, x, y, z, yaw, tickDelta, matrices, layer -> { dispatcher.render(entity, x, y, z, yaw, tickDelta, matrices, layer -> {
return vertices.getBuffer(RenderLayers.getEntityTranslucent(frostingTexture)); if (RenderLayerUtil.getTexture(layer).orElse(null) == null) {
return vertices.getBuffer(layer);
}
return VertexConsumers.union(vertices.getBuffer(layer), vertices.getBuffer(RenderLayers.getEntityTranslucent(frostingTexture)));
}, light); }, light);
dispatcher.setRenderShadows(true);
recurseFrosting = false; recurseFrosting = false;
return true; return true;
} }
@ -77,7 +75,14 @@ public class WorldRenderDelegate {
try { try {
recurseMinion = true; recurseMinion = true;
dispatcher.render(creature.asEntity(), x, y, z, yaw, tickDelta, matrices, layer -> { dispatcher.render(creature.asEntity(), x, y, z, yaw, tickDelta, matrices, layer -> {
return MINION_OVERLAY.build(vertices.getBuffer(layer)); var buffer = vertices.getBuffer(layer);
return RenderLayerUtil.getTexture(layer).map(texture -> {
return VertexConsumers.union(
vertices.getBuffer(RenderLayers.getMagicColored(texture, 0x0000FF)),
vertices.getBuffer(layer)
);
}).orElse(buffer);
//return MINION_OVERLAY.build(vertices.getBuffer(layer));
}, light); }, light);
} finally { } finally {
recurseMinion = false; recurseMinion = false;

View file

@ -1,5 +1,6 @@
accessWidener v1 named accessWidener v1 named
accessible class net/minecraft/client/render/RenderLayer$MultiPhaseParameters accessible class net/minecraft/client/render/RenderLayer$MultiPhaseParameters
accessible class net/minecraft/client/render/RenderPhase$TextureBase
accessible method net/minecraft/client/render/RenderLayer of (Ljava/lang/String;Lnet/minecraft/client/render/VertexFormat;Lnet/minecraft/client/render/VertexFormat$DrawMode;IZZLnet/minecraft/client/render/RenderLayer$MultiPhaseParameters;)Lnet/minecraft/client/render/RenderLayer$MultiPhase; accessible method net/minecraft/client/render/RenderLayer of (Ljava/lang/String;Lnet/minecraft/client/render/VertexFormat;Lnet/minecraft/client/render/VertexFormat$DrawMode;IZZLnet/minecraft/client/render/RenderLayer$MultiPhaseParameters;)Lnet/minecraft/client/render/RenderLayer$MultiPhase;
accessible class net/minecraft/client/render/item/HeldItemRenderer$HandRenderType accessible class net/minecraft/client/render/item/HeldItemRenderer$HandRenderType
accessible class net/minecraft/client/render/VertexConsumers$Union accessible class net/minecraft/client/render/VertexConsumers$Union
@ -10,4 +11,8 @@ accessible method net/minecraft/world/GameRules$IntRule create
accessible method net/minecraft/world/gen/foliage/FoliagePlacerType <init> (Lcom/mojang/serialization/Codec;)V accessible method net/minecraft/world/gen/foliage/FoliagePlacerType <init> (Lcom/mojang/serialization/Codec;)V
accessible field net/minecraft/entity/mob/CreeperEntity CHARGED Lnet/minecraft/entity/data/TrackedData; accessible field net/minecraft/entity/mob/CreeperEntity CHARGED Lnet/minecraft/entity/data/TrackedData;
accessible field net/minecraft/entity/mob/CreeperEntity IGNITED Lnet/minecraft/entity/data/TrackedData; accessible field net/minecraft/entity/mob/CreeperEntity IGNITED Lnet/minecraft/entity/data/TrackedData;
accessible method net/minecraft/client/render/RenderLayer$MultiPhase getPhases ()Lnet/minecraft/client/render/RenderLayer$MultiPhaseParameters;
accessible method net/minecraft/client/render/RenderPhase$TextureBase getId ()Ljava/util/Optional;
accessible field net/minecraft/client/render/RenderLayer$MultiPhaseParameters texture Lnet/minecraft/client/render/RenderPhase$TextureBase;