Jump to content

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


Majd123mc

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

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