feat: GUI overhaul

This commit is contained in:
LordMZTE 2023-12-07 18:59:58 +01:00
parent e6b7973efb
commit e97f516a34
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
10 changed files with 308 additions and 96 deletions

View file

@ -16,7 +16,7 @@ loom.platform=forge
yarn_mappings=1.18.2+build.4
# Mod Properties
mod_version=1.0.0
mod_version=1.1.0
maven_group=net.anvilcraft.ntx4core
archives_base_name=ntx4core
mod_id=ntx4core

View file

@ -0,0 +1,136 @@
package net.anvilcraft.ntx4core;
import com.mojang.blaze3d.platform.GlDebugInfo;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat.DrawMode;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.util.math.Vec3f;
public class RenderHelper {
private static final Identifier ALEC = Ntx4Core.id("textures/alec.png");
public static float shaderTime = 0f;
public static void renderSplashScreen(float alpha) {
// This shader is somehow borked on Intel. Not My fault!
if (!GlDebugInfo.getVendor().equals("Intel")) {
RenderSystem.setShader(() -> Ntx4CoreShaders.SPLASH);
Ntx4CoreShaders.SPLASH.getUniform("Time").set(shaderTime / 20.0f);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, alpha);
BufferBuilder buf = Tessellator.getInstance().getBuffer();
buf.begin(DrawMode.QUADS, VertexFormats.POSITION);
buf.vertex(-1.0, -1.0, 0.0).next();
buf.vertex(1.0, -1.0, 0.0).next();
buf.vertex(1.0, 1.0, 0.0).next();
buf.vertex(-1.0, 1.0, 0.0).next();
buf.end();
BufferRenderer.draw(buf);
if (AlecManager.HAS_ALEC) {
float offset_x = (float) Math.sin(shaderTime / 25.);
float offset_y = (float) Math.cos(shaderTime / 25.);
var mtx = Matrix4f.viewboxMatrix(45., 1.f, 0.1f, 100.f);
mtx.multiply(Matrix4f.translate(offset_x, offset_y, -5.f));
mtx.multiply(Vec3f.NEGATIVE_Y.getDegreesQuaternion(shaderTime * 4.f));
// clang-format off
mtx.multiply(new Matrix4f(new float[]{
1.f, 0.f, 0.f, 0.f,
0.f, -1.f, 0.f, 0.f,
0.f, 0.f, 1.f, 0.f,
0.f, 0.f, 0.f, 1.f,
}));
// clang-format on
RenderSystem.setShader(() -> Ntx4CoreShaders.ALECUBUS);
RenderSystem.setShaderTexture(0, ALEC);
Ntx4CoreShaders.ALECUBUS.getUniform("Mtx").set(mtx);
buf.begin(DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
alecVert(buf, -0.5, -0.5, -0.5, 1.0, 0.0);
alecVert(buf, 0.5, -0.5, -0.5, 0.0, 0.0);
alecVert(buf, 0.5, 0.5, -0.5, 0.0, 1.0);
alecVert(buf, -0.5, 0.5, -0.5, 1.0, 1.0);
alecVert(buf, -0.5, -0.5, 0.5, 0.0, 0.0);
alecVert(buf, 0.5, -0.5, 0.5, 1.0, 0.0);
alecVert(buf, 0.5, 0.5, 0.5, 1.0, 1.0);
alecVert(buf, -0.5, 0.5, 0.5, 0.0, 1.0);
alecVert(buf, -0.5, 0.5, 0.5, 1.0, 1.0);
alecVert(buf, -0.5, 0.5, -0.5, 0.0, 1.0);
alecVert(buf, -0.5, -0.5, -0.5, 0.0, 0.0);
alecVert(buf, -0.5, -0.5, 0.5, 1.0, 0.0);
alecVert(buf, 0.5, 0.5, 0.5, 0.0, 1.0);
alecVert(buf, 0.5, 0.5, -0.5, 1.0, 1.0);
alecVert(buf, 0.5, -0.5, -0.5, 1.0, 0.0);
alecVert(buf, 0.5, -0.5, 0.5, 0.0, 0.0);
alecVert(buf, -0.5, -0.5, -0.5, 0.0, 1.0);
alecVert(buf, 0.5, -0.5, -0.5, 1.0, 1.0);
alecVert(buf, 0.5, -0.5, 0.5, 1.0, 0.0);
alecVert(buf, -0.5, -0.5, 0.5, 0.0, 0.0);
alecVert(buf, -0.5, 0.5, -0.5, 0.0, 1.0);
alecVert(buf, 0.5, 0.5, -0.5, 1.0, 1.0);
alecVert(buf, 0.5, 0.5, 0.5, 1.0, 0.0);
alecVert(buf, -0.5, 0.5, 0.5, 0.0, 0.0);
buf.end();
GlStateManager._enableDepthTest();
GlStateManager._disableCull();
BufferRenderer.draw(buf);
GlStateManager._disableDepthTest();
GlStateManager._enableCull();
}
} else {
int width = MinecraftClient.getInstance().getWindow().getScaledWidth();
int height = MinecraftClient.getInstance().getWindow().getScaledHeight();
var bgTexture = AlecManager.HAS_ALEC
? ALEC
: new Identifier("textures/gui/options_background.png");
Tessellator tesselator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tesselator.getBuffer();
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
RenderSystem.setShaderTexture(0, bgTexture);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
bufferbuilder.begin(DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
bufferbuilder.vertex(0.0D, (double) height, 0.0D)
.texture(0.0F, (float) height / 32.0F)
.color(64, 64, 64, 255)
.next();
bufferbuilder.vertex((double) width, (double) height, 0.0D)
.texture((float) width / 32.0F, (float) height / 32.0F)
.color(64, 64, 64, 255)
.next();
bufferbuilder.vertex((double) width, 0.0D, 0.0D)
.texture((float) width / 32.0F, 0f)
.color(64, 64, 64, 255)
.next();
bufferbuilder.vertex(0.0D, 0.0D, 0.0D)
.texture(0.0F, 0f)
.color(64, 64, 64, 255)
.next();
tesselator.draw();
}
}
private static void
alecVert(BufferBuilder buf, double x, double y, double z, double u, double v) {
buf.vertex((float) x, (float) y, (float) z).texture((float) u, (float) v).next();
}
}

View file

@ -0,0 +1,77 @@
package net.anvilcraft.ntx4core.mixin.client;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.widget.EntryListWidget;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat.DrawMode;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
@Mixin(EntryListWidget.class)
public class EntryListWidgetMixin {
@Shadow
private boolean renderBackground;
@Shadow
private boolean renderHorizontalShadows;
@Shadow
private int left;
@Shadow
private int right;
@Shadow
private int bottom;
@Shadow
private int top;
@Inject(method = "<init>", at = @At("TAIL"))
private void onInit(CallbackInfo ci) {
this.renderBackground = false;
this.renderHorizontalShadows = false;
}
@Inject(method = "render", at = @At("HEAD"))
private void onRender(MatrixStack matrices, int mouseX, int mouseY, float dt, CallbackInfo ci) {
// transparent background
var tes = Tessellator.getInstance();
var bb = tes.getBuffer();
RenderSystem.setShader(GameRenderer::getPositionColorShader);
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
bb.begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
bb.vertex(this.left, this.bottom, 0f).color(0f, 0f, 0f, 0.6f).next();
bb.vertex(this.right, this.bottom, 0f).color(0f, 0f, 0f, 0.6f).next();
bb.vertex(this.right, this.top, 0f).color(0f, 0f, 0f, 0.6f).next();
bb.vertex(this.left, this.top, 0f).color(0f, 0f, 0f, 0.6f).next();
RenderSystem.defaultBlendFunc();
RenderSystem.enableBlend();
tes.draw();
RenderSystem.disableBlend();
}
/**
* @reason Never render the boring dirt background.
* @author LordMZTE
*/
@Overwrite
public void setRenderBackground(boolean alec) {}
/**
* @reason This doesn't work with our background.
* @author LordMZTE
*/
@Overwrite
public void setRenderHorizontalShadows(boolean alec) {}
}

View file

@ -0,0 +1,29 @@
package net.anvilcraft.ntx4core.mixin.client;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.anvilcraft.ntx4core.RenderHelper;
import net.minecraft.client.MinecraftClient;
@Mixin(MinecraftClient.class)
public class MinecraftClientMixin {
@Shadow
private float pausedTickDelta;
@Unique
private long lastFrameTime = System.nanoTime();
@Inject(method = "render", at = @At("HEAD"))
private void onRender(boolean alec, CallbackInfo ci) {
long now = System.nanoTime();
float dt = ((float) ((now - this.lastFrameTime) / 1000)) / 50000; // in ticks
RenderHelper.shaderTime += dt;
this.lastFrameTime = now;
}
}

View file

@ -0,0 +1,19 @@
package net.anvilcraft.ntx4core.mixin.client;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import net.anvilcraft.ntx4core.RenderHelper;
import net.minecraft.client.gui.screen.Screen;
@Mixin(Screen.class)
public class ScreenMixin {
/**
* @reason Fancy background.
* @author LordMZTE
*/
@Overwrite
public void renderBackgroundTexture(int vOffset) {
RenderHelper.renderSplashScreen(1.0f);
}
}

View file

@ -0,0 +1,25 @@
package net.anvilcraft.ntx4core.mixin.client;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.world.SelectWorldScreen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
@Mixin(SelectWorldScreen.class)
public class SelectWorldScreenMixin extends Screen {
protected SelectWorldScreenMixin(Text alec) {
super(alec);
throw new AssertionError();
}
@Inject(method = "render", at = @At("HEAD"))
private void
onRender(MatrixStack matrices, int alec1, int alec2, float alec3, CallbackInfo ci) {
this.renderBackground(matrices);
}
}

View file

@ -10,30 +10,22 @@ import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import com.mojang.blaze3d.platform.GlDebugInfo;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.anvilcraft.ntx4core.AlecManager;
import net.anvilcraft.ntx4core.Ntx4Core;
import net.anvilcraft.ntx4core.Ntx4CoreShaders;
import net.anvilcraft.ntx4core.RenderHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Overlay;
import net.minecraft.client.gui.screen.SplashOverlay;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat.DrawMode;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.resource.ResourceReload;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.math.ColorHelper.Argb;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.util.math.Vec3f;
import net.minecraftforge.client.loading.ClientModLoader;
@Mixin(SplashOverlay.class)
@ -69,16 +61,12 @@ public class SplashOverlayMixin extends Overlay {
@Shadow
private long reloadCompleteTime;
@Unique
private float time = 0.0f;
/**
* @reason Replaces the vanilla spash screen
* @author LordMZTE
*/
@Overwrite
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
time += delta;
if (Ntx4CoreShaders.SPLASH == null) {
Ntx4CoreShaders.registerShaders();
}
@ -120,81 +108,8 @@ public class SplashOverlayMixin extends Overlay {
} else {
f2 = 1.0F;
}
// This shader is somehow borked on Intel. Not My fault!
if (!GlDebugInfo.getVendor().equals("Intel")) {
RenderSystem.setShader(() -> Ntx4CoreShaders.SPLASH);
Ntx4CoreShaders.SPLASH.getUniform("Time").set(this.time / 20.0f);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, f2);
BufferBuilder buf = Tessellator.getInstance().getBuffer();
buf.begin(DrawMode.QUADS, VertexFormats.POSITION);
buf.vertex(-1.0, -1.0, 0.0).next();
buf.vertex(1.0, -1.0, 0.0).next();
buf.vertex(1.0, 1.0, 0.0).next();
buf.vertex(-1.0, 1.0, 0.0).next();
buf.end();
BufferRenderer.draw(buf);
if (AlecManager.HAS_ALEC) {
float offset_x = (float) Math.sin(this.time / 25.);
float offset_y = (float) Math.cos(this.time / 25.);
var mtx = Matrix4f.viewboxMatrix(45., 1.f, 0.1f, 100.f);
mtx.multiply(Matrix4f.translate(offset_x, offset_y, -5.f));
mtx.multiply(Vec3f.NEGATIVE_Y.getDegreesQuaternion(this.time * 4.f));
// clang-format off
mtx.multiply(new Matrix4f(new float[]{
1.f, 0.f, 0.f, 0.f,
0.f, -1.f, 0.f, 0.f,
0.f, 0.f, 1.f, 0.f,
0.f, 0.f, 0.f, 1.f,
}));
// clang-format on
RenderSystem.setShader(() -> Ntx4CoreShaders.ALECUBUS);
RenderSystem.setShaderTexture(0, ALEC);
Ntx4CoreShaders.ALECUBUS.getUniform("Mtx").set(mtx);
buf.begin(DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
alecVert(buf, -0.5, -0.5, -0.5, 1.0, 0.0);
alecVert(buf, 0.5, -0.5, -0.5, 0.0, 0.0);
alecVert(buf, 0.5, 0.5, -0.5, 0.0, 1.0);
alecVert(buf, -0.5, 0.5, -0.5, 1.0, 1.0);
alecVert(buf, -0.5, -0.5, 0.5, 0.0, 0.0);
alecVert(buf, 0.5, -0.5, 0.5, 1.0, 0.0);
alecVert(buf, 0.5, 0.5, 0.5, 1.0, 1.0);
alecVert(buf, -0.5, 0.5, 0.5, 0.0, 1.0);
alecVert(buf, -0.5, 0.5, 0.5, 1.0, 1.0);
alecVert(buf, -0.5, 0.5, -0.5, 0.0, 1.0);
alecVert(buf, -0.5, -0.5, -0.5, 0.0, 0.0);
alecVert(buf, -0.5, -0.5, 0.5, 1.0, 0.0);
alecVert(buf, 0.5, 0.5, 0.5, 0.0, 1.0);
alecVert(buf, 0.5, 0.5, -0.5, 1.0, 1.0);
alecVert(buf, 0.5, -0.5, -0.5, 1.0, 0.0);
alecVert(buf, 0.5, -0.5, 0.5, 0.0, 0.0);
alecVert(buf, -0.5, -0.5, -0.5, 0.0, 1.0);
alecVert(buf, 0.5, -0.5, -0.5, 1.0, 1.0);
alecVert(buf, 0.5, -0.5, 0.5, 1.0, 0.0);
alecVert(buf, -0.5, -0.5, 0.5, 0.0, 0.0);
alecVert(buf, -0.5, 0.5, -0.5, 0.0, 1.0);
alecVert(buf, 0.5, 0.5, -0.5, 1.0, 1.0);
alecVert(buf, 0.5, 0.5, 0.5, 1.0, 0.0);
alecVert(buf, -0.5, 0.5, 0.5, 0.0, 0.0);
buf.end();
GlStateManager._enableDepthTest();
GlStateManager._disableCull();
BufferRenderer.draw(buf);
GlStateManager._disableDepthTest();
GlStateManager._enableCull();
}
}
RenderHelper.renderSplashScreen(f2);
l1 = (int) ((double) this.client.getWindow().getScaledWidth() * 0.5D);
int k2 = (int) ((double) this.client.getWindow().getScaledHeight() * 0.5D);
@ -267,11 +182,6 @@ public class SplashOverlayMixin extends Overlay {
}
}
private void
alecVert(BufferBuilder buf, double x, double y, double z, double u, double v) {
buf.vertex((float) x, (float) y, (float) z).texture((float) u, (float) v).next();
}
private void renderProgressBar(
MatrixStack matrices, int minX, int minY, int maxX, int maxY, float opacity
) {

View file

@ -1,11 +1,12 @@
#version 150
// vim: ft=glsl
uniform vec4 ColorModulator;
uniform sampler2D Sampler0;
in vec2 texCoord;
out vec4 fragColor;
uniform sampler2D Sampler0;
void main() {
fragColor = texture(Sampler0, texCoord);
fragColor = texture(Sampler0, texCoord) * ColorModulator;
}

View file

@ -16,6 +16,17 @@
}
],
"uniforms": [
{
"name": "ColorModulator",
"type": "float",
"count": 4,
"values": [
1.0,
1.0,
1.0,
1.0
]
},
{
"name": "Mtx",
"type": "matrix4x4",

View file

@ -8,6 +8,10 @@
"common.ForgeFlowingFluidMixin"
],
"client": [
"client.EntryListWidgetMixin",
"client.MinecraftClientMixin",
"client.ScreenMixin",
"client.SelectWorldScreenMixin",
"client.SplashOverlayMixin",
"client.TitleScreenMixin"
],