| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.block.material.MapColor;
|
| 5 | import net.minecraft.block.material.Material;
|
| 6 | import net.minecraft.block.properties.IProperty;
|
| 7 | import net.minecraft.block.properties.PropertyEnum;
|
| 8 | import net.minecraft.block.state.BlockState;
|
| 9 | import net.minecraft.block.state.IBlockState;
|
| 10 | import net.minecraft.creativetab.CreativeTabs;
|
| 11 | import net.minecraft.item.Item;
|
| 12 | import net.minecraft.item.ItemStack;
|
| 13 | import net.minecraft.util.IStringSerializable;
|
| 14 | import net.minecraft.util.StatCollector;
|
| 15 |
|
| 16 | public class BlockPrismarine extends Block
|
| 17 | {
|
| 18 | public static final PropertyEnum<BlockPrismarine.EnumType> VARIANT = PropertyEnum.<BlockPrismarine.EnumType>create("variant", BlockPrismarine.EnumType.class);
|
| 19 | public static final int ROUGH_META = BlockPrismarine.EnumType.ROUGH.getMetadata();
|
| 20 | public static final int BRICKS_META = BlockPrismarine.EnumType.BRICKS.getMetadata();
|
| 21 | public static final int DARK_META = BlockPrismarine.EnumType.DARK.getMetadata();
|
| 22 |
|
| 23 | public BlockPrismarine()
|
| 24 | {
|
| 25 | super(Material.rock);
|
| 26 | this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockPrismarine.EnumType.ROUGH));
|
| 27 | this.setCreativeTab(CreativeTabs.tabBlock);
|
| 28 | }
|
| 29 |
|
| 30 | /**
|
| 31 | * Gets the localized name of this block. Used for the statistics page.
|
| 32 | */
|
| 33 | public String getLocalizedName()
|
| 34 | {
|
| 35 | return StatCollector.translateToLocal(this.getUnlocalizedName() + "." + BlockPrismarine.EnumType.ROUGH.getUnlocalizedName() + ".name");
|
| 36 | }
|
| 37 |
|
| 38 | /**
|
| 39 | * Get the MapColor for this Block and the given BlockState
|
| 40 | */
|
| 41 | public MapColor getMapColor(IBlockState state)
|
| 42 | {
|
| 43 | return state.getValue(VARIANT) == BlockPrismarine.EnumType.ROUGH ? MapColor.cyanColor : MapColor.diamondColor;
|
| 44 | }
|
| 45 |
|
| 46 | /**
|
| 47 | * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
|
| 48 | * returns the metadata of the dropped item based on the old metadata of the block.
|
| 49 | */
|
| 50 | public int damageDropped(IBlockState state)
|
| 51 | {
|
| 52 | return ((BlockPrismarine.EnumType)state.getValue(VARIANT)).getMetadata();
|
| 53 | }
|
| 54 |
|
| 55 | /**
|
| 56 | * Convert the BlockState into the correct metadata value
|
| 57 | */
|
| 58 | public int getMetaFromState(IBlockState state)
|
| 59 | {
|
| 60 | return ((BlockPrismarine.EnumType)state.getValue(VARIANT)).getMetadata();
|
| 61 | }
|
| 62 |
|
| 63 | protected BlockState createBlockState()
|
| 64 | {
|
| 65 | return new BlockState(this, new IProperty[] {VARIANT});
|
| 66 | }
|
| 67 |
|
| 68 | /**
|
| 69 | * Convert the given metadata into a BlockState for this Block
|
| 70 | */
|
| 71 | public IBlockState getStateFromMeta(int meta)
|
| 72 | {
|
| 73 | return this.getDefaultState().withProperty(VARIANT, BlockPrismarine.EnumType.byMetadata(meta));
|
| 74 | }
|
| 75 |
|
| 76 | /**
|
| 77 | * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
|
| 78 | */
|
| 79 | public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
|
| 80 | {
|
| 81 | list.add(new ItemStack(itemIn, 1, ROUGH_META));
|
| 82 | list.add(new ItemStack(itemIn, 1, BRICKS_META));
|
| 83 | list.add(new ItemStack(itemIn, 1, DARK_META));
|
| 84 | }
|
| 85 |
|
| 86 | public static enum EnumType implements IStringSerializable
|
| 87 | {
|
| 88 | ROUGH(0, "prismarine", "rough"),
|
| 89 | BRICKS(1, "prismarine_bricks", "bricks"),
|
| 90 | DARK(2, "dark_prismarine", "dark");
|
| 91 |
|
| 92 | private static final BlockPrismarine.EnumType[] META_LOOKUP = new BlockPrismarine.EnumType[values().length];
|
| 93 | private final int meta;
|
| 94 | private final String name;
|
| 95 | private final String unlocalizedName;
|
| 96 |
|
| 97 | private EnumType(int meta, String name, String unlocalizedName)
|
| 98 | {
|
| 99 | this.meta = meta;
|
| 100 | this.name = name;
|
| 101 | this.unlocalizedName = unlocalizedName;
|
| 102 | }
|
| 103 |
|
| 104 | public int getMetadata()
|
| 105 | {
|
| 106 | return this.meta;
|
| 107 | }
|
| 108 |
|
| 109 | public String toString()
|
| 110 | {
|
| 111 | return this.name;
|
| 112 | }
|
| 113 |
|
| 114 | public static BlockPrismarine.EnumType byMetadata(int meta)
|
| 115 | {
|
| 116 | if (meta < 0 || meta >= META_LOOKUP.length)
|
| 117 | {
|
| 118 | meta = 0;
|
| 119 | }
|
| 120 |
|
| 121 | return META_LOOKUP[meta];
|
| 122 | }
|
| 123 |
|
| 124 | public String getName()
|
| 125 | {
|
| 126 | return this.name;
|
| 127 | }
|
| 128 |
|
| 129 | public String getUnlocalizedName()
|
| 130 | {
|
| 131 | return this.unlocalizedName;
|
| 132 | }
|
| 133 |
|
| 134 | static {
|
| 135 | for (BlockPrismarine.EnumType blockprismarine$enumtype : values())
|
| 136 | {
|
| 137 | META_LOOKUP[blockprismarine$enumtype.getMetadata()] = blockprismarine$enumtype;
|
| 138 | }
|
| 139 | }
|
| 140 | }
|
| 141 | }
|
| 142 |
|