Jump to content

Problem with custom game renderer


Jetug

Recommended Posts

I needed to rewrite the GameRenderer#pick() method so I wrote my own GameRenderer class and set an instance of it to Minecraft#gameRenderer with reflection:

@Mod.EventBusSubscriber(modid = Global.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public final class SetupEvents {

    @SubscribeEvent()
    public static void onRegisterRenderers(EntityRenderersEvent.RegisterRenderers event){
        try {
            var minecraft = Minecraft.getInstance();
            var gameRenderer = new ModGameRenderer(minecraft, minecraft.getResourceManager() ,minecraft.renderBuffers());
            Field field = minecraft.getClass().getDeclaredField("gameRenderer");
            field.setAccessible(true);
            field.set(minecraft, gameRenderer);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

And when I run the mod in the IDE my pick() method works but when I build the mod and run it through the minecraft launcher it doesn't. Maybe it's because of the GeckoLib library that I use in my project?

Link to comment
Share on other sites

2 hours ago, Jetug said:

I needed to rewrite the GameRenderer#pick() method so I wrote my own GameRenderer class and set an instance of it to Minecraft#gameRenderer with reflection:

Don't do this. This is liable to break hundreds of mods. You should just replace the usage with a mixin injection whenever you need to do your specific logic.

3 hours ago, Jetug said:

And when I run the mod in the IDE my pick() method works but when I build the mod and run it through the minecraft launcher it doesn't. Maybe it's because of the GeckoLib library that I use in my project?

No, that's not it. It as to do with how you're reflecting the field. Forge uses SRG mappings during production, so the gameRenderer field is called something different. If you want to use reflection, you should use the ObfuscationReflectionHelper to handle this and provide the SRG name.

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.