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