No instance(s) of type variable(s) exist so that BlockBase confirms to BlockOre

1.8k views Asked by At

I am following this tutorial on how to create Minecraft mods. I get the below error but I don't see any issues. I don't know what this error means and more importantly I don't really know what I am doing hence following a tutorial.

I am using Forge 1.11 and IntelliJ IDEA 2016.3.2 IDE with Java 1.8.0_112 SDK. Based on some reading I think it has to do with a data type mismatch but it might just be my IDE is picky or it is Java 1.8 SDK thing. I am really lost, so I thought would reach out and see if anyone is willing to provide guidance.

Error:

register (T) in ModBlocks cannot be applied to (net.maramor.tutorial.block.BlockBase)

reason: no instance(s) of type variable(s) exist so that BlockBase conforms to BlockOre inference variable T has incompatible bounds: lower bounds: BlockBase upper bounds: Block, BlockOre

[BlockBase.java]

package net.maramor.tutorial.block;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemBlock;
import net.maramor.tutorial.TutorialMod;

/**
 * Created by Matt on 12/28/2016.
 */
public class BlockBase extends Block
{
    protected String name;

    public BlockBase(Material material, String name)
    {
        super(material);

        this.name = name;

        setUnlocalizedName(name);
        setRegistryName(name);
    }

    public void registerItemModel(ItemBlock itemBlock)
    {
        TutorialMod.proxy.registerItemRenderer(itemBlock,0, name);
    }

    @Override
    public BlockBase setCreativeTab(CreativeTabs tab)
    {
        super.setCreativeTab(tab);
        return this;
    }
}

[BlockOre.java]

package net.maramor.tutorial.block;

import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;

/**
 * Created by Matt on 12/28/2016.
 */
public class BlockOre extends BlockBase
{
    public BlockOre(String name)
    {
        super(Material.ROCK, name);

        setHardness(3f);
        setResistance(5f);
    }

    @Override
    public BlockBase setCreativeTab(CreativeTabs tab)
    {
        super.setCreativeTab(tab);
        return this;
    }
}

[ModBlocks.java]

package net.maramor.tutorial.block;

import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.fml.common.registry.GameRegistry;

/**
 * Created by Matt on 12/28/2016.
 */
public class ModBlocks
{
    public static BlockOre oreCopper;

    public static void init()
    {
        oreCopper = register(new BlockOre("ore_copper").setCreativeTab(CreativeTabs.MATERIALS));
    }

    private static <T extends Block> T register(T block, ItemBlock itemBlock)
    {
        GameRegistry.register(block);
        GameRegistry.register(itemBlock);

        if (block instanceof BlockBase)
        {
            ((BlockBase)block).registerItemModel(itemBlock);
        }

        return block;
    }

    private static <T extends Block> T register(T block)
    {
        ItemBlock itemBlock = new ItemBlock(block);
        itemBlock.setRegistryName(block.getRegistryName());
        return register(block, itemBlock);
    }
}
2

There are 2 answers

0
Seba13xp On

Yes that is one way to do on MC 1.10 and higher. Basically you have to register blocks, items, and textures during the loading of the game so they are available when you make/load a world.

0
ilife On

T register(T block) is a generic function in class ModBlocks.

oreCopper = register(new BlockOre("ore_copper").setCreativeTab(CreativeTabs.MATERIALS));

A instance with type BlockBase is passed to function register so that the expected return type is also BlockBase.