mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-03-03 16:51:28 +01:00
Fixed hidden stack rendering on sodium
This commit is contained in:
parent
8ab8ec9de3
commit
034691a758
6 changed files with 19 additions and 179 deletions
|
@ -5,23 +5,23 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.minelittlepony.client.util.render.RenderLayerUtil;
|
||||
import com.minelittlepony.common.client.gui.*;
|
||||
import com.minelittlepony.common.client.gui.element.Button;
|
||||
import com.minelittlepony.unicopia.ability.magic.spell.crafting.SpellbookRecipe;
|
||||
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
|
||||
import com.minelittlepony.unicopia.client.gui.ItemTraitsTooltipRenderer;
|
||||
import com.minelittlepony.unicopia.client.render.PassThroughVertexConsumer;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.item.TooltipContext;
|
||||
import net.minecraft.client.render.*;
|
||||
import com.minelittlepony.unicopia.client.render.RenderLayers;
|
||||
import net.minecraft.client.render.item.ItemRenderer;
|
||||
import net.minecraft.client.render.model.json.ModelTransformationMode;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.PlayerScreenHandler;
|
||||
|
||||
class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
|
||||
private final List<IngredientTree.Entry> entries = new ArrayList<>();
|
||||
|
@ -261,9 +261,6 @@ 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));
|
||||
|
||||
HiddenStacks(ItemStack stack) {
|
||||
super(stack);
|
||||
}
|
||||
|
@ -272,8 +269,6 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
|
|||
protected void drawItem(DrawContext context, int x, int y) {
|
||||
var model = itemRenderer.getModel(stack, null, null, 0);
|
||||
|
||||
MinecraftClient.getInstance().getTextureManager().getTexture(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE).setFilter(false, false);
|
||||
RenderSystem.setShaderTexture(0, PlayerScreenHandler.BLOCK_ATLAS_TEXTURE);
|
||||
MatrixStack matrices = context.getMatrices();
|
||||
matrices.push();
|
||||
matrices.translate(x, y, 100);
|
||||
|
@ -286,12 +281,12 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
|
|||
DiffuseLighting.disableGuiDepthLighting();
|
||||
}
|
||||
RenderSystem.disableDepthTest();
|
||||
try {
|
||||
itemRenderer.renderItem(stack, ModelTransformationMode.GUI, false, matrices, layer -> FIXTURE.build(immediate.getBuffer(layer)), 0, OverlayTexture.DEFAULT_UV, model);
|
||||
itemRenderer.renderItem(stack, ModelTransformationMode.GUI, false, matrices, layer -> {
|
||||
return immediate.getBuffer(RenderLayerUtil.getTexture(layer).map(texture -> {
|
||||
return RenderLayers.getMagicColored(texture, 0x09000000);
|
||||
}).orElse(RenderLayers.getMagicColored(0x09000000)));
|
||||
}, 0, OverlayTexture.DEFAULT_UV, model);
|
||||
immediate.draw();
|
||||
} catch (Exception e) {
|
||||
// Sodium
|
||||
}
|
||||
|
||||
RenderSystem.enableDepthTest();
|
||||
if (bl) {
|
||||
|
|
|
@ -58,7 +58,7 @@ public class HornFeatureRenderer<E extends LivingEntity> implements AccessoryFea
|
|||
.filter(i -> i != -1).or(() -> pony.getSpellSlot().get(SpellPredicate.IS_NOT_PLACED, false).map(spell -> spell.getType().getColor()));
|
||||
}).ifPresent(color -> {
|
||||
model.setState(true);
|
||||
model.render(stack, ItemRenderer.getArmorGlintConsumer(renderContext, RenderLayers.getMagicColored(color), false, false), lightUv, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1);
|
||||
model.render(stack, ItemRenderer.getArmorGlintConsumer(renderContext, RenderLayers.getMagicColored((0x99 << 24) | color), false, false), lightUv, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,157 +0,0 @@
|
|||
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 extends VertexConsumers.Union implements VertexConsumer {
|
||||
private final float[] buffer = new float[8];
|
||||
|
||||
private final Applicate<ColorFix, ColorFix.VertexConsumer> colorFix;
|
||||
private final Applicate<FUvFix, FUvFix.VertexConsumer> textureFix;
|
||||
private final Applicate<IUvFix, IUvFix.VertexConsumer> overlayFix;
|
||||
|
||||
private PassThroughVertexConsumer(VertexConsumer parent, Parameters parameters) {
|
||||
super(new VertexConsumer[] {parent});
|
||||
colorFix = Applicate.of(parameters.colorFix, ColorFix.NULL, super::color, (newR, newG, newB, newA) -> {
|
||||
buffer[0] = newR / 255F;
|
||||
buffer[1] = newG / 255F;
|
||||
buffer[2] = newB / 255F;
|
||||
buffer[3] = newA / 255F;
|
||||
});
|
||||
textureFix = Applicate.of(parameters.textureFix, FUvFix.NULL, super::texture, (u, v) -> {
|
||||
buffer[4] = u;
|
||||
buffer[5] = v;
|
||||
});
|
||||
overlayFix = Applicate.of(parameters.overlayFix, IUvFix.NULL, super::overlay, (u, v) -> {
|
||||
buffer[6] = u;
|
||||
buffer[7] = v;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer color(int r, int g, int b, int a) {
|
||||
colorFix.getFix().apply(colorFix.setter, r, g, b, a);
|
||||
colorFix.nested = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer texture(float u, float v) {
|
||||
textureFix.getFix().apply(textureFix.setter, u, v);
|
||||
textureFix.nested = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer overlay(int u, int v) {
|
||||
overlayFix.getFix().apply(overlayFix.setter, u, v);
|
||||
overlayFix.nested = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void vertex(float x, float y, float z, float red, float green, float blue, float alpha, float u, float v, int overlay, int light, float normalX, float normalY, float normalZ) {
|
||||
colorFix.getFix().apply(colorFix.collector, (int)(red * 255), (int)(green * 255F), (int)(blue * 255), (int)(alpha * 255));
|
||||
colorFix.nested = false;
|
||||
textureFix.getFix().apply(textureFix.collector, u, v);
|
||||
textureFix.nested = false;
|
||||
overlayFix.getFix().apply(overlayFix.collector, overlay & 0xFFFF, overlay >> 16 & 0xFFFF);
|
||||
overlayFix.nested = false;
|
||||
super.vertex(x, y, z, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], (int)buffer[6] | (int)buffer[7] << 16, light, normalX, normalY, normalZ);
|
||||
}
|
||||
|
||||
public static class Parameters {
|
||||
private @Nullable ColorFix colorFix;
|
||||
private @Nullable FUvFix textureFix;
|
||||
private @Nullable IUvFix overlayFix;
|
||||
|
||||
public Parameters color(ColorFix fix) {
|
||||
colorFix = fix;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Parameters texture(FUvFix fix) {
|
||||
textureFix = fix;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Parameters overlay(IUvFix fix) {
|
||||
overlayFix = fix;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VertexConsumer build(VertexConsumer parent) {
|
||||
return new PassThroughVertexConsumer(parent, this);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Applicate<T extends Applicate.Applicatable<V>, V> {
|
||||
public final T fix;
|
||||
public final T fallback;
|
||||
public final V setter;
|
||||
public final V collector;
|
||||
|
||||
public boolean nested;
|
||||
|
||||
public Applicate(T fix, T fallback, V setter, V collector) {
|
||||
this.fix = fix;
|
||||
this.fallback = fallback;
|
||||
this.setter = setter;
|
||||
this.collector = collector;
|
||||
}
|
||||
|
||||
public T getFix() {
|
||||
try {
|
||||
return nested ? fallback : fix;
|
||||
} finally {
|
||||
nested = true;
|
||||
}
|
||||
}
|
||||
|
||||
static <T extends Applicate.Applicatable<V>, V> Applicate<T, V> of(@Nullable T fix, T fallback, V setter, V collector) {
|
||||
return new Applicate<>(fix == null ? fallback : fix, fallback, setter, collector);
|
||||
}
|
||||
|
||||
interface Applicatable<T> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public interface PosFix extends Applicate.Applicatable<PosFix.VertexConsumer> {
|
||||
void apply(VertexConsumer consumer, float x, float y, float z);
|
||||
|
||||
public interface VertexConsumer {
|
||||
void vertex(float x, float y, float z);
|
||||
}
|
||||
}
|
||||
public interface ColorFix extends Applicate.Applicatable<ColorFix.VertexConsumer> {
|
||||
ColorFix NULL = (self, r, g, b, a) -> self.color(r, g, b, a);
|
||||
void apply(VertexConsumer consumer, int r, int g, int b, int a);
|
||||
|
||||
public interface VertexConsumer {
|
||||
void color(int r, int g, int b, int a);
|
||||
|
||||
default void color(float r, float g, float b, float a) {
|
||||
color((int)(r * 255), (int)(g * 255), (int)(b * 255), (int)(a * 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
public interface FUvFix extends Applicate.Applicatable<FUvFix.VertexConsumer> {
|
||||
FUvFix NULL = (self, u, v) -> self.uv(u, v);
|
||||
void apply(VertexConsumer consumer, float u, float v);
|
||||
|
||||
public interface VertexConsumer {
|
||||
void uv(float u, float v);
|
||||
}
|
||||
}
|
||||
public interface IUvFix extends Applicate.Applicatable<IUvFix.VertexConsumer> {
|
||||
IUvFix NULL = (self, u, v) -> self.uv(u, v);
|
||||
void apply(VertexConsumer consumer, int u, int v);
|
||||
|
||||
public interface VertexConsumer {
|
||||
void uv(int u, int v);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -33,11 +33,10 @@ public final class RenderLayers extends RenderLayer {
|
|||
.transparency(TRANSLUCENT_TRANSPARENCY)
|
||||
.layering(VIEW_OFFSET_Z_LAYERING)
|
||||
// .target(TRANSLUCENT_TARGET)
|
||||
.texturing(solid(Color.r(color), Color.g(color), Color.b(color), 0.6F))
|
||||
.texturing(solid(color))
|
||||
.build(false));
|
||||
});
|
||||
private static final RenderLayer MAGIC_COLORED = getMagicColored(Color.argbToHex(1, 0.8F, 0.9F, 1));
|
||||
|
||||
private static final RenderLayer MAGIC_COLORED = getMagicColored(Color.argbToHex(0.6F, 0.8F, 0.9F, 1));
|
||||
|
||||
private static final BiFunction<Identifier, Integer, RenderLayer> MAGIC_TINT_FUNC = Util.memoize((texture, color) -> {
|
||||
return of("magic_tint_" + color,
|
||||
|
@ -69,7 +68,11 @@ public final class RenderLayers extends RenderLayer {
|
|||
return MAGIC_TINT_FUNC.apply(texture, color);
|
||||
}
|
||||
|
||||
private static Texturing solid(float r, float g, float b, float a) {
|
||||
private static Texturing solid(int color) {
|
||||
final float r = Color.r(color);
|
||||
final float g = Color.g(color);
|
||||
final float b = Color.b(color);
|
||||
final float a = Color.a(color);
|
||||
return new Texturing("solid", () -> {
|
||||
RenderSystem.setShaderColor(r, g, b, a);
|
||||
}, () -> {
|
||||
|
@ -77,7 +80,6 @@ public final class RenderLayers extends RenderLayer {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
private static class Colored extends Texture {
|
||||
|
||||
private final float red;
|
||||
|
@ -90,7 +92,7 @@ public final class RenderLayers extends RenderLayer {
|
|||
this.red = Color.r(color);
|
||||
this.green = Color.g(color);
|
||||
this.blue = Color.b(color);
|
||||
this.alpha = 0.8F;
|
||||
this.alpha = Color.a(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -76,7 +76,7 @@ public class WorldRenderDelegate {
|
|||
var buffer = vertices.getBuffer(layer);
|
||||
return RenderLayerUtil.getTexture(layer).map(texture -> {
|
||||
return VertexConsumers.union(
|
||||
vertices.getBuffer(RenderLayers.getMagicColored(texture, creature.isDiscorded() ? 0xFF0000 : 0x0000FF)),
|
||||
vertices.getBuffer(RenderLayers.getMagicColored(texture, creature.isDiscorded() ? 0xCCFF0000 : 0xCC0000FF)),
|
||||
vertices.getBuffer(layer)
|
||||
);
|
||||
}).orElse(buffer);
|
||||
|
|
|
@ -58,7 +58,7 @@ public class MagicBeamEntityRenderer extends EntityRenderer<MagicProjectileEntit
|
|||
);
|
||||
|
||||
RenderLayer layer = entity.getSpellSlot().get(true)
|
||||
.map(spell -> spell.getType().getColor())
|
||||
.map(spell -> (0x99 << 24) | spell.getType().getColor())
|
||||
.map(RenderLayers::getMagicColored)
|
||||
.orElseGet(RenderLayers::getMagicColored);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue