Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HUD rendering causes crash after loading the world #43

Closed
erxson opened this issue Sep 15, 2023 · 13 comments
Closed

HUD rendering causes crash after loading the world #43

erxson opened this issue Sep 15, 2023 · 13 comments

Comments

@erxson
Copy link

erxson commented Sep 15, 2023

I tried to use OakClient base code for my mod. Let me clarify that there is no HUD in OakClient itself. It shown in ClickGUI or HudEditor, but not in the game itself. I tried to slightly change the code of the main class to make it as close as possible to the example from the PanelStudio repository.

I’ll say right away that I’m just learning Java and I’m not saying that the problem is in PanelStudio itself, but I just don’t know who else I can turn to for help. Sorry.

Crash Log (There are no errors or warns in the rest part the log)
https://paste.gg/p/anonymous/f128659adb004b58ac01cd98ca4f3c90

Main class
https://paste.gg/p/anonymous/df468e2b663d41b28a5436a70dd88195

ClickGUI class (I changed almost nothing, it seems to me)
https://paste.gg/p/anonymous/bcffafd116fe439c81cb7ce62fb25c49

OakClient
https://github.com/desertcod98/OakClient/tree/main/src/main/java/me/leeeaf/oakclient

build.gradle ???
https://paste.gg/p/anonymous/f13e88c4551c49df9ad59bd91f3e2da8

Help me, please

@lukflug
Copy link
Owner

lukflug commented Sep 15, 2023

Oh, it might be an oversight when I ported stuff over to newer versions of Minecraft. I can't believe this hasn't been caught earlier.

Add this to your ClickGUI class:

@override
public void render() {
	this.context = insert_current_DrawContext_here;
	super.render();
}

I don't know how exactly the render method gets invoked, so I can't give an exact expression for that. Alternatively:

@override
public void render(DrawContext context) {
	this.context = context;
	super.render();
}

I hope this helps!

@erxson
Copy link
Author

erxson commented Sep 15, 2023

Thanks for the quick response! Sorry, but I don't know how to get the current DrawContext. The first render() option is fine, but I really don't know where to get the DrawContext or what it even is. If this is fixed in some update, then I can just wait, I'm in no hurry. Thanks again!

@erxson
Copy link
Author

erxson commented Sep 15, 2023

It's probably worth saying that when I try to do this.context = new DrawContext(client, null); then the error is completely different. This is good? Like, it’s already complaining that I couldn’t pass vertex things instead of null

@lukflug
Copy link
Owner

lukflug commented Sep 15, 2023

Oh yeah, no, that's not how it would be done. I'd have to take a closer look.
Even when I fix it, you'd still need to pass a DrawContext.

@lukflug
Copy link
Owner

lukflug commented Sep 15, 2023

https://github.com/desertcod98/OakClient/blob/443b3735eeb1f5c977ba306cc85d6a27d212f8f4/src/main/java/me/leeeaf/oakclient/mixin/InGameHudMixin.java#L16

Iirc the 1.20 equivalent of MatrixStack is DrawContext. That parameter is what you need to pass.

@erxson
Copy link
Author

erxson commented Sep 15, 2023

Yes, I tried to pass it through render method, but... skill issue

@lukflug
Copy link
Owner

lukflug commented Sep 15, 2023

A quick and somewhat dirty solution would be to set the context variable of the ClickGUI in the InGameHudMixin.render method. Because it's protected, you might need a setter.

@lukflug
Copy link
Owner

lukflug commented Sep 15, 2023

A quick and somewhat dirty solution would be to set the context variable of the ClickGUI in the InGameHudMixin.render method. Because it's protected, you might need a setter.

This would make overriding ClickGUI.render unnecessary.

@erxson
Copy link
Author

erxson commented Sep 16, 2023

I did it and it works!

ClientTickEvents.END_CLIENT_TICK.register((client) -> {
    if (gui == null)
        gui=new ClickGUI();
    if (!inited) {
        if (gui.getContext() != null) {
            HudRenderCallback.EVENT.register((cli, tickDelta) -> gui.render());
            inited = true;
        }
    }
});
@Mixin(InGameHud.class)
public abstract class InGameHudMixin {
    @Inject(method = "render", at = @At(value = "RETURN"))
    public void render(DrawContext context, float tickDelta, CallbackInfo ci) {
        ZXCHack.gui.setContext(context);
        EventBus.getEventBus().post(new HudRenderEvent());
    }
}

ClickGUI.java

	public void setContext(DrawContext context) {
		this.context = context;
	}

	public DrawContext getContext() {
		return this.context;
	}

@erxson
Copy link
Author

erxson commented Sep 16, 2023

But can't interact with TabGUI arrows binds

@lukflug
Copy link
Owner

lukflug commented Sep 16, 2023

Is ClickGUI.handleKeyEvent getting invoked?

@erxson
Copy link
Author

erxson commented Sep 16, 2023

No, it replaced with Category.toggleModuleByKeybind in OakClient.

@erxson
Copy link
Author

erxson commented Sep 16, 2023

Sorry. It works now. Thank you very much!

@erxson erxson closed this as completed Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants