... I mean multi block use an ID, use damage to distinguish. Who can give a example .java file with basic code to create and registry it and its ItemBlock? If you can show me how to give a TranslationKey, that's fantastic! Please help me... I've been trying for three days, I look ic2, te5 and even gtce, and I still can't understand how to meta-hack the block...
my code:
package com.github.nyasroryo.lanticaltech.common.block.buildmaterial;
import com.github.nyasroryo.lanticaltech.common.block.BlockBase;
import net.minecraft.block.Block;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.NonNullList;
public class CeramicTile extends BlockBase {
private static final String NAME = "CeramicTile";
public static final Block THIS_BLOCK = new CeramicTile();
public static final Item THIS_ITEMBLOCK = new ItemBlock(THIS_BLOCK).setRegistryName(NAME);
public static final PropertyEnum<EnumColor> COLOR = PropertyEnum.create("color", EnumColor.class);
public CeramicTile() {
super(NAME); //set Hardness, resistance, sound etc. in other class
setDefaultState(this.blockState.getBaseState().withProperty(COLOR, EnumColor.WHITE));
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, COLOR);
}
@Override
public IBlockState getStateFromMeta(int metadata) {
return this.getDefaultState().withProperty(COLOR, EnumColor.values()[metadata]);
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(COLOR).ordinal();
}
@Override
public int damageDropped(IBlockState state) {
return getMetaFromState(state);
}
@Override
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
{
for (EnumDyeColor enumdyecolor : EnumDyeColor.values())
{
items.add(new ItemStack(this, 1, enumdyecolor.getMetadata()));
}
}
public static enum EnumColor implements IStringSerializable {
WHITE("white"),
BLACK("black"),
RED("red"),
BLUE("blue"),
GREEN("green"),
YELLOW("yellow"),
ORANGE("orange"),
GREY("grey"),
PURPLE("purple"),
CYAN("cyan"),
PINK("pink"),
MAGENTA("magenta"),
BROWN("brown"),
LIGHTBLUE("lightblue"),
LIGHTGREY("lightgrey"),
LIGHTGREEN("lightgreen");
private String name;
private EnumColor(String color)
{
this.name = color;
}
@Override
public String getName()
{
return this.name;
}
@Override
public String toString()
{
return this.name;
}
}
}
Registry and error:
ForgeRegistries.BLOCKS.register(CeramicTile.THIS_BLOCK);
ForgeRegistries.ITEMS.register(CeramicTile.THIS_ITEMBLOCK);
ModelLoader.setCustomModelResourceLocation(CeramicTile.THIS_ITEMBLOCK, 0, new ModelResourceLocation("CeramicTile","inventory"));
ModelLoader.setCustomModelResourceLocation(CeramicTile.THIS_ITEMBLOCK, 1, new ModelResourceLocation("CeramicTile","inventory"));
ModelLoader.setCustomModelResourceLocation(CeramicTile.THIS_ITEMBLOCK, 2, new ModelResourceLocation("CeramicTile","inventory"));
Caused by: java.lang.NullPointerException
at net.minecraft.block.state.BlockStateContainer.validateProperty(BlockStateContainer.java:103)
at net.minecraft.block.state.BlockStateContainer.<init>(BlockStateContainer.java:77)
at net.minecraft.block.state.BlockStateContainer.<init>(BlockStateContainer.java:62)
at com.github.nyasroryo.lanticaltech.common.block.buildmaterial.CeramicTile.createBlockState(CeramicTile.java:32)
at net.minecraft.block.Block.<init>(Block.java:313)
at net.minecraft.block.Block.<init>(Block.java:322)
at com.github.nyasroryo.lanticaltech.common.block.BlockBase.<init>(BlockBase.java:13)
at com.github.nyasroryo.lanticaltech.common.block.buildmaterial.CeramicTile.<init>(CeramicTile.java:26)
at com.github.nyasroryo.lanticaltech.common.block.buildmaterial.CeramicTile.<clinit>(CeramicTile.java:20)
... 51 more