Minecraft Forge项目块渲染问题

时间:2016-01-08 06:02:23

标签: java minecraft-forge

我遇到了一个项目块渲染问题,因为当我放置块时,它会正确呈现,但是当我手拿它时,它会丢失纹理/模型。

我看到的图片在链接中:http://i.stack.imgur.com/atq1L.png

我已经多次检查过原因,并且控制台中没有错误消息,JSON格式似乎没有任何问题,代码中似乎没有问题。

*顺便说一下,块类的代码并不太重要,因为它只是一个扩展* Block.class的类,然后给super带有Material.stone

这是我的块类的代码:

fragmentTransaction.addToBackStack(null);

以下是我的JSON文件的代码:

BLOCKDATA:

package com.kraftymods.luckyblocks.init;

import com.kraftymods.luckyblocks.blocks.LuckyBlock;
import com.kraftymods.luckyblocks.blocks.itemblocks.LuckyBlockItem;
import com.kraftymods.luckyblocks.main.Reference;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class Blocks {

    public static Block luckyblock;

    public static void init(){
        luckyblock = new LuckyBlock().setUnlocalizedName("luckyblock")[enter image description here][1].setCreativeTab(CreativeTabs.tabMisc);
    }

    public static void register(){
        GameRegistry.registerBlock(luckyblock, LuckyBlockItem.class, luckyblock.getUnlocalizedName().substring(5));
    }

    public static void registerRenders(){
        registerRender(luckyblock);
    }

    private static void registerRender(Block block){
        Item item = Item.getItemFromBlock(block);
        Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MODID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
    }

}

块模型:

{
    "variants": {
        "normal": { "model": "luckyblocks:luckyblock" }
    }
}

物品型号:

{
    "parent": "block/cube_all",
    "textures": {
        "all": "luckyblocks:blocks/luckyblock"
    }
}

我很感谢您花时间阅读本文

1 个答案:

答案 0 :(得分:0)

请为您注册渲染器的客户目的进行课程

我有这个例子:

public final class BlockRenderRegister {
    public static void registerBlockRenderer() {
        register(BlocksLibrary.blockDarkStone);
    }
    public static void register(Block block) {
        Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
                .register(Item.getItemFromBlock(block), 
                          0, 
                          new ModelResourceLocation(
                                ModHooks.MODID.toLowerCase() + ":" + BlocksLibrary.DARKSTONE, 
                                "inventory"
                                 )
                          );
    }
}

为了加载你的积木,我还建议一个单独的类(仅用于维护目的)

public class BlockLoader {
    /**
     * Loads all blocks into memory
     * and populates the BlocksLibary
     * with decent values.
     */
    public static void loadBlocks() {
        GameRegistry.registerBlock(
                BlocksLibrary.blockDarkStone = new BlockDarkStone(Material.rock),
                BlocksLibrary.DARKSTONE
                );
    }
}

我在PreInit事件中注册了块,所以游戏知道我的块。

@EventHandler
public void preInit(FMLPreInitializationEvent e) {
    BlockLoader.loadBlocks();
} 

我从主mod类的FMLInitializationEvent中调用它来注册渲染器。

@EventHandler
    public void init(FMLInitializationEvent event) {
        BlockRenderRegister.registerBlockRenderer();
    }