mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Fixed overlay on summoned minions not rendering correctly and make it shift through different colours
This commit is contained in:
parent
53f7e34e59
commit
1c878be324
3 changed files with 49 additions and 31 deletions
|
@ -1,14 +1,38 @@
|
|||
package com.minelittlepony.unicopia.client.render;
|
||||
|
||||
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.VertexConsumerProvider.Immediate;
|
||||
import net.minecraft.screen.PlayerScreenHandler;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public interface RenderLayerUtil {
|
||||
Identifier SHADOW_TEXTURE = new Identifier("textures/misc/shadow.png");
|
||||
|
||||
static Optional<Identifier> getTexture(RenderLayer layer) {
|
||||
if (layer instanceof RenderLayer.MultiPhase multiphase) {
|
||||
return multiphase.getPhases().texture.getId();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package com.minelittlepony.unicopia.client.render;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.minelittlepony.client.util.render.RenderLayerUtil;
|
||||
import com.minelittlepony.unicopia.EquinePredicates;
|
||||
import com.minelittlepony.unicopia.Race;
|
||||
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.duck.LavaAffine;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.util.ColorHelper;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
@ -24,14 +23,13 @@ import net.minecraft.client.util.math.MatrixStack;
|
|||
import net.minecraft.entity.*;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.vehicle.BoatEntity;
|
||||
import net.minecraft.screen.PlayerScreenHandler;
|
||||
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 static final WorldRenderDelegate INSTANCE = new WorldRenderDelegate();
|
||||
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 EntityDisguiseRenderer disguiseRenderer = new EntityDisguiseRenderer(this);
|
||||
|
@ -72,23 +70,10 @@ public class WorldRenderDelegate {
|
|||
|
||||
if (MinecraftClient.getInstance().getResourceManager().getResource(frostingTexture).isPresent()) {
|
||||
recurseFrosting = true;
|
||||
|
||||
Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEffectVertexConsumers();
|
||||
|
||||
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);
|
||||
RenderLayerUtil.createUnionBuffer(c -> {
|
||||
client.getEntityRenderDispatcher().render(entity, x, y, z, yaw, tickDelta, matrices, c, light);
|
||||
}, vertices, texture -> RenderLayers.getEntityTranslucent(frostingTexture));
|
||||
recurseFrosting = false;
|
||||
immediate.draw();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -146,16 +131,9 @@ public class WorldRenderDelegate {
|
|||
if (!recurseMinion && pony instanceof Creature creature && creature.isMinion()) {
|
||||
try {
|
||||
recurseMinion = true;
|
||||
client.getEntityRenderDispatcher().render(creature.asEntity(), x, y, z, yaw, tickDelta, matrices, layer -> {
|
||||
return RenderLayerUtil.getTexture(layer)
|
||||
.filter(texture -> texture != PlayerScreenHandler.BLOCK_ATLAS_TEXTURE)
|
||||
.map(texture -> {
|
||||
return VertexConsumers.union(
|
||||
vertices.getBuffer(layer),
|
||||
vertices.getBuffer(RenderLayers.getMagicColored(texture, creature.isDiscorded() ? 0xCCFF0000 : 0xCC0000FF))
|
||||
);
|
||||
}).orElseGet(() -> vertices.getBuffer(layer));
|
||||
}, light);
|
||||
RenderLayerUtil.createUnionBuffer(c -> {
|
||||
client.getEntityRenderDispatcher().render(creature.asEntity(), x, y, z, yaw, tickDelta, matrices, c, light);
|
||||
}, vertices, texture -> RenderLayers.getMagicColored(texture, creature.isDiscorded() ? 0x33FF0000 : ColorHelper.getRainbowColor(creature.asEntity(), 25, 1) )); // 0x8800AA00
|
||||
return true;
|
||||
} catch (Throwable t) {
|
||||
Unicopia.LOGGER.error("Error whilst rendering minion", t);
|
||||
|
|
|
@ -2,9 +2,25 @@ package com.minelittlepony.unicopia.util;
|
|||
|
||||
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;
|
||||
|
||||
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) {
|
||||
float avg = (red + green + blue) / 3F;
|
||||
|
|
Loading…
Reference in a new issue