| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import com.google.common.base.Predicate;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.block.material.MapColor;
|
| 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 |
|
| 14 | public class BlockOldLog extends BlockLog
|
| 15 | {
|
| 16 | public static final PropertyEnum<BlockPlanks.EnumType> VARIANT = PropertyEnum.<BlockPlanks.EnumType>create("variant", BlockPlanks.EnumType.class, new Predicate<BlockPlanks.EnumType>()
|
| 17 | {
|
| 18 | public boolean apply(BlockPlanks.EnumType p_apply_1_)
|
| 19 | {
|
| 20 | return p_apply_1_.getMetadata() < 4;
|
| 21 | }
|
| 22 | });
|
| 23 |
|
| 24 | public BlockOldLog()
|
| 25 | {
|
| 26 | this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, BlockPlanks.EnumType.OAK).withProperty(LOG_AXIS, BlockLog.EnumAxis.Y));
|
| 27 | }
|
| 28 |
|
| 29 | /**
|
| 30 | * Get the MapColor for this Block and the given BlockState
|
| 31 | */
|
| 32 | public MapColor getMapColor(IBlockState state)
|
| 33 | {
|
| 34 | BlockPlanks.EnumType blockplanks$enumtype = (BlockPlanks.EnumType)state.getValue(VARIANT);
|
| 35 |
|
| 36 | switch ((BlockLog.EnumAxis)state.getValue(LOG_AXIS))
|
| 37 | {
|
| 38 | case X:
|
| 39 | case Z:
|
| 40 | case NONE:
|
| 41 | default:
|
| 42 | switch (blockplanks$enumtype)
|
| 43 | {
|
| 44 | case OAK:
|
| 45 | default:
|
| 46 | return BlockPlanks.EnumType.SPRUCE.getMapColor();
|
| 47 |
|
| 48 | case SPRUCE:
|
| 49 | return BlockPlanks.EnumType.DARK_OAK.getMapColor();
|
| 50 |
|
| 51 | case BIRCH:
|
| 52 | return MapColor.quartzColor;
|
| 53 |
|
| 54 | case JUNGLE:
|
| 55 | return BlockPlanks.EnumType.SPRUCE.getMapColor();
|
| 56 | }
|
| 57 |
|
| 58 | case Y:
|
| 59 | return blockplanks$enumtype.getMapColor();
|
| 60 | }
|
| 61 | }
|
| 62 |
|
| 63 | /**
|
| 64 | * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
|
| 65 | */
|
| 66 | public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
|
| 67 | {
|
| 68 | list.add(new ItemStack(itemIn, 1, BlockPlanks.EnumType.OAK.getMetadata()));
|
| 69 | list.add(new ItemStack(itemIn, 1, BlockPlanks.EnumType.SPRUCE.getMetadata()));
|
| 70 | list.add(new ItemStack(itemIn, 1, BlockPlanks.EnumType.BIRCH.getMetadata()));
|
| 71 | list.add(new ItemStack(itemIn, 1, BlockPlanks.EnumType.JUNGLE.getMetadata()));
|
| 72 | }
|
| 73 |
|
| 74 | /**
|
| 75 | * Convert the given metadata into a BlockState for this Block
|
| 76 | */
|
| 77 | public IBlockState getStateFromMeta(int meta)
|
| 78 | {
|
| 79 | IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, BlockPlanks.EnumType.byMetadata((meta & 3) % 4));
|
| 80 |
|
| 81 | switch (meta & 12)
|
| 82 | {
|
| 83 | case 0:
|
| 84 | iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Y);
|
| 85 | break;
|
| 86 |
|
| 87 | case 4:
|
| 88 | iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.X);
|
| 89 | break;
|
| 90 |
|
| 91 | case 8:
|
| 92 | iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Z);
|
| 93 | break;
|
| 94 |
|
| 95 | default:
|
| 96 | iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.NONE);
|
| 97 | }
|
| 98 |
|
| 99 | return iblockstate;
|
| 100 | }
|
| 101 |
|
| 102 | @SuppressWarnings("incomplete-switch")
|
| 103 |
|
| 104 | /**
|
| 105 | * Convert the BlockState into the correct metadata value
|
| 106 | */
|
| 107 | public int getMetaFromState(IBlockState state)
|
| 108 | {
|
| 109 | int i = 0;
|
| 110 | i = i | ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata();
|
| 111 |
|
| 112 | switch ((BlockLog.EnumAxis)state.getValue(LOG_AXIS))
|
| 113 | {
|
| 114 | case X:
|
| 115 | i |= 4;
|
| 116 | break;
|
| 117 |
|
| 118 | case Z:
|
| 119 | i |= 8;
|
| 120 | break;
|
| 121 |
|
| 122 | case NONE:
|
| 123 | i |= 12;
|
| 124 | }
|
| 125 |
|
| 126 | return i;
|
| 127 | }
|
| 128 |
|
| 129 | protected BlockState createBlockState()
|
| 130 | {
|
| 131 | return new BlockState(this, new IProperty[] {VARIANT, LOG_AXIS});
|
| 132 | }
|
| 133 |
|
| 134 | protected ItemStack createStackedBlock(IBlockState state)
|
| 135 | {
|
| 136 | return new ItemStack(Item.getItemFromBlock(this), 1, ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata());
|
| 137 | }
|
| 138 |
|
| 139 | /**
|
| 140 | * Gets the metadata of the item this Block can drop. This method is called when the block gets destroyed. It
|
| 141 | * returns the metadata of the dropped item based on the old metadata of the block.
|
| 142 | */
|
| 143 | public int damageDropped(IBlockState state)
|
| 144 | {
|
| 145 | return ((BlockPlanks.EnumType)state.getValue(VARIANT)).getMetadata();
|
| 146 | }
|
| 147 | }
|
| 148 |
|