| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.block.material.Material;
|
| 5 | import net.minecraft.block.properties.IProperty;
|
| 6 | import net.minecraft.block.properties.PropertyEnum;
|
| 7 | import net.minecraft.block.state.BlockState;
|
| 8 | import net.minecraft.block.state.IBlockState;
|
| 9 | import net.minecraft.creativetab.CreativeTabs;
|
| 10 | import net.minecraft.item.Item;
|
| 11 | import net.minecraft.item.ItemStack;
|
| 12 | import net.minecraft.util.IStringSerializable;
|
| 13 |
|
| 14 | public class BlockRedSandstone extends Block
|
| 15 | {
|
| 16 | public static final PropertyEnum<BlockRedSandstone.EnumType> TYPE = PropertyEnum.<BlockRedSandstone.EnumType>create("type", BlockRedSandstone.EnumType.class);
|
| 17 |
|
| 18 | public BlockRedSandstone()
|
| 19 | {
|
| 20 | super(Material.rock, BlockSand.EnumType.RED_SAND.getMapColor());
|
| 21 | this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, BlockRedSandstone.EnumType.DEFAULT));
|
| 22 | this.setCreativeTab(CreativeTabs.tabBlock);
|
| 23 | }
|
| 24 |
|
| 25 | /**
|
| 26 | * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
|
| 27 | * returns the metadata of the dropped item based on the old metadata of the block.
|
| 28 | */
|
| 29 | public int damageDropped(IBlockState state)
|
| 30 | {
|
| 31 | return ((BlockRedSandstone.EnumType)state.getValue(TYPE)).getMetadata();
|
| 32 | }
|
| 33 |
|
| 34 | /**
|
| 35 | * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
|
| 36 | */
|
| 37 | public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
|
| 38 | {
|
| 39 | for (BlockRedSandstone.EnumType blockredsandstone$enumtype : BlockRedSandstone.EnumType.values())
|
| 40 | {
|
| 41 | list.add(new ItemStack(itemIn, 1, blockredsandstone$enumtype.getMetadata()));
|
| 42 | }
|
| 43 | }
|
| 44 |
|
| 45 | /**
|
| 46 | * Convert the given metadata into a BlockState for this Block
|
| 47 | */
|
| 48 | public IBlockState getStateFromMeta(int meta)
|
| 49 | {
|
| 50 | return this.getDefaultState().withProperty(TYPE, BlockRedSandstone.EnumType.byMetadata(meta));
|
| 51 | }
|
| 52 |
|
| 53 | /**
|
| 54 | * Convert the BlockState into the correct metadata value
|
| 55 | */
|
| 56 | public int getMetaFromState(IBlockState state)
|
| 57 | {
|
| 58 | return ((BlockRedSandstone.EnumType)state.getValue(TYPE)).getMetadata();
|
| 59 | }
|
| 60 |
|
| 61 | protected BlockState createBlockState()
|
| 62 | {
|
| 63 | return new BlockState(this, new IProperty[] {TYPE});
|
| 64 | }
|
| 65 |
|
| 66 | public static enum EnumType implements IStringSerializable
|
| 67 | {
|
| 68 | DEFAULT(0, "red_sandstone", "default"),
|
| 69 | CHISELED(1, "chiseled_red_sandstone", "chiseled"),
|
| 70 | SMOOTH(2, "smooth_red_sandstone", "smooth");
|
| 71 |
|
| 72 | private static final BlockRedSandstone.EnumType[] META_LOOKUP = new BlockRedSandstone.EnumType[values().length];
|
| 73 | private final int meta;
|
| 74 | private final String name;
|
| 75 | private final String unlocalizedName;
|
| 76 |
|
| 77 | private EnumType(int meta, String name, String unlocalizedName)
|
| 78 | {
|
| 79 | this.meta = meta;
|
| 80 | this.name = name;
|
| 81 | this.unlocalizedName = unlocalizedName;
|
| 82 | }
|
| 83 |
|
| 84 | public int getMetadata()
|
| 85 | {
|
| 86 | return this.meta;
|
| 87 | }
|
| 88 |
|
| 89 | public String toString()
|
| 90 | {
|
| 91 | return this.name;
|
| 92 | }
|
| 93 |
|
| 94 | public static BlockRedSandstone.EnumType byMetadata(int meta)
|
| 95 | {
|
| 96 | if (meta < 0 || meta >= META_LOOKUP.length)
|
| 97 | {
|
| 98 | meta = 0;
|
| 99 | }
|
| 100 |
|
| 101 | return META_LOOKUP[meta];
|
| 102 | }
|
| 103 |
|
| 104 | public String getName()
|
| 105 | {
|
| 106 | return this.name;
|
| 107 | }
|
| 108 |
|
| 109 | public String getUnlocalizedName()
|
| 110 | {
|
| 111 | return this.unlocalizedName;
|
| 112 | }
|
| 113 |
|
| 114 | static {
|
| 115 | for (BlockRedSandstone.EnumType blockredsandstone$enumtype : values())
|
| 116 | {
|
| 117 | META_LOOKUP[blockredsandstone$enumtype.getMetadata()] = blockredsandstone$enumtype;
|
| 118 | }
|
| 119 | }
|
| 120 | }
|
| 121 | }
|
| 122 |
|