| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import net.minecraft.block.material.Material;
|
| 4 | import net.minecraft.block.properties.PropertyEnum;
|
| 5 | import net.minecraft.block.state.IBlockState;
|
| 6 | import net.minecraft.creativetab.CreativeTabs;
|
| 7 | import net.minecraft.entity.EntityLivingBase;
|
| 8 | import net.minecraft.util.BlockPos;
|
| 9 | import net.minecraft.util.EnumFacing;
|
| 10 | import net.minecraft.util.IStringSerializable;
|
| 11 | import net.minecraft.world.World;
|
| 12 |
|
| 13 | public abstract class BlockLog extends BlockRotatedPillar
|
| 14 | {
|
| 15 | public static final PropertyEnum<BlockLog.EnumAxis> LOG_AXIS = PropertyEnum.<BlockLog.EnumAxis>create("axis", BlockLog.EnumAxis.class);
|
| 16 |
|
| 17 | public BlockLog()
|
| 18 | {
|
| 19 | super(Material.wood);
|
| 20 | this.setCreativeTab(CreativeTabs.tabBlock);
|
| 21 | this.setHardness(2.0F);
|
| 22 | this.setStepSound(soundTypeWood);
|
| 23 | }
|
| 24 |
|
| 25 | public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
|
| 26 | {
|
| 27 | int i = 4;
|
| 28 | int j = i + 1;
|
| 29 |
|
| 30 | if (worldIn.isAreaLoaded(pos.add(-j, -j, -j), pos.add(j, j, j)))
|
| 31 | {
|
| 32 | for (BlockPos blockpos : BlockPos.getAllInBox(pos.add(-i, -i, -i), pos.add(i, i, i)))
|
| 33 | {
|
| 34 | IBlockState iblockstate = worldIn.getBlockState(blockpos);
|
| 35 |
|
| 36 | if (iblockstate.getBlock().getMaterial() == Material.leaves && !((Boolean)iblockstate.getValue(BlockLeaves.CHECK_DECAY)).booleanValue())
|
| 37 | {
|
| 38 | worldIn.setBlockState(blockpos, iblockstate.withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(true)), 4);
|
| 39 | }
|
| 40 | }
|
| 41 | }
|
| 42 | }
|
| 43 |
|
| 44 | /**
|
| 45 | * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
|
| 46 | * IBlockstate
|
| 47 | */
|
| 48 | public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
|
| 49 | {
|
| 50 | return super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(LOG_AXIS, BlockLog.EnumAxis.fromFacingAxis(facing.getAxis()));
|
| 51 | }
|
| 52 |
|
| 53 | public static enum EnumAxis implements IStringSerializable
|
| 54 | {
|
| 55 | X("x"),
|
| 56 | Y("y"),
|
| 57 | Z("z"),
|
| 58 | NONE("none");
|
| 59 |
|
| 60 | private final String name;
|
| 61 |
|
| 62 | private EnumAxis(String name)
|
| 63 | {
|
| 64 | this.name = name;
|
| 65 | }
|
| 66 |
|
| 67 | public String toString()
|
| 68 | {
|
| 69 | return this.name;
|
| 70 | }
|
| 71 |
|
| 72 | public static BlockLog.EnumAxis fromFacingAxis(EnumFacing.Axis axis)
|
| 73 | {
|
| 74 | switch (axis)
|
| 75 | {
|
| 76 | case X:
|
| 77 | return X;
|
| 78 |
|
| 79 | case Y:
|
| 80 | return Y;
|
| 81 |
|
| 82 | case Z:
|
| 83 | return Z;
|
| 84 |
|
| 85 | default:
|
| 86 | return NONE;
|
| 87 | }
|
| 88 | }
|
| 89 |
|
| 90 | public String getName()
|
| 91 | {
|
| 92 | return this.name;
|
| 93 | }
|
| 94 | }
|
| 95 | }
|
| 96 |
|