mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Fixed tint for overlay for faithful entities not rendering
This commit is contained in:
parent
c6e94d758b
commit
82daf178df
4 changed files with 94 additions and 10 deletions
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.minelittlepony.unicopia.client.render;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
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.VertexFormat;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Util;
|
||||
|
||||
public final class RenderLayers extends RenderLayer {
|
||||
|
@ -29,12 +31,28 @@ public final class RenderLayers extends RenderLayer {
|
|||
MultiPhaseParameters.builder()
|
||||
.program(COLOR_PROGRAM)
|
||||
.transparency(TRANSLUCENT_TRANSPARENCY)
|
||||
.layering(VIEW_OFFSET_Z_LAYERING)
|
||||
// .target(TRANSLUCENT_TARGET)
|
||||
.texturing(solid(Color.r(color), Color.g(color), Color.b(color), 0.6F))
|
||||
.build(false));
|
||||
});
|
||||
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() {
|
||||
return MAGIC_NO_COLOR;
|
||||
}
|
||||
|
@ -47,6 +65,10 @@ public final class RenderLayers extends RenderLayer {
|
|||
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) {
|
||||
return new Texturing("solid", () -> {
|
||||
RenderSystem.setShaderColor(r, g, b, a);
|
||||
|
@ -54,4 +76,42 @@ public final class RenderLayers extends RenderLayer {
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.client.render;
|
|||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.minelittlepony.client.util.render.RenderLayerUtil;
|
||||
import com.minelittlepony.unicopia.Unicopia;
|
||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||
import com.minelittlepony.unicopia.ability.magic.SpellPredicate;
|
||||
|
@ -35,9 +36,6 @@ import net.minecraft.util.math.*;
|
|||
public class 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 recurseFrosting;
|
||||
|
||||
|
@ -50,13 +48,13 @@ public class WorldRenderDelegate {
|
|||
|
||||
if (MinecraftClient.getInstance().getResourceManager().getResource(frostingTexture).isPresent()) {
|
||||
recurseFrosting = true;
|
||||
|
||||
dispatcher.render(entity, x, y, z, yaw, tickDelta, matrices, vertices, light);
|
||||
dispatcher.setRenderShadows(false);
|
||||
//dispatcher.render(entity, x, y, z, yaw, tickDelta, matrices, vertices, light);
|
||||
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);
|
||||
dispatcher.setRenderShadows(true);
|
||||
recurseFrosting = false;
|
||||
return true;
|
||||
}
|
||||
|
@ -77,7 +75,14 @@ public class WorldRenderDelegate {
|
|||
try {
|
||||
recurseMinion = true;
|
||||
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);
|
||||
} finally {
|
||||
recurseMinion = false;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
accessWidener v1 named
|
||||
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 class net/minecraft/client/render/item/HeldItemRenderer$HandRenderType
|
||||
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 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;
|
||||
|
|
Loading…
Reference in a new issue