以下代码已添加到我的minecraft mod
public class ModBlocks {
public static BlockPlatinum blockPlatinum;
public static BlockNickel blockNickel;
public static void init() {
registerPlatinum();
registerNickel();
}
@SideOnly(Side.CLIENT)
public static void initClient(ItemModelMesher mesher) {
registerClientPlatinum(mesher);
registerClientNickel(mesher);
}
private static void registerClientNickel(ItemModelMesher mesher) {
Item item = Item.getItemFromBlock(blockNickel);
ModelResourceLocation model = new ModelResourceLocation(ModMetaData.RESOURCE_PREFIX + References.NICKEL_BLOCK,
"inventory");
ModelLoader.registerItemVariants(item, model);
mesher.register(item, 0, model);
}
private static void registerClientPlatinum(ItemModelMesher mesher) {
Item item = Item.getItemFromBlock(blockPlatinum);
ModelResourceLocation model = new ModelResourceLocation(ModMetaData.RESOURCE_PREFIX + References.PLATINUM_BLOCK,
"inventory");
ModelLoader.registerItemVariants(item, model);
mesher.register(item, 0, model);
}
private static void registerNickel() {
ResourceLocation location = new ResourceLocation(ModMetaData.MODID, References.NICKEL_BLOCK);
blockNickel = new BlockNickel();
blockNickel.setRegistryName(location);
GameRegistry.register(blockNickel);
GameRegistry.register(new ItemBlock(blockNickel), location);
}
private static void registerPlatinum() {
ResourceLocation location = new ResourceLocation(ModMetaData.MODID, References.PLATINUM_BLOCK);
blockPlatinum = new BlockPlatinum();
blockPlatinum.setRegistryName(location);
GameRegistry.register(blockPlatinum);
GameRegistry.register(new ItemBlock(blockPlatinum), location);
}
}
我想我会有数百个Block,我可以看到这个文件很快失控!
我尝试重构它,使得块被存储在列表外部的静态类中,然后我在registerClient和registerBlock的重构版本中使用此列表创建了一个for循环,而不是每个块的每个方法。 / p>
当我加载我的世界时,我得到了隐形的块,所以看起来这些块有点进入游戏但没有任何纹理。
我相信有人之前已经解决了这个问题,有谁知道重构这个课程的方法吗?
理想情况下,我希望能够传递一个块列表,并且只要我需要添加一个新块或类似的东西,我就可以添加到此列表中。