This commit is contained in:
Sollace 2023-08-04 18:32:41 +01:00
parent f16632e5fe
commit 3dec711b78
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
4 changed files with 59 additions and 64 deletions

View file

@ -261,9 +261,8 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
}
static class HiddenStacks extends Stacks {
private static final PassThroughVertexConsumer.Parameters FIXTURE = new PassThroughVertexConsumer.Parameters().color((parent, r, g, b, a) -> {
parent.color(0, 0, 0, 0.6F);
});
private static final PassThroughVertexConsumer.Parameters FIXTURE = new PassThroughVertexConsumer.Parameters()
.color((parent, r, g, b, a) -> parent.color(0, 0, 0, 0.6F));
HiddenStacks(ItemStack stack) {
super(stack);
@ -288,7 +287,7 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
}
RenderSystem.disableDepthTest();
try {
itemRenderer.renderItem(stack, ModelTransformationMode.GUI, false, matrices, layer -> PassThroughVertexConsumer.of(immediate.getBuffer(layer), FIXTURE), 0, OverlayTexture.DEFAULT_UV, model);
itemRenderer.renderItem(stack, ModelTransformationMode.GUI, false, matrices, layer -> FIXTURE.build(immediate.getBuffer(layer)), 0, OverlayTexture.DEFAULT_UV, model);
immediate.draw();
} catch (Exception e) {
// Sodium

View file

@ -1,88 +1,57 @@
package com.minelittlepony.unicopia.client.render;
import org.jetbrains.annotations.Nullable;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumers;
public class PassThroughVertexConsumer implements VertexConsumer {
private static final ColorFix COLOR = VertexConsumer::color;
private static final FUvFix TEXTURE = VertexConsumer::texture;
private static final IUvFix OVERLAY = VertexConsumer::overlay;
private static final IUvFix LIGHT = VertexConsumer::light;
public class PassThroughVertexConsumer extends VertexConsumers.Union implements VertexConsumer {
private final Applicate<ColorFix> colorFix;
private final Applicate<FUvFix> textureFix;
private final Applicate<IUvFix> overlayFix;
private final Applicate<IUvFix> lightFix;
private final VertexConsumer parent;
private final ColorFix colorFix;
private final FUvFix textureFix;
private final IUvFix overlayFix;
private final IUvFix lightFix;
public static VertexConsumer of(VertexConsumer parent, Parameters parameters) {
return new PassThroughVertexConsumer(parent, parameters);
}
PassThroughVertexConsumer(VertexConsumer parent, Parameters parameters) {
this.parent = parent;
colorFix = parameters.colorFix;
textureFix = parameters.textureFix;
overlayFix = parameters.overlayFix;
lightFix = parameters.lightFix;
}
@Override
public VertexConsumer vertex(double x, double y, double z) {
parent.vertex(x, y, z);
return this;
private PassThroughVertexConsumer(VertexConsumer parent, Parameters parameters) {
super(new VertexConsumer[] {parent});
colorFix = Applicate.of(parameters.colorFix, (self, r, g, b, a) -> super.color(r, g, b, a));
textureFix = Applicate.of(parameters.textureFix, (self, u, v) -> super.texture(u, v));
overlayFix = Applicate.of(parameters.overlayFix, (self, u, v) -> super.overlay(u, v));
lightFix = Applicate.of(parameters.lightFix, (self, u, v) -> super.light(u, v));
}
@Override
public VertexConsumer color(int r, int g, int b, int a) {
colorFix.apply(parent, r, g, b, a);
colorFix.getFix().apply(this, r, g, b, a);
colorFix.nested = false;
return this;
}
@Override
public VertexConsumer texture(float u, float v) {
textureFix.apply(parent, u, v);
textureFix.getFix().apply(this, u, v);
textureFix.nested = false;
return this;
}
@Override
public VertexConsumer overlay(int u, int v) {
overlayFix.apply(parent, u, v);
overlayFix.getFix().apply(this, u, v);
overlayFix.nested = false;
return this;
}
@Override
public VertexConsumer light(int u, int v) {
lightFix.apply(parent, u, v);
lightFix.getFix().apply(this, u, v);
lightFix.nested = false;
return this;
}
@Override
public VertexConsumer normal(float x, float y, float z) {
parent.normal(x, y, z);
return this;
}
@Override
public void next() {
parent.next();
}
@Override
public void fixedColor(int r, int g, int b, int a) {
parent.fixedColor(r, g, b, a);
}
@Override
public void unfixColor() {
parent.unfixColor();
}
public static class Parameters {
private ColorFix colorFix = COLOR;
private FUvFix textureFix = TEXTURE;
private IUvFix overlayFix = OVERLAY;
private IUvFix lightFix = LIGHT;
private @Nullable ColorFix colorFix;
private @Nullable FUvFix textureFix;
private @Nullable IUvFix overlayFix;
private @Nullable IUvFix lightFix;
public Parameters color(ColorFix fix) {
colorFix = fix;
@ -103,6 +72,34 @@ public class PassThroughVertexConsumer implements VertexConsumer {
lightFix = fix;
return this;
}
public VertexConsumer build(VertexConsumer parent) {
return new PassThroughVertexConsumer(parent, this);
}
}
private static class Applicate<T> {
public final T fix;
public final T fallback;
public boolean nested;
public Applicate(T fix, T fallback) {
this.fix = fix;
this.fallback = fallback;
}
public T getFix() {
try {
return nested ? fallback : fix;
} finally {
nested = true;
}
}
static <T> Applicate<T> of(@Nullable T fix, T fallback) {
return new Applicate<>(fix == null ? fallback : fix, fallback);
}
}
public interface PosFix {

View file

@ -75,9 +75,7 @@ public class WorldRenderDelegate {
if (!recurseMinion && pony instanceof Creature creature && creature.isMinion()) {
recurseMinion = true;
dispatcher.render(creature.asEntity(), x, y, z, yaw, tickDelta, matrices, layer -> {
return PassThroughVertexConsumer.of(vertices.getBuffer(layer), MINION_OVERLAY);
}, light);
dispatcher.render(creature.asEntity(), x, y, z, yaw, tickDelta, matrices, layer -> MINION_OVERLAY.build(vertices.getBuffer(layer)), light);
recurseMinion = false;
return true;

View file

@ -2,6 +2,7 @@ accessWidener v1 named
accessible class net/minecraft/client/render/RenderLayer$MultiPhaseParameters
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
accessible method net/minecraft/world/GameRules register (Ljava/lang/String;Lnet/minecraft/world/GameRules$Category;Lnet/minecraft/world/GameRules$Type;)Lnet/minecraft/world/GameRules$Key;
accessible method net/minecraft/world/GameRules$BooleanRule create (Z)Lnet/minecraft/world/GameRules$Type;