Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

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.

  • Author

Never heard of mixin before, very cool tool, rewrote everything with mixin and it works. Thanks.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.