【发布时间】:2016-06-19 17:04:09
【问题描述】:
我的世界 1.8.9
我已经成功制作了一个只有一个纹理并且渲染正确的块。我遵循了一些 youtube 教程并且它有效。耶!
但是我的问题是另一个应该有多个纹理的块。它最初像另一个块一样具有一个纹理(仅用于练习我的块),但后来我决定它需要元数据和状态。为此,我关注了this tutorial,直到它调出 BlockRenderRegister.class。我没有这门课,也没有详细说明把它放在哪里,所以我试着自己弄清楚其余的。
成功的块称为“cellauto1”(元胞自动机框架),故障块称为“cellauto2”(元胞自动机网格),应该有黑色变体(cellauto2b)和白色变体(cellauto2w),但它不是那样的。虽然这两个块都出现在创意选项卡中,但它们在此处或放置在世界中时都无法正确渲染(而是加载了粉黑色纹理)。
我得到如下异常:[Client thread/ERROR] [FML]: Exception loading model for variant cellauto:cellauto2#type=black for blockstate "cellauto:cellauto2[type=black]"
这是我的文件结构:
这是我的 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"));
}
}
如果您需要任何其他文件,请告诉我。谢谢!
【问题讨论】:
标签: java minecraft minecraft-forge