package eiteam.esteemedinnovation.buzzsaw; import eiteam.esteemedinnovation.api.block.BlockSteamTransporter; import eiteam.esteemedinnovation.api.wrench.Wrenchable; import eiteam.esteemedinnovation.commons.util.WorldHelper; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.material.Material; 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.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class BlockSaw extends BlockSteamTransporter implements Wrenchable { public static final PropertyDirection FACING = BlockHorizontal.FACING; public BlockSaw() { super(Material.IRON); setHardness(5F); setResistance(10F); } @Override public boolean hasTileEntity(IBlockState state) { return true; } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntitySaw(); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, FACING); } @Override public IBlockState getStateFromMeta(int meta) { return getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)); } @Override public int getMetaFromState(IBlockState state) { return state.getValue(FACING).getHorizontalIndex(); } @Override public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { world.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite())); } @Override public boolean onWrench(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, IBlockState state, float hitX, float hitY, float hitZ) { if (!player.isSneaking() && facing.getAxis() != EnumFacing.Axis.Y) { WorldHelper.rotateProperly(FACING, world, state, pos, facing); TileEntity te = world.getTileEntity(pos); if (te instanceof TileEntitySaw) { ((TileEntitySaw) te).uninitialize(); } } return true; } }