| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import net.minecraft.block.material.MapColor;
|
| 4 | import net.minecraft.block.material.Material;
|
| 5 | import net.minecraft.block.properties.IProperty;
|
| 6 | import net.minecraft.block.state.BlockState;
|
| 7 | import net.minecraft.block.state.IBlockState;
|
| 8 | import net.minecraft.creativetab.CreativeTabs;
|
| 9 | import net.minecraft.entity.EntityLivingBase;
|
| 10 | import net.minecraft.item.Item;
|
| 11 | import net.minecraft.item.ItemStack;
|
| 12 | import net.minecraft.util.BlockPos;
|
| 13 | import net.minecraft.util.EnumFacing;
|
| 14 | import net.minecraft.world.World;
|
| 15 |
|
| 16 | public class BlockHay extends BlockRotatedPillar
|
| 17 | {
|
| 18 | public BlockHay()
|
| 19 | {
|
| 20 | super(Material.grass, MapColor.yellowColor);
|
| 21 | this.setDefaultState(this.blockState.getBaseState().withProperty(AXIS, EnumFacing.Axis.Y));
|
| 22 | this.setCreativeTab(CreativeTabs.tabBlock);
|
| 23 | }
|
| 24 |
|
| 25 | /**
|
| 26 | * Convert the given metadata into a BlockState for this Block
|
| 27 | */
|
| 28 | public IBlockState getStateFromMeta(int meta)
|
| 29 | {
|
| 30 | EnumFacing.Axis enumfacing$axis = EnumFacing.Axis.Y;
|
| 31 | int i = meta & 12;
|
| 32 |
|
| 33 | if (i == 4)
|
| 34 | {
|
| 35 | enumfacing$axis = EnumFacing.Axis.X;
|
| 36 | }
|
| 37 | else if (i == 8)
|
| 38 | {
|
| 39 | enumfacing$axis = EnumFacing.Axis.Z;
|
| 40 | }
|
| 41 |
|
| 42 | return this.getDefaultState().withProperty(AXIS, enumfacing$axis);
|
| 43 | }
|
| 44 |
|
| 45 | /**
|
| 46 | * Convert the BlockState into the correct metadata value
|
| 47 | */
|
| 48 | public int getMetaFromState(IBlockState state)
|
| 49 | {
|
| 50 | int i = 0;
|
| 51 | EnumFacing.Axis enumfacing$axis = (EnumFacing.Axis)state.getValue(AXIS);
|
| 52 |
|
| 53 | if (enumfacing$axis == EnumFacing.Axis.X)
|
| 54 | {
|
| 55 | i |= 4;
|
| 56 | }
|
| 57 | else if (enumfacing$axis == EnumFacing.Axis.Z)
|
| 58 | {
|
| 59 | i |= 8;
|
| 60 | }
|
| 61 |
|
| 62 | return i;
|
| 63 | }
|
| 64 |
|
| 65 | protected BlockState createBlockState()
|
| 66 | {
|
| 67 | return new BlockState(this, new IProperty[] {AXIS});
|
| 68 | }
|
| 69 |
|
| 70 | protected ItemStack createStackedBlock(IBlockState state)
|
| 71 | {
|
| 72 | return new ItemStack(Item.getItemFromBlock(this), 1, 0);
|
| 73 | }
|
| 74 |
|
| 75 | /**
|
| 76 | * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
|
| 77 | * IBlockstate
|
| 78 | */
|
| 79 | public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
|
| 80 | {
|
| 81 | return super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(AXIS, facing.getAxis());
|
| 82 | }
|
| 83 | }
|
| 84 |
|