Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package redsword.mub.blocks;
- 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.BlockStateContainer;
- 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.IStringSerializable;
- import net.minecraft.util.NonNullList;
- import net.minecraft.util.ResourceLocation;
- import redsword.mub.Reference;
- public class BlockMeta extends Block
- {
- public static final PropertyEnum<BlockMeta.EnumType> VARIANT = PropertyEnum.<BlockMeta.EnumType>create("variant", BlockMeta.EnumType.class);
- public BlockMeta(String unlocalizedName) {
- this.setUnlocalizedName(unlocalizedName);
- this.setRegistryName(new ResourceLocation(Reference.MODID, unlocalizedName));
- this.setHardness(3);
- this.setResistance(20);
- setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockMeta.EnumType.FIRST));
- setResistance(5.0F);
- setHardness(3.0F);
- }
- public int damageDropped(IBlockState state)
- {
- return state.getValue(VARIANT).getMetadata();
- }
- public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list)
- {
- for (BlockMeta.EnumType type : BlockMeta.EnumType.values()) {
- list.add(new ItemStack(itemIn, 1, type.getMetadata()));
- }
- }
- public IBlockState getStateFromMeta(int meta)
- {
- return this.getDefaultState().withProperty(VARIANT, BlockMeta.EnumType.byMetadata(meta));
- }
- public int getMetaFromState(IBlockState state)
- {
- return ((BlockMeta.EnumType)state.getValue(VARIANT)).getMetadata();
- }
- protected BlockStateContainer createBlockState()
- {
- return new BlockStateContainer(this, new IProperty[] {VARIANT});
- }
- public static enum EnumType implements IStringSerializable
- {
- FIRST(0, "tutorial", "tutorial_block"),
- SECOND(1, "tutorial2", "tutorial_block_m1");
- private static final BlockMeta.EnumType[] META_LOOKUP = new BlockMeta.EnumType[values().length];
- private final int meta;
- private final String name;
- private final String unlocalizedName;
- private EnumType(int metaIn, String nameIn, String unlocalizedIn)
- {
- this.meta = metaIn;
- this.name = nameIn;
- this.unlocalizedName = unlocalizedIn;
- }
- public static String[] getUnlocalizedNames()
- {
- String[] names = new String[values().length];
- for (int i = 0; i < META_LOOKUP.length; i++)
- names[i] = META_LOOKUP[i].unlocalizedName;
- return names;
- }
- public int getMetadata()
- {
- return this.meta;
- }
- public static BlockMeta.EnumType byMetadata(int meta)
- {
- if (meta < 0 || meta >= META_LOOKUP.length)
- {
- meta = 0;
- }
- return META_LOOKUP[meta];
- }
- public String toString()
- {
- return this.name;
- }
- public String getName()
- {
- return this.name;
- }
- static
- {
- for (BlockMeta.EnumType type : values())
- {
- META_LOOKUP[type.getMetadata()] = type;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement