Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

no instance(s) of type variable(s) T exist so that Block conforms to Supplier<T>

I was just coding from a course, when there was this error:

no instance(s) of type variable(s) T exist so that Block conforms to Supplier<T>

I don’t know what it is, but here is my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

package com.berriz44.breloaded.block;

import com.berriz44.breloaded.util.Registration;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.registries.RegistryObject;

import java.util.function.Supplier;

public class ModBlocks {

    public static RegistryObject<Block> SMOOTH_BRICK = register("smooth_brick", new Block(BlockBehaviour.Properties.of(Material.STONE).sound(SoundType.STONE).strength(2f,6f)));

    private static <T extends Block>RegistryObject<T> register(String name, Supplier<T> block) {
        RegistryObject<T> toReturn = Registration.BLOCKS.register(name, block);
        Registration.ITEMS.register(name, () -> new BlockItem(toReturn.get(), new Item.Properties().tab(CreativeModeTab.TAB_BUILDING_BLOCKS)));
        return toReturn;
    }

}

Send help.

>Solution :

The method register takes a Supplier<Block>, not a Block.

You are trying to pass it a Block here instead of a Supplier<Block>:

public static RegistryObject<Block> SMOOTH_BRICK = register("smooth_brick",
    new Block(BlockBehaviour.Properties.of(Material.STONE).sound(SoundType.STONE).strength(2f,6f)));

You can implement Supplier<Block> with a lambda expression:

public static RegistryObject<Block> SMOOTH_BRICK = register("smooth_brick",
    () -> new Block(BlockBehaviour.Properties.of(Material.STONE).sound(SoundType.STONE).strength(2f,6f)));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading