#`MinecraftClient setScreen` makes the window blurry

21 messages · Page 1 of 1 (latest)

frail zephyr
#

Hello,
I'm following a YouTube tutorial for a Fabric client (like Feather/Lunar) which is made for 1.19. Most things work, I had to find replacements for some old things, but one thing that doesn't work properly is viewing a GUI screen which just right now is some boxes with text. When I call setScreen with the instance of the Screen class it makes the entire window blurry, including the boxes and things I want to have.

I'm new to Fabric and relatively new to Java so sorry if I'm not explaining this right

somber turtle
#

First, you need to send your code, without it will be hard to give solution

#

Will be good to see your screen and how you set it

frail zephyr
#

Yeah sure

#

src/main/java/spectraclient/Client.java (main entrypoint in fabric.mod.json)

package spectraclient;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.glfw.GLFW;

import net.fabricmc.api.ModInitializer;
import net.minecraft.client.MinecraftClient;
import spectraclient.ui.screens.clickgui.ClickGUI;

public class Client implements ModInitializer {

    public Logger logger = LogManager.getLogger();
    private MinecraftClient mc = MinecraftClient.getInstance();

    public void onKeyPress(int key, int action) {
        if (action == GLFW.GLFW_PRESS && key == GLFW.GLFW_KEY_RIGHT_SHIFT) {
            mc.setScreen(ClickGUI.INSTANCE);

        }

    }

    @Override
    public void onInitialize() {
        logger.info("Hello world");

    }

}
package spectraclient.ui.screens.clickgui;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;

import spectraclient.module.Mod.Category;

public class ClickGUI extends Screen {
    public static final ClickGUI INSTANCE = new ClickGUI();

    private List<Frame> frames;

    private ClickGUI() {
        super(Text.literal("Click GUI"));

        frames = new ArrayList<>();

        int offset = 20;
        for (Category category : Category.values()) {
            frames.add(new Frame(category, offset, 30, 100, 30));
            offset += 120;
        }
    }

    @Override
    public void render(DrawContext context, int mouseX, int mouseY, float delta) {
        for (Frame frame : frames) {
            frame.render(context, mouseX, mouseY, delta);
        }
        super.render(context, mouseX, mouseY, delta);
    }

    @Override
    public boolean mouseClicked(double mouseX, double mouseY, int button) {
        for (Frame frame : frames) {
            frame.mouseClicked(mouseX, mouseY, button);
        }
        
        return super.mouseClicked(mouseX, mouseY, button);
    }

}
package spectraclient.ui.screens.clickgui;

import java.awt.Color;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import spectraclient.module.Mod.Category;

public class Frame {

    public int x, y, width, height;
    public Category category;
    public boolean dragging;

    private MinecraftClient mc = MinecraftClient.getInstance();

    public Frame(Category category, int x, int y, int width, int height) {
        this.x = x;
        this.y = y;
        this.height = height;
        this.width = width;
        this.category = category;
        this.dragging = false;
    }

    public void render(DrawContext context, int mouseX, int mouseY, float delta) {
        context.fill(x, y, x + width, y + height, -1);
        context.drawCenteredTextWithShadow(mc.textRenderer, "Test", x + 2, y + 2, Color.black.getRGB());
    }

    public void mouseClicked(double mouseX, double mouseY, int button) {

    }

}
somber turtle
#

So, first, I recommend you don't use MinecraftClient from class fields, like private MinecraftClient mc = MinecraftClient.getInstance();, just invokeMinecraftClient.getInstance().something()
Second, I think your Frame widgets are blurred because it draws behind the background, try to translate it by Z axis, like this:

    public void render(DrawContext context, int mouseX, int mouseY, float delta) {
        MatrixStack matrices = context.getMatrices();
        matrices.push();
        matrices.translate(0, 0, 10);
        context.fill(x, y, x + width, y + height, -1); // Z: 10
        matrices.translate(0, 0, 10); // Z: 20
        context.drawCenteredTextWithShadow(mc.textRenderer, "Test", x + 2, y + 2, Color.black.getRGB());
        matrices.pop();
    }
olive wharf
#

In your #render, call the super method before rendering your widgets

frail zephyr
#

That worked, thank you ❤️

#

I can see how that makes sense now

#

the screen renders then you draw on top of that

fickle tusk
#

oops im a bit late

wanton tundra
fickle tusk
fickle socket
#

“For a Fabric client” should have been a red flag already

surreal lake
#

Literally

cerulean pollen
#

^