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.

ModScreens.java:22: error: incompatible types: cannot infer type-variable(s) M,U

Featured Replies

Posted

I'm struggling to try and figure out why I'm receiving this error when doing a gradlew build

D:\Projects\ModAlpha6.0\src\main\java\com\dwyvern\modalpha\init\ModScreens.java:22: error: incompatible types: cannot infer type-variable(s) M,U
                        MenuScreens.register(ModContainers.ELEPHANT_INVENTORY_CONTAINER.get(), ElephantInventoryScreen::new);
                                            ^
    (argument mismatch; cannot infer functional interface descriptor for ScreenConstructor<ElephantInventoryContainer,U>)
  where M,U are type-variables:
    M extends AbstractContainerMenu declared in method <M,U>register(MenuType<? extends M>,ScreenConstructor<M,U>)
    U extends Screen,MenuAccess<M> declared in method <M,U>register(MenuType<? extends M>,ScreenConstructor<M,U>)

When I execute runClient from within Eclipse (2021-12 4.22.0), it compiles, runs, and functions correctly without any issue.  but when I run gradlew build from the command prompt to generate the jar file for the mod, I receive the above error.  Does anyone know why this is happening and how I should fix it?

Here are some of the class Contents:
 

public class ModContainers
{
    public static final DeferredRegister<MenuType<?>> CONTAINER = DeferredRegister.create(ForgeRegistries.CONTAINERS, Reference.MOD_ID);
    
    public static final RegistryObject<MenuType<ElephantInventoryContainer>> ELEPHANT_INVENTORY_CONTAINER  = CONTAINER.register("elephant_inventory_container", () -> new MenuType<>(ElephantInventoryContainer::new));

}
public class ModScreens
{
    public static void registerScreens(FMLClientSetupEvent event)
    {
        event.enqueueWork(() -> {
            MenuScreens.register(ModContainers.ELEPHANT_INVENTORY_CONTAINER.get(), ElephantInventoryScreen::new);
        });
    }

public class ElephantInventoryScreen extends AbstractContainerScreen<ElephantInventoryContainer>
{    
    private static final ResourceLocation TEXTURE_BG = new ResourceLocation(Reference.MOD_ID + ":textures/gui/container3x9.png");

    public ElephantInventoryScreen(ElephantInventoryContainer container, Inventory playerInventory, Component title)
    {
        super(container, playerInventory, title);
    }

...

}

public class ElephantInventoryContainer extends AbstractContainerMenu
{

    public ElephantInventoryContainer(int id, Inventory playerInv)
    {

        super(ModContainers.ELEPHANT_INVENTORY_CONTAINER.get(), id);
    }

...
}

 

Any guidance or suggestions is much appreciated.

 

Thank you. 

Edited by diesieben07
code tag

  • Author

I should have came to this forum sooner. 🙂

I've been racking my brain over why this was happening for a couple days now. You are correct.  Specifying the Parameter Type solved the issue.

            MenuScreens.register(ModContainers.ELEPHANT_INVENTORY_CONTAINER.get(), (MenuScreens.ScreenConstructor<ElephantInventoryContainer, ElephantInventoryScreen>) ElephantInventoryScreen::new);

 

 

Thank you very much diesieben07

  • Author

I guess what I did was more along the lines of casting, but it allowed gradle to build, so I'm content now.

 

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.