Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[SOLVED] [1.17.1] How to register a Screen to a Menu (Container)


Majd123mc
 Share

Recommended Posts

Hello, I am trying to make my own furnace. But I have ran into an issue. How am I supposed to register a Screen?

In the vanilla implementation, it uses "MenuScreen.register", but it does not accept a supplier, and by the time I am registering it the blocks and menu haven't been registered yet.

I have heard to use ScreenManager.registerFactory, but it seems that method doesn't exist anymore.

Where/when/how should I register the screen? Thanks a lot.

Code for ModScreens.java:

public class ModScreens {
    public static void register() {
        MenuScreens.register(ModMenus.REFINERY_FURNACE.get(), RefineryFurnaceScreen::new);
        // Doesn't work because ModMenus.REFINERY_FURNACE is not initialized until registry.
    }
}

Code for MiniTech.java:

@Mod(MiniTech.MODID)
public class MiniTech
{
    // Directly reference a log4j logger.
    public static final Logger LOGGER = LogManager.getLogger();

    public static final String MODID = "minitech";

    private static final List<Consumer<IEventBus>> registrationFunctions = Arrays.asList(
            ModBlocks::register,
            ModItems::register,
            ModBlockEntities::register,
            ModMenus::register,
            __ -> ModScreens.register()
    );

    public MiniTech() {
        IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();

        for (var registrationFunction : registrationFunctions) {
            registrationFunction.accept(eventBus);
        }
    }
}

 

Edited by Majd123mc
Closed
Link to comment
Share on other sites

1 hour ago, Majd123mc said:

I have heard to use ScreenManager.registerFactory, but it seems that method doesn't exist anymore.

That's what MenuScreens.register is. You need to call it during FMLCLientSetupEvent#enqueueWork, not your mod constructor.

Link to comment
Share on other sites

  • Majd123mc changed the title to [SOLVED] [1.17.1] How to register a Screen to a Menu (Container)

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

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.