Jump to content

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


Recommended Posts

Posted (edited)

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
Posted

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

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.