Fixed overlay on summoned minions not rendering correctly and make it shift through different colours

This commit is contained in:
Sollace 2024-03-12 14:52:48 +00:00
parent 53f7e34e59
commit 1c878be324
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 49 additions and 31 deletions

View file

@ -1,14 +1,38 @@
package com.minelittlepony.unicopia.client.render; package com.minelittlepony.unicopia.client.render;
import java.util.Optional; import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.*; import net.minecraft.client.render.*;
import net.minecraft.client.render.VertexConsumerProvider.Immediate;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public interface RenderLayerUtil { public interface RenderLayerUtil {
Identifier SHADOW_TEXTURE = new Identifier("textures/misc/shadow.png");
static Optional<Identifier> getTexture(RenderLayer layer) { static Optional<Identifier> getTexture(RenderLayer layer) {
if (layer instanceof RenderLayer.MultiPhase multiphase) { if (layer instanceof RenderLayer.MultiPhase multiphase) {
return multiphase.getPhases().texture.getId(); return multiphase.getPhases().texture.getId();
} }
return Optional.empty(); return Optional.empty();
} }
static void createUnionBuffer(Consumer<VertexConsumerProvider> action, VertexConsumerProvider vertices, Function<Identifier, RenderLayer> overlayFunction) {
Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEffectVertexConsumers();
action.accept(layer -> {
Identifier texture = RenderLayerUtil.getTexture(layer).orElse(null);
if (texture == null || texture.equals(SHADOW_TEXTURE) || texture.equals(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE)) {
return vertices.getBuffer(layer);
}
return VertexConsumers.union(
vertices.getBuffer(layer),
immediate.getBuffer(overlayFunction.apply(texture))
);
});
immediate.draw();
}
} }

View file

@ -1,8 +1,6 @@
package com.minelittlepony.unicopia.client.render; package com.minelittlepony.unicopia.client.render;
import java.util.Optional; import java.util.Optional;
import com.minelittlepony.client.util.render.RenderLayerUtil;
import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.EquinePredicates;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
@ -14,6 +12,7 @@ import com.minelittlepony.unicopia.entity.ItemImpl;
import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.duck.LavaAffine; import com.minelittlepony.unicopia.entity.duck.LavaAffine;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.ColorHelper;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
@ -24,14 +23,13 @@ import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.*; import net.minecraft.entity.*;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.vehicle.BoatEntity; import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.*; import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
public class WorldRenderDelegate { public class WorldRenderDelegate {
public static final WorldRenderDelegate INSTANCE = new WorldRenderDelegate(); public static final WorldRenderDelegate INSTANCE = new WorldRenderDelegate();
private static final Optional<Vec3d> RED_SKY_COLOR = Optional.of(new Vec3d(1, 0, 0)); private static final Optional<Vec3d> RED_SKY_COLOR = Optional.of(new Vec3d(1, 0, 0));
private static final Identifier SHADOW_TEXTURE = new Identifier("textures/misc/shadow.png");
private final EntityReplacementManager disguiseLookup = new EntityReplacementManager(); private final EntityReplacementManager disguiseLookup = new EntityReplacementManager();
private final EntityDisguiseRenderer disguiseRenderer = new EntityDisguiseRenderer(this); private final EntityDisguiseRenderer disguiseRenderer = new EntityDisguiseRenderer(this);
@ -72,23 +70,10 @@ public class WorldRenderDelegate {
if (MinecraftClient.getInstance().getResourceManager().getResource(frostingTexture).isPresent()) { if (MinecraftClient.getInstance().getResourceManager().getResource(frostingTexture).isPresent()) {
recurseFrosting = true; recurseFrosting = true;
RenderLayerUtil.createUnionBuffer(c -> {
Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEffectVertexConsumers(); client.getEntityRenderDispatcher().render(entity, x, y, z, yaw, tickDelta, matrices, c, light);
}, vertices, texture -> RenderLayers.getEntityTranslucent(frostingTexture));
client.getEntityRenderDispatcher().render(entity, x, y, z, yaw, tickDelta, matrices, layer -> {
Identifier texture = RenderLayerUtil.getTexture(layer).orElse(null);
if (texture == null || texture.equals(SHADOW_TEXTURE)) {
return vertices.getBuffer(layer);
}
return VertexConsumers.union(
vertices.getBuffer(layer),
immediate.getBuffer(RenderLayers.getEntityTranslucent(frostingTexture))
);
}, light);
recurseFrosting = false; recurseFrosting = false;
immediate.draw();
return true; return true;
} }
} }
@ -146,16 +131,9 @@ public class WorldRenderDelegate {
if (!recurseMinion && pony instanceof Creature creature && creature.isMinion()) { if (!recurseMinion && pony instanceof Creature creature && creature.isMinion()) {
try { try {
recurseMinion = true; recurseMinion = true;
client.getEntityRenderDispatcher().render(creature.asEntity(), x, y, z, yaw, tickDelta, matrices, layer -> { RenderLayerUtil.createUnionBuffer(c -> {
return RenderLayerUtil.getTexture(layer) client.getEntityRenderDispatcher().render(creature.asEntity(), x, y, z, yaw, tickDelta, matrices, c, light);
.filter(texture -> texture != PlayerScreenHandler.BLOCK_ATLAS_TEXTURE) }, vertices, texture -> RenderLayers.getMagicColored(texture, creature.isDiscorded() ? 0x33FF0000 : ColorHelper.getRainbowColor(creature.asEntity(), 25, 1) )); // 0x8800AA00
.map(texture -> {
return VertexConsumers.union(
vertices.getBuffer(layer),
vertices.getBuffer(RenderLayers.getMagicColored(texture, creature.isDiscorded() ? 0xCCFF0000 : 0xCC0000FF))
);
}).orElseGet(() -> vertices.getBuffer(layer));
}, light);
return true; return true;
} catch (Throwable t) { } catch (Throwable t) {
Unicopia.LOGGER.error("Error whilst rendering minion", t); Unicopia.LOGGER.error("Error whilst rendering minion", t);

View file

@ -2,9 +2,25 @@ package com.minelittlepony.unicopia.util;
import com.minelittlepony.common.util.Color; import com.minelittlepony.common.util.Color;
import net.minecraft.entity.Entity;
import net.minecraft.entity.passive.SheepEntity;
import net.minecraft.util.DyeColor;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
public interface ColorHelper { public interface ColorHelper {
static int getRainbowColor(Entity entity, int speed, float tickDelta) {
int n = entity.age / speed + entity.getId();
int o = DyeColor.values().length;
int p = n % o;
int q = (n + 1) % o;
float r = (entity.age % speed + tickDelta) / 25.0f;
float[] fs = SheepEntity.getRgbColor(DyeColor.byId(p));
float[] gs = SheepEntity.getRgbColor(DyeColor.byId(q));
float s = fs[0] * (1.0f - r) + gs[0] * r;
float t = fs[1] * (1.0f - r) + gs[1] * r;
float u = fs[2] * (1.0f - r) + gs[2] * r;
return Color.argbToHex(1, s, t, u);
}
static float[] changeSaturation(float red, float green, float blue, float intensity) { static float[] changeSaturation(float red, float green, float blue, float intensity) {
float avg = (red + green + blue) / 3F; float avg = (red + green + blue) / 3F;