| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import java.util.Random;
|
| 5 | import net.minecraft.block.material.MapColor;
|
| 6 | import net.minecraft.block.material.Material;
|
| 7 | import net.minecraft.block.properties.IProperty;
|
| 8 | import net.minecraft.block.properties.PropertyEnum;
|
| 9 | import net.minecraft.block.state.BlockState;
|
| 10 | import net.minecraft.block.state.IBlockState;
|
| 11 | import net.minecraft.creativetab.CreativeTabs;
|
| 12 | import net.minecraft.init.Blocks;
|
| 13 | import net.minecraft.item.Item;
|
| 14 | import net.minecraft.item.ItemStack;
|
| 15 | import net.minecraft.util.IStringSerializable;
|
| 16 | import net.minecraft.util.StatCollector;
|
| 17 |
|
| 18 | public class BlockStone extends Block
|
| 19 | {
|
| 20 | public static final PropertyEnum<BlockStone.EnumType> VARIANT = PropertyEnum.<BlockStone.EnumType>create("variant", BlockStone.EnumType.class);
|
| 21 |
|
| 22 | public BlockStone()
|
| 23 | {
|
| 24 | super(Material.rock);
|
| 25 | this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockStone.EnumType.STONE));
|
| 26 | this.setCreativeTab(CreativeTabs.tabBlock);
|
| 27 | }
|
| 28 |
|
| 29 | /**
|
| 30 | * Gets the localized name of this block. Used for the statistics page.
|
| 31 | */
|
| 32 | public String getLocalizedName()
|
| 33 | {
|
| 34 | return StatCollector.translateToLocal(this.getUnlocalizedName() + "." + BlockStone.EnumType.STONE.getUnlocalizedName() + ".name");
|
| 35 | }
|
| 36 |
|
| 37 | /**
|
| 38 | * Get the MapColor for this Block and the given BlockState
|
| 39 | */
|
| 40 | public MapColor getMapColor(IBlockState state)
|
| 41 | {
|
| 42 | return ((BlockStone.EnumType)state.getValue(VARIANT)).func_181072_c();
|
| 43 | }
|
| 44 |
|
| 45 | /**
|
| 46 | * Get the Item that this Block should drop when harvested.
|
| 47 | */
|
| 48 | public Item getItemDropped(IBlockState state, Random rand, int fortune)
|
| 49 | {
|
| 50 | return state.getValue(VARIANT) == BlockStone.EnumType.STONE ? Item.getItemFromBlock(Blocks.cobblestone) : Item.getItemFromBlock(Blocks.stone);
|
| 51 | }
|
| 52 |
|
| 53 | /**
|
| 54 | * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
|
| 55 | * returns the metadata of the dropped item based on the old metadata of the block.
|
| 56 | */
|
| 57 | public int damageDropped(IBlockState state)
|
| 58 | {
|
| 59 | return ((BlockStone.EnumType)state.getValue(VARIANT)).getMetadata();
|
| 60 | }
|
| 61 |
|
| 62 | /**
|
| 63 | * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
|
| 64 | */
|
| 65 | public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
|
| 66 | {
|
| 67 | for (BlockStone.EnumType blockstone$enumtype : BlockStone.EnumType.values())
|
| 68 | {
|
| 69 | list.add(new ItemStack(itemIn, 1, blockstone$enumtype.getMetadata()));
|
| 70 | }
|
| 71 | }
|
| 72 |
|
| 73 | /**
|
| 74 | * Convert the given metadata into a BlockState for this Block
|
| 75 | */
|
| 76 | public IBlockState getStateFromMeta(int meta)
|
| 77 | {
|
| 78 | return this.getDefaultState().withProperty(VARIANT, BlockStone.EnumType.byMetadata(meta));
|
| 79 | }
|
| 80 |
|
| 81 | /**
|
| 82 | * Convert the BlockState into the correct metadata value
|
| 83 | */
|
| 84 | public int getMetaFromState(IBlockState state)
|
| 85 | {
|
| 86 | return ((BlockStone.EnumType)state.getValue(VARIANT)).getMetadata();
|
| 87 | }
|
| 88 |
|
| 89 | protected BlockState createBlockState()
|
| 90 | {
|
| 91 | return new BlockState(this, new IProperty[] {VARIANT});
|
| 92 | }
|
| 93 |
|
| 94 | public static enum EnumType implements IStringSerializable
|
| 95 | {
|
| 96 | STONE(0, MapColor.stoneColor, "stone"),
|
| 97 | GRANITE(1, MapColor.dirtColor, "granite"),
|
| 98 | GRANITE_SMOOTH(2, MapColor.dirtColor, "smooth_granite", "graniteSmooth"),
|
| 99 | DIORITE(3, MapColor.quartzColor, "diorite"),
|
| 100 | DIORITE_SMOOTH(4, MapColor.quartzColor, "smooth_diorite", "dioriteSmooth"),
|
| 101 | ANDESITE(5, MapColor.stoneColor, "andesite"),
|
| 102 | ANDESITE_SMOOTH(6, MapColor.stoneColor, "smooth_andesite", "andesiteSmooth");
|
| 103 |
|
| 104 | private static final BlockStone.EnumType[] META_LOOKUP = new BlockStone.EnumType[values().length];
|
| 105 | private final int meta;
|
| 106 | private final String name;
|
| 107 | private final String unlocalizedName;
|
| 108 | private final MapColor field_181073_l;
|
| 109 |
|
| 110 | private EnumType(int p_i46383_3_, MapColor p_i46383_4_, String p_i46383_5_)
|
| 111 | {
|
| 112 | this(p_i46383_3_, p_i46383_4_, p_i46383_5_, p_i46383_5_);
|
| 113 | }
|
| 114 |
|
| 115 | private EnumType(int p_i46384_3_, MapColor p_i46384_4_, String p_i46384_5_, String p_i46384_6_)
|
| 116 | {
|
| 117 | this.meta = p_i46384_3_;
|
| 118 | this.name = p_i46384_5_;
|
| 119 | this.unlocalizedName = p_i46384_6_;
|
| 120 | this.field_181073_l = p_i46384_4_;
|
| 121 | }
|
| 122 |
|
| 123 | public int getMetadata()
|
| 124 | {
|
| 125 | return this.meta;
|
| 126 | }
|
| 127 |
|
| 128 | public MapColor func_181072_c()
|
| 129 | {
|
| 130 | return this.field_181073_l;
|
| 131 | }
|
| 132 |
|
| 133 | public String toString()
|
| 134 | {
|
| 135 | return this.name;
|
| 136 | }
|
| 137 |
|
| 138 | public static BlockStone.EnumType byMetadata(int meta)
|
| 139 | {
|
| 140 | if (meta < 0 || meta >= META_LOOKUP.length)
|
| 141 | {
|
| 142 | meta = 0;
|
| 143 | }
|
| 144 |
|
| 145 | return META_LOOKUP[meta];
|
| 146 | }
|
| 147 |
|
| 148 | public String getName()
|
| 149 | {
|
| 150 | return this.name;
|
| 151 | }
|
| 152 |
|
| 153 | public String getUnlocalizedName()
|
| 154 | {
|
| 155 | return this.unlocalizedName;
|
| 156 | }
|
| 157 |
|
| 158 | static {
|
| 159 | for (BlockStone.EnumType blockstone$enumtype : values())
|
| 160 | {
|
| 161 | META_LOOKUP[blockstone$enumtype.getMetadata()] = blockstone$enumtype;
|
| 162 | }
|
| 163 | }
|
| 164 | }
|
| 165 | }
|
| 166 |
|