Vanillinization

- Move all text visual related things into vanillin
This commit is contained in:
Jozufozu 2025-01-20 13:58:51 -06:00
parent 6003748f0e
commit 6d2aab7716
28 changed files with 126 additions and 104 deletions

View file

@ -103,27 +103,6 @@ public final class InstanceTypes {
.cullShader(Flywheel.rl("instance/cull/shadow.glsl"))
.build();
public static final InstanceType<GlyphInstance> GLYPH = SimpleInstanceType.builder(GlyphInstance::new)
.layout(LayoutBuilder.create()
.matrix("pose", FloatRepr.FLOAT, 4)
.vector("u0u1v0v1", FloatRepr.NORMALIZED_UNSIGNED_SHORT, 4)
.vector("color", FloatRepr.NORMALIZED_UNSIGNED_BYTE, 4)
.vector("light", FloatRepr.UNSIGNED_SHORT, 2)
.build())
.writer((ptr, instance) -> {
ExtraMemoryOps.putMatrix4f(ptr, instance.pose);
ExtraMemoryOps.put2x16(ptr + 64, instance.packedUs);
ExtraMemoryOps.put2x16(ptr + 68, instance.packedVs);
MemoryUtil.memPutByte(ptr + 72, instance.red);
MemoryUtil.memPutByte(ptr + 73, instance.green);
MemoryUtil.memPutByte(ptr + 74, instance.blue);
MemoryUtil.memPutByte(ptr + 75, instance.alpha);
ExtraMemoryOps.put2x16(ptr + 76, instance.light);
})
.vertexShader(Flywheel.rl("instance/glyph.vert"))
.cullShader(Flywheel.rl("instance/cull/glyph.glsl"))
.build();
private InstanceTypes() {
}
}

View file

@ -10,11 +10,7 @@ import com.mojang.blaze3d.vertex.VertexConsumer;
import dev.engine_room.flywheel.api.internal.DependencyInjection;
import dev.engine_room.flywheel.lib.transform.PoseTransformStack;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.font.FontSet;
import net.minecraft.client.gui.font.glyphs.BakedGlyph;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.resources.ResourceLocation;
public interface FlwLibLink {
FlwLibLink INSTANCE = DependencyInjection.load(FlwLibLink.class, "dev.engine_room.flywheel.impl.FlwLibLinkImpl");
@ -36,10 +32,4 @@ public interface FlwLibLink {
boolean isShaderPackInUse();
boolean isRenderingShadowPass();
FontSet getFontSet(Font font, ResourceLocation loc);
boolean getFilterFishyGlyphs(Font font);
BakedGlyphExtension getBakedGlyphExtension(BakedGlyph glyph);
}

View file

@ -13,15 +13,9 @@ import dev.engine_room.flywheel.impl.compat.OptifineCompat;
import dev.engine_room.flywheel.impl.extension.PoseStackExtension;
import dev.engine_room.flywheel.impl.mixin.ModelPartAccessor;
import dev.engine_room.flywheel.impl.mixin.PoseStackAccessor;
import dev.engine_room.flywheel.impl.mixin.text.FontAccessor;
import dev.engine_room.flywheel.lib.internal.BakedGlyphExtension;
import dev.engine_room.flywheel.lib.internal.FlwLibLink;
import dev.engine_room.flywheel.lib.transform.PoseTransformStack;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.font.FontSet;
import net.minecraft.client.gui.font.glyphs.BakedGlyph;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.resources.ResourceLocation;
public class FlwLibLinkImpl implements FlwLibLink {
@Override
@ -80,19 +74,4 @@ public class FlwLibLinkImpl implements FlwLibLink {
return false;
}
}
@Override
public FontSet getFontSet(Font font, ResourceLocation loc) {
return ((FontAccessor) font).flywheel$getFontSet(loc);
}
@Override
public boolean getFilterFishyGlyphs(Font font) {
return ((FontAccessor) font).flywheel$getFilterFishyGlyphs();
}
@Override
public BakedGlyphExtension getBakedGlyphExtension(BakedGlyph glyph) {
return (BakedGlyphExtension) glyph;
}
}

View file

@ -16,12 +16,6 @@
"PoseStackMixin",
"fix.FixFabulousDepthMixin",
"fix.FixNormalScalingMixin",
"text.BakedGlyphMixin",
"text.CodePointMapMixin",
"text.FontAccessor",
"text.FontSetMixin",
"text.FontTexture$NodeAccessor",
"text.FontTextureMixin",
"visualmanage.BlockEntityMixin",
"visualmanage.LevelChunkMixin",
"visualmanage.LevelRendererMixin",

View file

@ -1,13 +1,14 @@
package dev.engine_room.flywheel.lib.instance;
package dev.engine_room.vanillin;
import org.joml.Matrix4f;
import org.joml.Matrix4fc;
import dev.engine_room.flywheel.api.instance.InstanceHandle;
import dev.engine_room.flywheel.api.instance.InstanceType;
import dev.engine_room.flywheel.lib.internal.BakedGlyphExtension;
import dev.engine_room.flywheel.lib.internal.FlwLibLink;
import dev.engine_room.flywheel.lib.instance.ColoredLitInstance;
import dev.engine_room.flywheel.lib.math.DataPacker;
import dev.engine_room.vanillin.text.BakedGlyphExtension;
import dev.engine_room.vanillin.text.TextUtil;
import net.minecraft.client.gui.font.glyphs.BakedGlyph;
public class GlyphInstance extends ColoredLitInstance {
@ -25,7 +26,7 @@ public class GlyphInstance extends ColoredLitInstance {
}
public GlyphInstance setGlyph(BakedGlyph glyph, Matrix4fc initialPose, float x, float y, boolean italic) {
var glyphExtension = FlwLibLink.INSTANCE.getBakedGlyphExtension(glyph);
var glyphExtension = TextUtil.getBakedGlyphExtension(glyph);
setUvs(glyphExtension);
float left = glyphExtension.flywheel$left();
@ -44,7 +45,7 @@ public class GlyphInstance extends ColoredLitInstance {
}
public GlyphInstance setEffect(BakedGlyph glyph, Matrix4fc initialPose, float x0, float y0, float x1, float y1, float depth) {
var glyphExtension = FlwLibLink.INSTANCE.getBakedGlyphExtension(glyph);
var glyphExtension = TextUtil.getBakedGlyphExtension(glyph);
setUvs(glyphExtension);
pose.set(initialPose);

View file

@ -4,6 +4,7 @@ import dev.engine_room.vanillin.visuals.BellVisual;
import dev.engine_room.vanillin.visuals.ChestVisual;
import dev.engine_room.vanillin.visuals.MinecartVisual;
import dev.engine_room.vanillin.visuals.ShulkerBoxVisual;
import dev.engine_room.vanillin.visuals.SignVisual;
import dev.engine_room.vanillin.visuals.TntMinecartVisual;
import net.minecraft.client.model.geom.ModelLayers;
import net.minecraft.world.entity.Entity;
@ -33,6 +34,9 @@ public class VanillaVisuals {
.factory(ShulkerBoxVisual::new)
.apply(true);
builder(BlockEntityType.SIGN).factory(SignVisual::new)
.apply(false);
builder(EntityType.CHEST_MINECART)
.factory((ctx, entity, partialTick) -> new MinecartVisual<>(ctx, entity, partialTick, ModelLayers.CHEST_MINECART))
.skipVanillaRender(MinecartVisual::shouldSkipRender)

View file

@ -0,0 +1,32 @@
package dev.engine_room.vanillin;
import org.lwjgl.system.MemoryUtil;
import dev.engine_room.flywheel.api.instance.InstanceType;
import dev.engine_room.flywheel.api.layout.FloatRepr;
import dev.engine_room.flywheel.api.layout.LayoutBuilder;
import dev.engine_room.flywheel.lib.instance.SimpleInstanceType;
import dev.engine_room.flywheel.lib.util.ExtraMemoryOps;
public class VanillinInstanceTypes {
public static final InstanceType<GlyphInstance> GLYPH = SimpleInstanceType.builder(GlyphInstance::new)
.layout(LayoutBuilder.create()
.matrix("pose", FloatRepr.FLOAT, 4)
.vector("u0u1v0v1", FloatRepr.NORMALIZED_UNSIGNED_SHORT, 4)
.vector("color", FloatRepr.NORMALIZED_UNSIGNED_BYTE, 4)
.vector("light", FloatRepr.UNSIGNED_SHORT, 2)
.build())
.writer((ptr, instance) -> {
ExtraMemoryOps.putMatrix4f(ptr, instance.pose);
ExtraMemoryOps.put2x16(ptr + 64, instance.packedUs);
ExtraMemoryOps.put2x16(ptr + 68, instance.packedVs);
MemoryUtil.memPutByte(ptr + 72, instance.red);
MemoryUtil.memPutByte(ptr + 73, instance.green);
MemoryUtil.memPutByte(ptr + 74, instance.blue);
MemoryUtil.memPutByte(ptr + 75, instance.alpha);
ExtraMemoryOps.put2x16(ptr + 76, instance.light);
})
.vertexShader(Vanillin.rl("instance/glyph.vert"))
.cullShader(Vanillin.rl("instance/cull/glyph.glsl"))
.build();
}

View file

@ -1,11 +1,11 @@
package dev.engine_room.flywheel.impl.mixin.text;
package dev.engine_room.vanillin.mixin.text;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import dev.engine_room.flywheel.lib.internal.BakedGlyphExtension;
import dev.engine_room.vanillin.text.BakedGlyphExtension;
import net.minecraft.client.gui.font.glyphs.BakedGlyph;
import net.minecraft.resources.ResourceLocation;

View file

@ -1,4 +1,4 @@
package dev.engine_room.flywheel.impl.mixin.text;
package dev.engine_room.vanillin.mixin.text;
import java.util.function.IntFunction;

View file

@ -1,4 +1,4 @@
package dev.engine_room.flywheel.impl.mixin.text;
package dev.engine_room.vanillin.mixin.text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

View file

@ -1,4 +1,4 @@
package dev.engine_room.flywheel.impl.mixin.text;
package dev.engine_room.vanillin.mixin.text;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.At;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import dev.engine_room.flywheel.impl.extension.FontTextureExtension;
import dev.engine_room.vanillin.text.FontTextureExtension;
import net.minecraft.client.gui.font.FontSet;
import net.minecraft.client.gui.font.FontTexture;
import net.minecraft.resources.ResourceLocation;

View file

@ -1,4 +1,4 @@
package dev.engine_room.flywheel.impl.mixin.text;
package dev.engine_room.vanillin.mixin.text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

View file

@ -1,4 +1,4 @@
package dev.engine_room.flywheel.impl.mixin.text;
package dev.engine_room.vanillin.mixin.text;
import java.util.ArrayList;
import java.util.List;
@ -20,9 +20,9 @@ import com.mojang.blaze3d.font.SheetGlyphInfo;
import com.mojang.blaze3d.platform.NativeImage;
import com.mojang.blaze3d.systems.RenderSystem;
import dev.engine_room.flywheel.impl.FontTextureUpload;
import dev.engine_room.flywheel.impl.extension.FontTextureExtension;
import dev.engine_room.flywheel.lib.internal.BakedGlyphExtension;
import dev.engine_room.vanillin.text.BakedGlyphExtension;
import dev.engine_room.vanillin.text.FontTextureExtension;
import dev.engine_room.vanillin.text.FontTextureUpload;
import net.minecraft.client.gui.font.FontTexture;
import net.minecraft.client.gui.font.glyphs.BakedGlyph;
import net.minecraft.client.renderer.texture.AbstractTexture;

View file

@ -1,4 +1,4 @@
package dev.engine_room.flywheel.lib.internal;
package dev.engine_room.vanillin.text;
import net.minecraft.resources.ResourceLocation;

View file

@ -1,4 +1,4 @@
package dev.engine_room.flywheel.impl.extension;
package dev.engine_room.vanillin.text;
import net.minecraft.resources.ResourceLocation;

View file

@ -1,4 +1,4 @@
package dev.engine_room.flywheel.impl;
package dev.engine_room.vanillin.text;
import com.mojang.blaze3d.font.SheetGlyphInfo;

View file

@ -1,4 +1,4 @@
package dev.engine_room.flywheel.lib.visual.text;
package dev.engine_room.vanillin.text;
import java.util.Objects;

View file

@ -1,4 +1,4 @@
package dev.engine_room.flywheel.lib.visual.text;
package dev.engine_room.vanillin.text;
import java.util.function.Consumer;

View file

@ -1,4 +1,4 @@
package dev.engine_room.flywheel.lib.visual.text;
package dev.engine_room.vanillin.text;
import net.minecraft.client.gui.Font;

View file

@ -0,0 +1,21 @@
package dev.engine_room.vanillin.text;
import dev.engine_room.vanillin.mixin.text.FontAccessor;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.font.FontSet;
import net.minecraft.client.gui.font.glyphs.BakedGlyph;
import net.minecraft.resources.ResourceLocation;
public class TextUtil {
public static FontSet getFontSet(Font font, ResourceLocation loc) {
return ((FontAccessor) font).flywheel$getFontSet(loc);
}
public static boolean getFilterFishyGlyphs(Font font) {
return ((FontAccessor) font).flywheel$getFilterFishyGlyphs();
}
public static BakedGlyphExtension getBakedGlyphExtension(BakedGlyph glyph) {
return (BakedGlyphExtension) glyph;
}
}

View file

@ -1,4 +1,4 @@
package dev.engine_room.flywheel.lib.visual.text;
package dev.engine_room.vanillin.text;
import java.util.ArrayList;
import java.util.List;
@ -17,13 +17,12 @@ import dev.engine_room.flywheel.api.instance.InstancerProvider;
import dev.engine_room.flywheel.api.model.Mesh;
import dev.engine_room.flywheel.api.model.Model;
import dev.engine_room.flywheel.api.vertex.MutableVertexList;
import dev.engine_room.flywheel.lib.instance.GlyphInstance;
import dev.engine_room.flywheel.lib.instance.InstanceTypes;
import dev.engine_room.flywheel.lib.internal.FlwLibLink;
import dev.engine_room.flywheel.lib.model.QuadMesh;
import dev.engine_room.flywheel.lib.model.SingleMeshModel;
import dev.engine_room.flywheel.lib.util.ResourceReloadCache;
import dev.engine_room.flywheel.lib.util.RendererReloadCache;
import dev.engine_room.flywheel.lib.visual.util.SmartRecycler;
import dev.engine_room.vanillin.GlyphInstance;
import dev.engine_room.vanillin.VanillinInstanceTypes;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.font.FontSet;
@ -42,8 +41,8 @@ import net.minecraft.util.Mth;
public final class TextVisual {
private static final Font FONT = Minecraft.getInstance().font;
private static final ResourceReloadCache<GlyphMeshKey, GlyphMesh> GLYPH_MESH_CACHE = new ResourceReloadCache<>(GlyphMeshKey::into);
private static final ResourceReloadCache<GlyphModelKey, Model> GLYPH_MODEL_CACHE = new ResourceReloadCache<>(GlyphModelKey::into);
private static final RendererReloadCache<GlyphMeshKey, GlyphMesh> GLYPH_MESH_CACHE = new RendererReloadCache<>(GlyphMeshKey::into);
private static final RendererReloadCache<GlyphModelKey, Model> GLYPH_MODEL_CACHE = new RendererReloadCache<>(GlyphModelKey::into);
private static final ThreadLocal<Sink> SINKS = ThreadLocal.withInitial(Sink::new);
@ -56,7 +55,7 @@ public final class TextVisual {
private int light;
public TextVisual(InstancerProvider provider) {
recycler = new SmartRecycler<>(key -> provider.instancer(InstanceTypes.GLYPH, GLYPH_MODEL_CACHE.get(key.modelKey), key.bias)
recycler = new SmartRecycler<>(key -> provider.instancer(VanillinInstanceTypes.GLYPH, GLYPH_MODEL_CACHE.get(key.modelKey), key.bias)
.createInstance());
}
@ -179,8 +178,8 @@ public final class TextVisual {
@Override
public boolean accept(int index, Style style, int codePoint) {
FontSet fontSet = FlwLibLink.INSTANCE.getFontSet(FONT, style.getFont());
GlyphInfo glyphInfo = fontSet.getGlyphInfo(codePoint, FlwLibLink.INSTANCE.getFilterFishyGlyphs(FONT));
FontSet fontSet = TextUtil.getFontSet(FONT, style.getFont());
GlyphInfo glyphInfo = fontSet.getGlyphInfo(codePoint, TextUtil.getFilterFishyGlyphs(FONT));
BakedGlyph glyph = style.isObfuscated() && codePoint != ' ' ? fontSet.getRandomGlyph(glyphInfo) : fontSet.getGlyph(codePoint);
boolean bold = style.isBold();
@ -218,10 +217,10 @@ public final class TextVisual {
public void addBackground(int backgroundColor, float startX, float endX) {
if (backgroundColor != 0) {
BakedGlyph glyph = FlwLibLink.INSTANCE.getFontSet(FONT, Style.DEFAULT_FONT)
BakedGlyph glyph = TextUtil.getFontSet(FONT, Style.DEFAULT_FONT)
.whiteGlyph();
var glyphExtension = FlwLibLink.INSTANCE.getBakedGlyphExtension(glyph);
var glyphExtension = TextUtil.getBakedGlyphExtension(glyph);
GlyphInstance instance = recycler.get(effectKey(glyphExtension.flywheel$texture(), TextLayer.GlyphMaterial.SEE_THROUGH, 0));
instance.setEffect(glyph, pose, startX - 1.0f, 9.0f, endX + 1.0f, 1.0f, 0.01f);
@ -232,7 +231,7 @@ public final class TextVisual {
}
private void addEffect(TextLayer layer, float x0, float y0, float x1, float y1, float depth, int colorArgb) {
BakedGlyph glyph = FlwLibLink.INSTANCE.getFontSet(FONT, Style.DEFAULT_FONT)
BakedGlyph glyph = TextUtil.getFontSet(FONT, Style.DEFAULT_FONT)
.whiteGlyph();
GlyphInstance instance = recycler.get(effectKey(glyph, layer));
@ -243,7 +242,7 @@ public final class TextVisual {
}
private static GlyphInstanceKey key(TextLayer layer, GlyphInfo glyphInfo, BakedGlyph glyph, boolean bold) {
var glyphExtension = FlwLibLink.INSTANCE.getBakedGlyphExtension(glyph);
var glyphExtension = TextUtil.getBakedGlyphExtension(glyph);
float glyphWidth = glyphExtension.flywheel$right() - glyphExtension.flywheel$left();
float glyphHeight = glyphExtension.flywheel$down() - glyphExtension.flywheel$up();
@ -257,7 +256,7 @@ public final class TextVisual {
}
private static GlyphInstanceKey effectKey(BakedGlyph glyph, TextLayer layer) {
var glyphExtension = FlwLibLink.INSTANCE.getBakedGlyphExtension(glyph);
var glyphExtension = TextUtil.getBakedGlyphExtension(glyph);
return effectKey(glyphExtension.flywheel$texture(), layer.material(), layer.bias());
}

View file

@ -1,4 +1,4 @@
package dev.engine_room.flywheel.vanilla;
package dev.engine_room.vanillin.visuals;
import java.util.ArrayList;
import java.util.List;
@ -15,12 +15,12 @@ import dev.engine_room.flywheel.lib.material.SimpleMaterial;
import dev.engine_room.flywheel.lib.model.part.InstanceTree;
import dev.engine_room.flywheel.lib.model.part.ModelTree;
import dev.engine_room.flywheel.lib.model.part.ModelTrees;
import dev.engine_room.flywheel.lib.util.ResourceReloadCache;
import dev.engine_room.flywheel.lib.util.RendererReloadCache;
import dev.engine_room.flywheel.lib.visual.AbstractBlockEntityVisual;
import dev.engine_room.flywheel.lib.visual.SimpleDynamicVisual;
import dev.engine_room.flywheel.lib.visual.text.TextLayer;
import dev.engine_room.flywheel.lib.visual.text.TextLayers;
import dev.engine_room.flywheel.lib.visual.text.TextVisual;
import dev.engine_room.vanillin.text.TextLayer;
import dev.engine_room.vanillin.text.TextLayers;
import dev.engine_room.vanillin.text.TextVisual;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.model.geom.ModelLayers;
@ -41,7 +41,7 @@ public class SignVisual extends AbstractBlockEntityVisual<SignBlockEntity> imple
private static final Vec3 TEXT_OFFSET = new Vec3(0.0, 0.3333333432674408, 0.046666666865348816);
private static final Font FONT = Minecraft.getInstance().font;
private static final ResourceReloadCache<WoodType, ModelTree> SIGN_MODELS = new ResourceReloadCache<>(SignVisual::createSignModel);
private static final RendererReloadCache<WoodType, ModelTree> SIGN_MODELS = new RendererReloadCache<>(SignVisual::createSignModel);
private static final Material MATERIAL = SimpleMaterial.builder()
.cutout(CutoutShaders.ONE_TENTH)

View file

@ -0,0 +1,18 @@
{
"required" : true,
"minVersion" : "0.8",
"package" : "dev.engine_room.vanillin.mixin",
"compatibilityLevel" : "JAVA_17",
"refmap" : "vanillin.refmap.json",
"client" : [
"text.BakedGlyphMixin",
"text.CodePointMapMixin",
"text.FontAccessor",
"text.FontSetMixin",
"text.FontTexture$NodeAccessor",
"text.FontTextureMixin"
],
"injectors" : {
"defaultRequire" : 1
}
}

View file

@ -113,9 +113,6 @@ dependencies {
modCompileOnly("maven.modrinth:embeddium:${property("embeddium_version")}")
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.4.1")!!)
implementation(include("io.github.llamalad7:mixinextras-forge:0.4.1")!!)
"forApi"(project(path = common, configuration = "apiClasses"))
"forLib"(project(path = common, configuration = "libClasses"))
"forBackend"(project(path = common, configuration = "backendClasses"))

View file

@ -22,6 +22,7 @@
]
},
"mixins" : [
"vanillin.mixins.json"
],
"depends" : {
"minecraft" : "${minecraft_semver_version_range}",

View file

@ -42,6 +42,10 @@ loom {
add(main, "vanillin.refmap.json")
}
forge {
mixinConfig("vanillin.mixins.json")
}
runs {
configureEach {
property("forge.logging.markers", "")
@ -58,6 +62,9 @@ dependencies {
compileOnly(project(path = common, configuration = "vanillinClasses"))
compileOnly(project(path = common, configuration = "vanillinResources"))
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.4.1")!!)
implementation(include("io.github.llamalad7:mixinextras-forge:0.4.1")!!)
// JiJ flywheel proper
include(project(path = platform, configuration = "flywheelRemap"))
runtimeOnly(project(path = platform, configuration = "flywheelDev"))