berriz44
berriz44

Reputation: 62

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:

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.

Upvotes: 1

Views: 3163

Answers (1)

Jesper
Jesper

Reputation: 206916

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)));

Upvotes: 4

Related Questions