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