package com.team.kalstuff.block; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class BlockBakedPotato extends BlockFood { public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public BlockBakedPotato(float hardness, int amount, float saturation) { super(hardness, amount, saturation); } public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); } public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { this.setDefaultFacing(worldIn, pos, state); } private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state) { if (!worldIn.isRemote) { IBlockState block = worldIn.getBlockState(pos.north()); IBlockState block1 = worldIn.getBlockState(pos.south()); IBlockState block2 = worldIn.getBlockState(pos.west()); IBlockState block3 = worldIn.getBlockState(pos.east()); EnumFacing enumfacing = (EnumFacing)state.getValue(FACING); if (enumfacing == EnumFacing.NORTH && block.isFullBlock() && !block1.isFullBlock()) enumfacing = EnumFacing.SOUTH; else if (enumfacing == EnumFacing.SOUTH && block1.isFullBlock() && !block.isFullBlock()) enumfacing = EnumFacing.NORTH; else if (enumfacing == EnumFacing.WEST && block2.isFullBlock() && !block3.isFullBlock()) enumfacing = EnumFacing.EAST; else if (enumfacing == EnumFacing.EAST && block3.isFullBlock() && !block2.isFullBlock()) enumfacing = EnumFacing.WEST; worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2); } } /** * Convert the given metadata into a BlockState for this Block */ public IBlockState getStateFromMeta(int meta) { EnumFacing enumfacing = EnumFacing.getFront(meta); if (enumfacing.getAxis() == EnumFacing.Axis.Y) { enumfacing = EnumFacing.NORTH; } return this.getDefaultState().withProperty(FACING, enumfacing); } /** * Convert the BlockState into the correct metadata value */ public int getMetaFromState(IBlockState state) { return ((EnumFacing)state.getValue(FACING)).getIndex(); } protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {FACING}); } }