当前位置: 首页 > 知识库问答 >
问题:

不存在类型变量T的实例,因此块符合供应商

姬自强
2023-03-14

我刚从一门课程中编写代码,这时出现了以下错误:

不存在类型变量T的实例,因此块符合供应商的要求

我不知道是什么,但这是我的代码:

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

}

派人来帮忙。


共有1个答案

吴炎彬
2023-03-14

方法寄存器需要一个供应商

您试图在这里传递一个Block而不是供应商

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

您可以实现供应商

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

 类似资料: