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