Minecraft Forge Modding - 具有变体的块无法正确呈现

时间:2016-06-19 17:04:09

标签: java minecraft minecraft-forge

Minecraft 1.8.9

我已经成功制作了一个只有一个纹理并且渲染正确的块。我按照一些youtube教程进行了操作。好极了!

然而我的问题是另一个应该有多个纹理的块。它最初有一个像另一个块一样的纹理(只是为了练习我的块),但后来我决定它需要元数据和状态。为此,我跟着this tutorial,直到它出现了BlockRenderRegister.class。我没有制作这门课程,也没有详细说明把它放在哪里,所以我试着弄清楚其余部分。

成功的块名为' cellauto1' (Cellular Automaton Frame)和故障块称为' cellauto2' (细胞自动机网格)应该有一个黑色变体(cellauto2b)和一个白色变体(cellauto2w),但它并没有像这样。虽然两个块都出现在广告素材标签中,但它们无法在此处正确呈现,也不会放置在世界中(而是加载了粉红色 - 黑色纹理)。

我得到的例外情况如下:[Client thread/ERROR] [FML]: Exception loading model for variant cellauto:cellauto2#type=black for blockstate "cellauto:cellauto2[type=black]"

这是我的文件结构:

enter image description here

这是我的CellularAutomatonGrid类:

package com.cellularautomaton.mod.blocks;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

public class CellularAutomatonGrid extends Block implements IMetaBlockName{
    public CellularAutomatonGrid(String unlocalizedName, Material material, float hardness, float resistance){
        super(material);
        this.setUnlocalizedName(unlocalizedName);
        this.setCreativeTab(CreativeTabs.tabBlock);
        this.setHardness(hardness);
        this.setResistance(resistance);
        this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE,  EnumType.WHITE));
    }

    @Override
    public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) {
        list.add(new ItemStack(itemIn, 1, 0)); //Meta 0
        list.add(new ItemStack(itemIn, 1, 1)); //Meta 1
    }
    public CellularAutomatonGrid(String unlocalizedName, float hardness, float resistance){
        this(unlocalizedName, Material.rock, hardness, resistance);
    }

    public CellularAutomatonGrid(String unlocalizedName)
    {
        this(unlocalizedName, 2.0f, 10.0f);
    }

    @Override
    protected BlockState createBlockState(){
        return new BlockState (this, new IProperty[] { TYPE } );
    }

    @Override
    public IBlockState getStateFromMeta(int meta){
        return getDefaultState().withProperty(TYPE,  meta == 0 ?EnumType.WHITE : EnumType.BLACK);
    }

    @Override
    public int getMetaFromState(IBlockState state){
        EnumType type = (EnumType) state.getValue(TYPE);
        return type.getID();
    }

    @Override
    public int damageDropped(IBlockState state){
        return getMetaFromState(state);
    }
    public static final PropertyEnum TYPE = PropertyEnum.create("type", CellularAutomatonGrid.EnumType.class);

    public enum EnumType implements IStringSerializable {
        WHITE(0, "white"),
        BLACK(1, "black");

        private int ID;
        private String name;

        private EnumType(int ID, String name) {
            this.ID = ID;
            this.name = name;
        }

        @Override
        public String getName() {
            return name;
        }

        @Override
        public String toString(){
            return getName();
        }

        public int getID() {
            return ID;
        }
    }

    @Override
    public String getSpecialName(ItemStack stack) {
        return stack.getItemDamage() == 0 ?"white" :"black";
    }

    @Override
    public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos){
        return new ItemStack(Item.getItemFromBlock(this), 1, this.getMetaFromState(world.getBlockState(pos)));

    }

}

我的CellularAutomatonBlocks课程:

package com.cellularautomaton.mod.blocks;

import com.cellularautomaton.mod.Reference;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelBakery;
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 CellularAutomatonBlocks {

    public static Block cellauto1;
    public static Block cellauto2;

    public static void init(){
        cellauto1 = new CellularAutomatonFrame("cellauto1");
        cellauto2 = new CellularAutomatonGrid("cellauto2");
    }
    public static void register(){
        GameRegistry.registerBlock(cellauto1, cellauto1.getUnlocalizedName().substring(5));
        GameRegistry.registerBlock(cellauto2, ItemBlockMeta.class, "cellauto2");
    }

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

告诉我你是否还需要其他文件。谢谢!

1 个答案:

答案 0 :(得分:0)

好的......你按照教程进入了我遇到的同样的难题。至少我不是唯一的一个; - )

对我有帮助的是下载提供的来源 在bedrockminers教程中,您通常会发现隐藏的链接

  

您可以从此处下载本教程中使用的代码作为.zip文件。

下载它,复制源并从那里开始工作。然后反思教程,了解它的各个元素。

就个人而言,这对我有所帮助。他解释说这很好,但不是在编辑中你可以轻松地遵循的方式,错误会变得很糟糕,事情会受到监督。