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 { static class HiddenStacks extends Stacks {
private static final PassThroughVertexConsumer.Parameters FIXTURE = new PassThroughVertexConsumer.Parameters().color((parent, r, g, b, a) -> { private static final PassThroughVertexConsumer.Parameters FIXTURE = new PassThroughVertexConsumer.Parameters()
parent.color(0, 0, 0, 0.6F); .color((parent, r, g, b, a) -> parent.color(0, 0, 0, 0.6F));
});
HiddenStacks(ItemStack stack) { HiddenStacks(ItemStack stack) {
super(stack); super(stack);
@ -288,7 +287,7 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
} }
RenderSystem.disableDepthTest(); RenderSystem.disableDepthTest();
try { 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(); immediate.draw();
} catch (Exception e) { } catch (Exception e) {
// Sodium // Sodium

View file

@ -1,88 +1,57 @@
package com.minelittlepony.unicopia.client.render; package com.minelittlepony.unicopia.client.render;
import org.jetbrains.annotations.Nullable;
import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumers;
public class PassThroughVertexConsumer implements VertexConsumer { public class PassThroughVertexConsumer extends VertexConsumers.Union implements VertexConsumer {
private static final ColorFix COLOR = VertexConsumer::color; private final Applicate<ColorFix> colorFix;
private static final FUvFix TEXTURE = VertexConsumer::texture; private final Applicate<FUvFix> textureFix;
private static final IUvFix OVERLAY = VertexConsumer::overlay; private final Applicate<IUvFix> overlayFix;
private static final IUvFix LIGHT = VertexConsumer::light; private final Applicate<IUvFix> lightFix;
private final VertexConsumer parent; private PassThroughVertexConsumer(VertexConsumer parent, Parameters parameters) {
super(new VertexConsumer[] {parent});
private final ColorFix colorFix; colorFix = Applicate.of(parameters.colorFix, (self, r, g, b, a) -> super.color(r, g, b, a));
private final FUvFix textureFix; textureFix = Applicate.of(parameters.textureFix, (self, u, v) -> super.texture(u, v));
private final IUvFix overlayFix; overlayFix = Applicate.of(parameters.overlayFix, (self, u, v) -> super.overlay(u, v));
private final IUvFix lightFix; lightFix = Applicate.of(parameters.lightFix, (self, u, v) -> super.light(u, v));
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;
} }
@Override @Override
public VertexConsumer color(int r, int g, int b, int a) { 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; return this;
} }
@Override @Override
public VertexConsumer texture(float u, float v) { public VertexConsumer texture(float u, float v) {
textureFix.apply(parent, u, v); textureFix.getFix().apply(this, u, v);
textureFix.nested = false;
return this; return this;
} }
@Override @Override
public VertexConsumer overlay(int u, int v) { public VertexConsumer overlay(int u, int v) {
overlayFix.apply(parent, u, v); overlayFix.getFix().apply(this, u, v);
overlayFix.nested = false;
return this; return this;
} }
@Override @Override
public VertexConsumer light(int u, int v) { public VertexConsumer light(int u, int v) {
lightFix.apply(parent, u, v); lightFix.getFix().apply(this, u, v);
lightFix.nested = false;
return this; 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 { public static class Parameters {
private ColorFix colorFix = COLOR; private @Nullable ColorFix colorFix;
private FUvFix textureFix = TEXTURE; private @Nullable FUvFix textureFix;
private IUvFix overlayFix = OVERLAY; private @Nullable IUvFix overlayFix;
private IUvFix lightFix = LIGHT; private @Nullable IUvFix lightFix;
public Parameters color(ColorFix fix) { public Parameters color(ColorFix fix) {
colorFix = fix; colorFix = fix;
@ -103,6 +72,34 @@ public class PassThroughVertexConsumer implements VertexConsumer {
lightFix = fix; lightFix = fix;
return this; 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 { public interface PosFix {

View file

@ -75,9 +75,7 @@ public class WorldRenderDelegate {
if (!recurseMinion && pony instanceof Creature creature && creature.isMinion()) { if (!recurseMinion && pony instanceof Creature creature && creature.isMinion()) {
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 -> MINION_OVERLAY.build(vertices.getBuffer(layer)), light);
return PassThroughVertexConsumer.of(vertices.getBuffer(layer), MINION_OVERLAY);
}, light);
recurseMinion = false; recurseMinion = false;
return true; return true;

View file

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