| 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.PropertyBool;
|
| 9 | import net.minecraft.block.properties.PropertyEnum;
|
| 10 | import net.minecraft.block.state.BlockState;
|
| 11 | import net.minecraft.block.state.IBlockState;
|
| 12 | import net.minecraft.creativetab.CreativeTabs;
|
| 13 | import net.minecraft.init.Blocks;
|
| 14 | import net.minecraft.item.Item;
|
| 15 | import net.minecraft.item.ItemStack;
|
| 16 | import net.minecraft.util.BlockPos;
|
| 17 | import net.minecraft.util.IStringSerializable;
|
| 18 | import net.minecraft.util.StatCollector;
|
| 19 | import net.minecraft.world.World;
|
| 20 |
|
| 21 | public abstract class BlockStoneSlabNew extends BlockSlab
|
| 22 | {
|
| 23 | public static final PropertyBool SEAMLESS = PropertyBool.create("seamless");
|
| 24 | public static final PropertyEnum<BlockStoneSlabNew.EnumType> VARIANT = PropertyEnum.<BlockStoneSlabNew.EnumType>create("variant", BlockStoneSlabNew.EnumType.class);
|
| 25 |
|
| 26 | public BlockStoneSlabNew()
|
| 27 | {
|
| 28 | super(Material.rock);
|
| 29 | IBlockState iblockstate = this.blockState.getBaseState();
|
| 30 |
|
| 31 | if (this.isDouble())
|
| 32 | {
|
| 33 | iblockstate = iblockstate.withProperty(SEAMLESS, Boolean.valueOf(false));
|
| 34 | }
|
| 35 | else
|
| 36 | {
|
| 37 | iblockstate = iblockstate.withProperty(HALF, BlockSlab.EnumBlockHalf.BOTTOM);
|
| 38 | }
|
| 39 |
|
| 40 | this.setDefaultState(iblockstate.withProperty(VARIANT, BlockStoneSlabNew.EnumType.RED_SANDSTONE));
|
| 41 | this.setCreativeTab(CreativeTabs.tabBlock);
|
| 42 | }
|
| 43 |
|
| 44 | /**
|
| 45 | * Gets the localized name of this block. Used for the statistics page.
|
| 46 | */
|
| 47 | public String getLocalizedName()
|
| 48 | {
|
| 49 | return StatCollector.translateToLocal(this.getUnlocalizedName() + ".red_sandstone.name");
|
| 50 | }
|
| 51 |
|
| 52 | /**
|
| 53 | * Get the Item that this Block should drop when harvested.
|
| 54 | */
|
| 55 | public Item getItemDropped(IBlockState state, Random rand, int fortune)
|
| 56 | {
|
| 57 | return Item.getItemFromBlock(Blocks.stone_slab2);
|
| 58 | }
|
| 59 |
|
| 60 | public Item getItem(World worldIn, BlockPos pos)
|
| 61 | {
|
| 62 | return Item.getItemFromBlock(Blocks.stone_slab2);
|
| 63 | }
|
| 64 |
|
| 65 | /**
|
| 66 | * Returns the slab block name with the type associated with it
|
| 67 | */
|
| 68 | public String getUnlocalizedName(int meta)
|
| 69 | {
|
| 70 | return super.getUnlocalizedName() + "." + BlockStoneSlabNew.EnumType.byMetadata(meta).getUnlocalizedName();
|
| 71 | }
|
| 72 |
|
| 73 | public IProperty<?> getVariantProperty()
|
| 74 | {
|
| 75 | return VARIANT;
|
| 76 | }
|
| 77 |
|
| 78 | public Object getVariant(ItemStack stack)
|
| 79 | {
|
| 80 | return BlockStoneSlabNew.EnumType.byMetadata(stack.getMetadata() & 7);
|
| 81 | }
|
| 82 |
|
| 83 | /**
|
| 84 | * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
|
| 85 | */
|
| 86 | public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
|
| 87 | {
|
| 88 | if (itemIn != Item.getItemFromBlock(Blocks.double_stone_slab2))
|
| 89 | {
|
| 90 | for (BlockStoneSlabNew.EnumType blockstoneslabnew$enumtype : BlockStoneSlabNew.EnumType.values())
|
| 91 | {
|
| 92 | list.add(new ItemStack(itemIn, 1, blockstoneslabnew$enumtype.getMetadata()));
|
| 93 | }
|
| 94 | }
|
| 95 | }
|
| 96 |
|
| 97 | /**
|
| 98 | * Convert the given metadata into a BlockState for this Block
|
| 99 | */
|
| 100 | public IBlockState getStateFromMeta(int meta)
|
| 101 | {
|
| 102 | IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, BlockStoneSlabNew.EnumType.byMetadata(meta & 7));
|
| 103 |
|
| 104 | if (this.isDouble())
|
| 105 | {
|
| 106 | iblockstate = iblockstate.withProperty(SEAMLESS, Boolean.valueOf((meta & 8) != 0));
|
| 107 | }
|
| 108 | else
|
| 109 | {
|
| 110 | iblockstate = iblockstate.withProperty(HALF, (meta & 8) == 0 ? BlockSlab.EnumBlockHalf.BOTTOM : BlockSlab.EnumBlockHalf.TOP);
|
| 111 | }
|
| 112 |
|
| 113 | return iblockstate;
|
| 114 | }
|
| 115 |
|
| 116 | /**
|
| 117 | * Convert the BlockState into the correct metadata value
|
| 118 | */
|
| 119 | public int getMetaFromState(IBlockState state)
|
| 120 | {
|
| 121 | int i = 0;
|
| 122 | i = i | ((BlockStoneSlabNew.EnumType)state.getValue(VARIANT)).getMetadata();
|
| 123 |
|
| 124 | if (this.isDouble())
|
| 125 | {
|
| 126 | if (((Boolean)state.getValue(SEAMLESS)).booleanValue())
|
| 127 | {
|
| 128 | i |= 8;
|
| 129 | }
|
| 130 | }
|
| 131 | else if (state.getValue(HALF) == BlockSlab.EnumBlockHalf.TOP)
|
| 132 | {
|
| 133 | i |= 8;
|
| 134 | }
|
| 135 |
|
| 136 | return i;
|
| 137 | }
|
| 138 |
|
| 139 | protected BlockState createBlockState()
|
| 140 | {
|
| 141 | return this.isDouble() ? new BlockState(this, new IProperty[] {SEAMLESS, VARIANT}): new BlockState(this, new IProperty[] {HALF, VARIANT});
|
| 142 | }
|
| 143 |
|
| 144 | /**
|
| 145 | * Get the MapColor for this Block and the given BlockState
|
| 146 | */
|
| 147 | public MapColor getMapColor(IBlockState state)
|
| 148 | {
|
| 149 | return ((BlockStoneSlabNew.EnumType)state.getValue(VARIANT)).func_181068_c();
|
| 150 | }
|
| 151 |
|
| 152 | /**
|
| 153 | * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
|
| 154 | * returns the metadata of the dropped item based on the old metadata of the block.
|
| 155 | */
|
| 156 | public int damageDropped(IBlockState state)
|
| 157 | {
|
| 158 | return ((BlockStoneSlabNew.EnumType)state.getValue(VARIANT)).getMetadata();
|
| 159 | }
|
| 160 |
|
| 161 | public static enum EnumType implements IStringSerializable
|
| 162 | {
|
| 163 | RED_SANDSTONE(0, "red_sandstone", BlockSand.EnumType.RED_SAND.getMapColor());
|
| 164 |
|
| 165 | private static final BlockStoneSlabNew.EnumType[] META_LOOKUP = new BlockStoneSlabNew.EnumType[values().length];
|
| 166 | private final int meta;
|
| 167 | private final String name;
|
| 168 | private final MapColor field_181069_e;
|
| 169 |
|
| 170 | private EnumType(int p_i46391_3_, String p_i46391_4_, MapColor p_i46391_5_)
|
| 171 | {
|
| 172 | this.meta = p_i46391_3_;
|
| 173 | this.name = p_i46391_4_;
|
| 174 | this.field_181069_e = p_i46391_5_;
|
| 175 | }
|
| 176 |
|
| 177 | public int getMetadata()
|
| 178 | {
|
| 179 | return this.meta;
|
| 180 | }
|
| 181 |
|
| 182 | public MapColor func_181068_c()
|
| 183 | {
|
| 184 | return this.field_181069_e;
|
| 185 | }
|
| 186 |
|
| 187 | public String toString()
|
| 188 | {
|
| 189 | return this.name;
|
| 190 | }
|
| 191 |
|
| 192 | public static BlockStoneSlabNew.EnumType byMetadata(int meta)
|
| 193 | {
|
| 194 | if (meta < 0 || meta >= META_LOOKUP.length)
|
| 195 | {
|
| 196 | meta = 0;
|
| 197 | }
|
| 198 |
|
| 199 | return META_LOOKUP[meta];
|
| 200 | }
|
| 201 |
|
| 202 | public String getName()
|
| 203 | {
|
| 204 | return this.name;
|
| 205 | }
|
| 206 |
|
| 207 | public String getUnlocalizedName()
|
| 208 | {
|
| 209 | return this.name;
|
| 210 | }
|
| 211 |
|
| 212 | static {
|
| 213 | for (BlockStoneSlabNew.EnumType blockstoneslabnew$enumtype : values())
|
| 214 | {
|
| 215 | META_LOOKUP[blockstoneslabnew$enumtype.getMetadata()] = blockstoneslabnew$enumtype;
|
| 216 | }
|
| 217 | }
|
| 218 | }
|
| 219 | }
|
| 220 |
|