Reputation: 238
Minecraft 1.8.9
I have successfully made a block that only has one texture and it renders properly. I followed some youtube tutorial and it worked. Yay!
However my problem is with another block that is supposed to have multiple textures. It originally had one texture like the other block (just for practicing my blocks) but then I decided it needed metadata and states. For this I followed this tutorial until it brings up BlockRenderRegister.class. I don't have this class made, and it doesn't elaborate where to put it so I tried to figure out the rest myself.
The successful block is called 'cellauto1' (Cellular Automaton Frame) and the faulty block is called 'cellauto2' (Cellular Automaton Grid) and should come in a black variant (cellauto2b) and a white variant (cellauto2w), but it doesn't work out like that. While both blocks appear in the creative tabs, they don't render properly there nor when placed in the world (the pink-black texture is loaded instead).
I get exceptions like: [Client thread/ERROR] [FML]: Exception loading model for variant cellauto:cellauto2#type=black for blockstate "cellauto:cellauto2[type=black]"
Here is my file structure:
Here is my CellularAutomatonGrid class:
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)));
}
}
My CellularAutomatonBlocks class:
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"));
}
}
Tell me if you need any other files. Thank you!
Upvotes: 0
Views: 1101
Reputation: 28742
Okay... You followed the tutorial and ran into the same crux I ran into. At least I wasn't the only one ;-)
What helped for me was to download the provided sources.
On bedrockminers tutorials you usually find a link hidden
You can download the code used in this tutorial as a .zip file from here.
Download it, copy over the sources and work from there. Then reflect back on the tutorial to understand it's individual elements.
Personally it helped me better that way. He explains it good, but not in a way you can easely follow in an editor, mistakes will hapen and things will be overseen.
Upvotes: 0