我关注如何创建Minecraft mod的this tutorial。我得到以下错误,但我没有看到任何问题。我不知道这个错误意味着什么,更重要的是我不知道我在做什么,因此在教程之后。
我正在使用Forge 1.11和IntelliJ IDEA 2016.3.2 IDE以及Java 1.8.0_112 SDK。 根据一些阅读,我认为它与数据类型不匹配有关,但它可能只是我的IDE挑剔或它是Java 1.8 SDK的东西。我真的迷路了,所以我想会伸手去看看是否有人愿意提供指导。
错误:
无法应用ModBlocks中的寄存器(T) (net.maramor.tutorial.block.BlockBase)
原因:没有类型变量的实例存在以便BlockBase 符合BlockOre推理变量T具有不兼容的边界: 下界:BlockBase上限: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);
}
}
答案 0 :(得分:0)
是的,这是MC 1.10及更高版本的一种方法。基本上你必须在加载游戏时注册块,项目和纹理,以便在你创建/加载世界时可以使用它们。
答案 1 :(得分:0)
T寄存器(T块)是ModBlocks类中的通用函数。
oreCopper = register(new BlockOre(&#34; ore_copper&#34;)。setCreativeTab(CreativeTabs.MATERIALS));
将类型为BlockBase的实例传递给函数寄存器,以便预期的返回类型也是BlockBase。